[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [okular] ui: Use different RMB menus in page view and review pane
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2012-08-15 17:23:37
Message-ID: 20120815172337.29722A6094 () git ! kde ! org
[Download RAW message or body]

Git commit 719a0df886887d0465e95bcd5eca2708b9402464 by Tobias Koenig.
Committed on 15/08/2012 at 19:21.
Pushed by tokoe into branch 'master'.

Use different RMB menus in page view and review pane

Since the review pane has different requirements than the page view, this
change introduces a mode parameter to the AnnotationPopup ctor.

REVIEW: 106045

M  +59   -9    ui/annotationpopup.cpp
M  +11   -2    ui/annotationpopup.h
M  +1    -1    ui/pageview.cpp
M  +1    -1    ui/side_reviews.cpp

http://commits.kde.org/okular/719a0df886887d0465e95bcd5eca2708b9402464

diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp
index 6d00004..26b2859 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 9856933..7194605 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 e158b60..5e04412 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 fc4b307..a036c48 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)) );
 


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic