1 /***************************************************************************
2 * Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
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 "annotationpopup.h"
15 #include "annotationpropertiesdialog.h"
17 #include "core/annotations.h"
18 #include "core/document.h"
21 AnnotationPopup::AnnotationPopup( Okular::Document
*document
,
23 : mParent( parent
), mDocument( document
)
27 void AnnotationPopup::addAnnotation( Okular::Annotation
* annotation
, int pageNumber
)
29 AnnotPagePair pair
= qMakePair( annotation
, pageNumber
);
30 if ( !mAnnotations
.contains( pair
) )
31 mAnnotations
.append( pair
);
34 void AnnotationPopup::exec( const QPoint
&point
)
36 if ( mAnnotations
.isEmpty() )
39 KMenu
menu( mParent
);
41 QAction
*popoutWindow
= 0;
42 QAction
*deleteNote
= 0;
43 QAction
*showProperties
= 0;
44 QAction
*saveAttachment
= 0;
45 Okular::FileAttachmentAnnotation
*fileAttachAnnot
= 0;
47 const bool onlyOne
= mAnnotations
.count() == 1;
49 menu
.addTitle( i18np( "Annotation", "%1 Annotations", mAnnotations
.count() ) );
50 popoutWindow
= menu
.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) );
51 popoutWindow
->setEnabled( onlyOne
);
52 deleteNote
= menu
.addAction( KIcon( "list-remove" ), i18n( "&Delete" ) );
53 deleteNote
->setEnabled( mDocument
->isAllowed( Okular::AllowNotes
) );
55 if ( onlyOne
&& mAnnotations
.first().first
->flags() & Okular::Annotation::DenyDelete
)
56 deleteNote
->setEnabled( false );
58 showProperties
= menu
.addAction( KIcon( "configure" ), i18n( "&Properties" ) );
59 showProperties
->setEnabled( onlyOne
);
61 if ( onlyOne
&& mAnnotations
.first().first
->subType() == Okular::Annotation::AFileAttachment
)
64 fileAttachAnnot
= static_cast< Okular::FileAttachmentAnnotation
* >( mAnnotations
.first().first
);
65 const QString saveText
= i18nc( "%1 is the name of the file to save", "&Save '%1'...", fileAttachAnnot
->embeddedFile()->name() );
66 saveAttachment
= menu
.addAction( KIcon( "document-save" ), saveText
);
69 QAction
*choice
= menu
.exec( point
.isNull() ? QCursor::pos() : point
);
71 // check if the user really selected an action
73 if ( choice
== popoutWindow
) {
74 emit
setAnnotationWindow( mAnnotations
.first().first
);
75 } else if( choice
== deleteNote
) {
76 Q_FOREACH ( const AnnotPagePair
& pair
, mAnnotations
)
78 if ( pair
.second
!= -1 )
79 mDocument
->removePageAnnotation( pair
.second
, pair
.first
);
81 emit
removeAnnotationWindow( pair
.first
);
83 } else if( choice
== showProperties
) {
84 if ( mAnnotations
.first().second
!= -1 ) {
85 AnnotsPropertiesDialog
propdialog( mParent
, mDocument
, mAnnotations
.first().second
, mAnnotations
.first().first
);
88 } else if( choice
== saveAttachment
) {
89 Q_ASSERT( fileAttachAnnot
);
90 GuiUtils::saveEmbeddedFile( fileAttachAnnot
->embeddedFile(), mParent
);
95 #include "annotationpopup.moc"