diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp index 6d0000417..26b285994 100644 --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -20,9 +20,9 @@ Q_DECLARE_METATYPE( AnnotationPopup::AnnotPagePair ) -AnnotationPopup::AnnotationPopup( Okular::Document *document, +AnnotationPopup::AnnotationPopup( Okular::Document *document, MenuMode mode, QWidget *parent ) - : mParent( parent ), mDocument( document ) + : mParent( parent ), mDocument( document ), mMenuMode( mode ) { } @@ -47,29 +47,41 @@ void AnnotationPopup::exec( const QPoint &point ) const QString openId = QString::fromLatin1( "open" ); const QString deleteId = QString::fromLatin1( "delete" ); + const QString deleteAllId = QString::fromLatin1( "deleteAll" ); const QString propertiesId = QString::fromLatin1( "properties" ); const QString saveId = QString::fromLatin1( "save" ); - foreach ( const AnnotPagePair& pair, mAnnotations ) + if ( mMenuMode == SingleAnnotationMode ) { - menu.addTitle( GuiUtils::captionForAnnotation( pair.annotation ) ); + const bool onlyOne = (mAnnotations.count() == 1); + + const AnnotPagePair &pair = mAnnotations.at(0); + + menu.addTitle( i18np( "Annotation", "%1 Annotations", mAnnotations.count() ) ); action = menu.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) ); action->setData( QVariant::fromValue( pair ) ); + action->setEnabled( onlyOne ); action->setProperty( actionTypeId, openId ); action = menu.addAction( KIcon( "list-remove" ), i18n( "&Delete" ) ); - action->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) && - mDocument->canRemovePageAnnotation( pair.annotation ) ); - action->setData( QVariant::fromValue( pair ) ); - action->setProperty( actionTypeId, deleteId ); + action->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) ); + action->setProperty( actionTypeId, deleteAllId ); + + foreach ( const AnnotPagePair& pair, mAnnotations ) + { + if ( !mDocument->canRemovePageAnnotation( pair.annotation ) ) + action->setEnabled( false ); + } action = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) ); action->setData( QVariant::fromValue( pair ) ); + action->setEnabled( onlyOne ); action->setProperty( actionTypeId, propertiesId ); - if ( pair.annotation->subType() == Okular::Annotation::AFileAttachment ) + if ( onlyOne && pair.annotation->subType() == Okular::Annotation::AFileAttachment ) { + menu.addSeparator(); fileAttachAnnot = static_cast< Okular::FileAttachmentAnnotation * >( pair.annotation ); const QString saveText = i18nc( "%1 is the name of the file to save", "&Save '%1'...", fileAttachAnnot->embeddedFile()->name() ); @@ -78,6 +90,38 @@ void AnnotationPopup::exec( const QPoint &point ) action->setProperty( actionTypeId, saveId ); } } + else + { + foreach ( const AnnotPagePair& pair, mAnnotations ) + { + menu.addTitle( GuiUtils::captionForAnnotation( pair.annotation ) ); + + action = menu.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) ); + action->setData( QVariant::fromValue( pair ) ); + action->setProperty( actionTypeId, openId ); + + action = menu.addAction( KIcon( "list-remove" ), i18n( "&Delete" ) ); + action->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) && + mDocument->canRemovePageAnnotation( pair.annotation ) ); + action->setData( QVariant::fromValue( pair ) ); + action->setProperty( actionTypeId, deleteId ); + + action = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) ); + action->setData( QVariant::fromValue( pair ) ); + action->setProperty( actionTypeId, propertiesId ); + + if ( pair.annotation->subType() == Okular::Annotation::AFileAttachment ) + { + menu.addSeparator(); + fileAttachAnnot = static_cast< Okular::FileAttachmentAnnotation * >( pair.annotation ); + const QString saveText = i18nc( "%1 is the name of the file to save", "&Save '%1'...", fileAttachAnnot->embeddedFile()->name() ); + + action = menu.addAction( KIcon( "document-save" ), saveText ); + action->setData( QVariant::fromValue( pair ) ); + action->setProperty( actionTypeId, saveId ); + } + } + } QAction *choice = menu.exec( point.isNull() ? QCursor::pos() : point ); @@ -91,6 +135,12 @@ void AnnotationPopup::exec( const QPoint &point ) } else if( actionType == deleteId ) { if ( pair.pageNumber != -1 ) mDocument->removePageAnnotation( pair.pageNumber, pair.annotation ); + } else if( actionType == deleteAllId ) { + Q_FOREACH ( const AnnotPagePair& pair, mAnnotations ) + { + if ( pair.pageNumber != -1 ) + mDocument->removePageAnnotation( pair.pageNumber, pair.annotation ); + } } else if( actionType == propertiesId ) { if ( pair.pageNumber != -1 ) { AnnotsPropertiesDialog propdialog( mParent, mDocument, pair.pageNumber, pair.annotation ); diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h index 9856933cf..71946050d 100644 --- a/ui/annotationpopup.h +++ b/ui/annotationpopup.h @@ -25,8 +25,16 @@ class AnnotationPopup : public QObject Q_OBJECT public: - explicit AnnotationPopup( Okular::Document *document, - QWidget *parent = 0 ); + /** + * Describes the structure of the popup menu. + */ + enum MenuMode + { + SingleAnnotationMode, ///< The menu shows only entries to manipulate a single annotation, or multiple annotations as a group. + MultiAnnotationMode ///< The menu shows entries to manipulate multiple annotations. + }; + + AnnotationPopup( Okular::Document *document, MenuMode mode, QWidget *parent = 0 ); void addAnnotation( Okular::Annotation* annotation, int pageNumber ); @@ -58,6 +66,7 @@ class AnnotationPopup : public QObject QList< AnnotPagePair > mAnnotations; Okular::Document *mDocument; + MenuMode mMenuMode; }; diff --git a/ui/pageview.cpp b/ui/pageview.cpp index e158b601a..5e04412bd 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -2020,7 +2020,7 @@ void PageView::mousePressEvent( QMouseEvent * e ) if ( !orects.isEmpty() ) { - AnnotationPopup popup( d->document, this ); + AnnotationPopup popup( d->document, AnnotationPopup::MultiAnnotationMode, this ); foreach ( const Okular::ObjectRect * orect, orects ) { diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index fc4b307ef..a036c48be 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -252,7 +252,7 @@ QModelIndexList Reviews::retrieveAnnotations(const QModelIndex& idx) const void Reviews::contextMenuRequested( const QPoint &pos ) { - AnnotationPopup popup( m_document, this ); + AnnotationPopup popup( m_document, AnnotationPopup::SingleAnnotationMode, this ); connect( &popup, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)), this, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)) );