1 /***************************************************************************
2 * Copyright (C) 2006 by Chu Xiaodong <xiaodongchu@gmail.com> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
8 ***************************************************************************/
10 #include "annotationpropertiesdialog.h"
16 #include <qheaderview.h>
17 #include <qtextedit.h>
18 #include <kcolorbutton.h>
20 #include <klineedit.h>
22 #include <knuminput.h>
26 #include "core/document.h"
27 #include "core/page.h"
28 #include "core/annotations.h"
29 #include "annotationwidgets.h"
32 AnnotsPropertiesDialog::AnnotsPropertiesDialog( QWidget
*parent
, Okular::Document
*document
, int docpage
, Okular::Annotation
*ann
)
33 : KPageDialog( parent
), m_document( document
), m_page( docpage
), modified( false )
35 setFaceType( Tabbed
);
37 bool canEditAnnotations
= !(ann
->flags() & Okular::Annotation::External
) && m_document
->isAllowed( Okular::AllowNotes
);
38 setCaptionTextbyAnnotType();
39 if ( canEditAnnotations
)
41 setButtons( Ok
| Apply
| Cancel
);
42 enableButton( Apply
, false );
43 connect( this, SIGNAL( applyClicked() ), this, SLOT( slotapply() ) );
44 connect( this, SIGNAL( okClicked() ), this, SLOT( slotapply() ) );
49 setDefaultButton( Close
);
52 m_annotWidget
= AnnotationWidgetFactory::widgetFor( ann
);
57 QFrame
*page
= new QFrame( this );
58 addPage( page
, i18n( "&Appearance" ) );
59 QGridLayout
* gridlayout
= new QGridLayout( page
);
61 tmplabel
= new QLabel( i18n( "&Color:" ), page
);
62 gridlayout
->addWidget( tmplabel
, 0, 0, Qt::AlignRight
);
63 colorBn
= new KColorButton( page
);
64 colorBn
->setColor( ann
->style().color() );
65 colorBn
->setEnabled( canEditAnnotations
);
66 tmplabel
->setBuddy( colorBn
);
67 gridlayout
->addWidget( colorBn
, 0, 1 );
69 tmplabel
= new QLabel( i18n( "&Opacity:" ), page
);
70 gridlayout
->addWidget( tmplabel
, 1, 0, Qt::AlignRight
);
71 m_opacity
= new KIntNumInput( page
);
72 m_opacity
->setRange( 0, 100 );
73 m_opacity
->setValue( (int)( ann
->style().opacity() * 100 ) );
74 m_opacity
->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) );
75 m_opacity
->setEnabled( canEditAnnotations
);
76 tmplabel
->setBuddy( m_opacity
);
77 gridlayout
->addWidget( m_opacity
, 1, 1 );
79 QWidget
* configWidget
= 0;
80 if ( m_annotWidget
&& ( configWidget
= m_annotWidget
->styleWidget() ) )
82 gridlayout
->addWidget( configWidget
, 2, 0, 1, 2 );
83 configWidget
->setEnabled( canEditAnnotations
);
86 gridlayout
->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed
, QSizePolicy::MinimumExpanding
), 3, 0 );
90 page
= new QFrame( this );
91 addPage( page
, i18n( "&General" ) );
92 // m_tabitem[1]->setIcon( KIcon( "fonts" ) );
93 gridlayout
= new QGridLayout( page
);
94 tmplabel
= new QLabel( i18n( "&Author:" ), page
);
95 AuthorEdit
= new KLineEdit( ann
->author(), page
);
96 AuthorEdit
->setEnabled( canEditAnnotations
);
97 tmplabel
->setBuddy( AuthorEdit
);
98 gridlayout
->addWidget( tmplabel
, 0, 0, Qt::AlignRight
);
99 gridlayout
->addWidget( AuthorEdit
, 0, 1 );
101 tmplabel
= new QLabel( page
);
102 tmplabel
->setText( i18n( "Created: %1", KGlobal::locale()->formatDateTime( ann
->creationDate(), KLocale::LongDate
, true ) ) );
103 tmplabel
->setTextInteractionFlags( Qt::TextSelectableByMouse
);
104 gridlayout
->addWidget( tmplabel
, 1, 0, 1, 2 );
106 m_modifyDateLabel
= new QLabel( page
);
107 m_modifyDateLabel
->setText( i18n( "Modified: %1", KGlobal::locale()->formatDateTime( ann
->modificationDate(), KLocale::LongDate
, true ) ) );
108 m_modifyDateLabel
->setTextInteractionFlags( Qt::TextSelectableByMouse
);
109 gridlayout
->addWidget( m_modifyDateLabel
, 2, 0, 1, 2 );
111 gridlayout
->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed
, QSizePolicy::MinimumExpanding
), 3, 0 );
114 QWidget
* extraWidget
= 0;
115 if ( m_annotWidget
&& ( extraWidget
= m_annotWidget
->extraWidget() ) )
117 addPage( extraWidget
, extraWidget
->windowTitle() );
121 connect( colorBn
, SIGNAL( changed( const QColor
& ) ), this, SLOT( setModified() ) );
122 connect( m_opacity
, SIGNAL( valueChanged( int ) ), this, SLOT( setModified() ) );
123 connect( AuthorEdit
, SIGNAL( textChanged ( const QString
& ) ), this, SLOT( setModified() ) );
126 connect( m_annotWidget
, SIGNAL( dataChanged() ), this, SLOT( setModified() ) );
131 kDebug() << "Annotation details:";
132 kDebug().nospace() << " => unique name: '" << ann
->uniqueName() << "'";
133 kDebug() << " => flags:" << QString::number( m_annot
->flags(), 2 );
136 resize( sizeHint() );
138 AnnotsPropertiesDialog::~AnnotsPropertiesDialog()
140 delete m_annotWidget
;
144 void AnnotsPropertiesDialog::setCaptionTextbyAnnotType()
146 Okular::Annotation::SubType type
=m_annot
->subType();
150 case Okular::Annotation::AText
:
151 if(((Okular::TextAnnotation
*)m_annot
)->textType()==Okular::TextAnnotation::Linked
)
152 captiontext
= i18n( "Note Properties" );
154 captiontext
= i18n( "Inline Note Properties" );
156 case Okular::Annotation::ALine
:
157 captiontext
= i18n( "Line Properties" );
159 case Okular::Annotation::AGeom
:
160 captiontext
= i18n( "Geometry Properties" );
162 case Okular::Annotation::AHighlight
:
163 captiontext
= i18n( "Highlight Properties" );
165 case Okular::Annotation::AStamp
:
166 captiontext
= i18n( "Stamp Properties" );
168 case Okular::Annotation::AInk
:
169 captiontext
= i18n( "Ink Properties" );
171 case Okular::Annotation::ACaret
:
172 captiontext
= i18n( "Caret Properties" );
174 case Okular::Annotation::AFileAttachment
:
175 captiontext
= i18n( "File Attachment Properties" );
177 case Okular::Annotation::ASound
:
178 captiontext
= i18n( "Sound Properties" );
180 case Okular::Annotation::AMovie
:
181 captiontext
= i18n( "Movie Properties" );
184 captiontext
= i18n( "Annotation Properties" );
187 setCaption( captiontext
);
190 void AnnotsPropertiesDialog::setModified()
193 enableButton( Apply
, true );
196 void AnnotsPropertiesDialog::slotapply()
201 m_annot
->setAuthor( AuthorEdit
->text() );
202 m_annot
->setModificationDate( QDateTime::currentDateTime() );
203 m_annot
->style().setColor( colorBn
->color() );
204 m_annot
->style().setOpacity( (double)m_opacity
->value() / 100.0 );
207 m_annotWidget
->applyChanges();
209 m_document
->modifyPageAnnotation( m_page
, m_annot
);
211 m_modifyDateLabel
->setText( i18n( "Modified: %1", KGlobal::locale()->formatDateTime( m_annot
->modificationDate(), KLocale::LongDate
, true ) ) );
214 enableButton( Apply
, false );
217 #include "annotationpropertiesdialog.moc"