compile
[kdegraphics.git] / okular / ui / annotationpropertiesdialog.cpp
blob99ad0c0625690e9a32b7288950e0570a2c4ceef0
1 /***************************************************************************
2 * Copyright (C) 2006 by Chu Xiaodong <xiaodongchu@gmail.com> *
3 * *
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"
12 // qt/kde includes
13 #include <qframe.h>
14 #include <qlayout.h>
15 #include <qlabel.h>
16 #include <qheaderview.h>
17 #include <qtextedit.h>
18 #include <kcolorbutton.h>
19 #include <kicon.h>
20 #include <klineedit.h>
21 #include <klocale.h>
22 #include <knuminput.h>
23 #include <kglobal.h>
25 // local includes
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 );
36 m_annot=ann;
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() ) );
46 else
48 setButtons( Close );
49 setDefaultButton( Close );
52 m_annotWidget = AnnotationWidgetFactory::widgetFor( ann );
54 QLabel* tmplabel;
55 //1. Appearance
56 //BEGIN tab1
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 );
87 //END tab1
89 //BEGIN tab 2
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 );
112 //END tab 2
114 QWidget * extraWidget = 0;
115 if ( m_annotWidget && ( extraWidget = m_annotWidget->extraWidget() ) )
117 addPage( extraWidget, extraWidget->windowTitle() );
120 //BEGIN connections
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() ) );
124 if ( m_annotWidget )
126 connect( m_annotWidget, SIGNAL( dataChanged() ), this, SLOT( setModified() ) );
128 //END
130 #if 0
131 kDebug() << "Annotation details:";
132 kDebug().nospace() << " => unique name: '" << ann->uniqueName() << "'";
133 kDebug() << " => flags:" << QString::number( m_annot->flags(), 2 );
134 #endif
136 resize( sizeHint() );
138 AnnotsPropertiesDialog::~AnnotsPropertiesDialog()
140 delete m_annotWidget;
144 void AnnotsPropertiesDialog::setCaptionTextbyAnnotType()
146 Okular::Annotation::SubType type=m_annot->subType();
147 QString captiontext;
148 switch(type)
150 case Okular::Annotation::AText:
151 if(((Okular::TextAnnotation*)m_annot)->textType()==Okular::TextAnnotation::Linked)
152 captiontext = i18n( "Note Properties" );
153 else
154 captiontext = i18n( "Inline Note Properties" );
155 break;
156 case Okular::Annotation::ALine:
157 captiontext = i18n( "Line Properties" );
158 break;
159 case Okular::Annotation::AGeom:
160 captiontext = i18n( "Geometry Properties" );
161 break;
162 case Okular::Annotation::AHighlight:
163 captiontext = i18n( "Highlight Properties" );
164 break;
165 case Okular::Annotation::AStamp:
166 captiontext = i18n( "Stamp Properties" );
167 break;
168 case Okular::Annotation::AInk:
169 captiontext = i18n( "Ink Properties" );
170 break;
171 case Okular::Annotation::ACaret:
172 captiontext = i18n( "Caret Properties" );
173 break;
174 case Okular::Annotation::AFileAttachment:
175 captiontext = i18n( "File Attachment Properties" );
176 break;
177 case Okular::Annotation::ASound:
178 captiontext = i18n( "Sound Properties" );
179 break;
180 case Okular::Annotation::AMovie:
181 captiontext = i18n( "Movie Properties" );
182 break;
183 default:
184 captiontext = i18n( "Annotation Properties" );
185 break;
187 setCaption( captiontext );
190 void AnnotsPropertiesDialog::setModified()
192 modified = true;
193 enableButton( Apply, true );
196 void AnnotsPropertiesDialog::slotapply()
198 if ( !modified )
199 return;
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 );
206 if ( m_annotWidget )
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 ) ) );
213 modified = false;
214 enableButton( Apply, false );
217 #include "annotationpropertiesdialog.moc"