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

List:       kde-commits
Subject:    [okular] /: Support multiple annotations in RMB menu
From:       Tobias Koenig <tokoe () kde ! org>
Date:       2012-08-15 15:27:30
Message-ID: 20120815152730.D7B2DA6094 () git ! kde ! org
[Download RAW message or body]

Git commit 58eb957f26e0688ceec561160febfaeb28f2b5b1 by Tobias Koenig.
Committed on 29/06/2012 at 12:39.
Pushed by tokoe into branch 'master'.

Support multiple annotations in RMB menu

Provide the actions for all annotations in the RMB menu, if multiple
annotations are located on top of each other.

BUGS: 300942
REVIEW: 106035
FIXED-IN: 4.10.0

M  +13   -0    core/page.cpp
M  +6    -0    core/page.h
M  +46   -37   ui/annotationpopup.cpp
M  +8    -2    ui/annotationpopup.h
M  +12   -6    ui/pageview.cpp

http://commits.kde.org/okular/58eb957f26e0688ceec561160febfaeb28f2b5b1

diff --git a/core/page.cpp b/core/page.cpp
index c778fe2..ca40d92 100644
--- a/core/page.cpp
+++ b/core/page.cpp
@@ -405,6 +405,19 @@ const ObjectRect * Page::objectRect( ObjectRect::ObjectType \
type, double x, doub  return 0;
 }
 
+QLinkedList< const ObjectRect * > Page::objectRects( ObjectRect::ObjectType type, \
double x, double y, double xScale, double yScale ) const +{
+    QLinkedList< const ObjectRect * > result;
+
+    QLinkedList< ObjectRect * >::const_iterator it = m_rects.begin(), end = \
m_rects.end(); +    for ( ; it != end; ++it )
+        if ( ( (*it)->objectType() == type ) && (*it)->contains( x, y, xScale, \
yScale ) ) +            result.append( *it );
+
+    return result;
+}
+
+
 const ObjectRect* Page::nearestObjectRect( ObjectRect::ObjectType type, double x, \
double y, double xScale, double yScale, double * distance ) const  {
     ObjectRect * res = 0;
diff --git a/core/page.h b/core/page.h
index a2571b7..a8f2761 100644
--- a/core/page.h
+++ b/core/page.h
@@ -224,6 +224,12 @@ class OKULAR_EXPORT Page
         const ObjectRect * objectRect( ObjectRect::ObjectType type, double x, double \
y, double xScale, double yScale ) const;  
         /**
+         * Returns all object rects of the given @p type which are at point (@p x, \
@p y) at scale (@p xScale, @p yScale). +         * @since 0.16 (KDE 4.10)
+         */
+        QLinkedList< const ObjectRect * > objectRects( ObjectRect::ObjectType type, \
double x, double y, double xScale, double yScale ) const; +
+        /**
          * Returns the object rect of the given @p type which is nearest to the \
                point (@p x, @p y) at scale (@p xScale, @p yScale).
          *
          * @since 0.8.2 (KDE 4.2.2)
diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp
index 1c3a717..6d00004 100644
--- a/ui/annotationpopup.cpp
+++ b/ui/annotationpopup.cpp
@@ -18,6 +18,8 @@
 #include "core/document.h"
 #include "guiutils.h"
 
+Q_DECLARE_METATYPE( AnnotationPopup::AnnotPagePair )
+
 AnnotationPopup::AnnotationPopup( Okular::Document *document,
                                   QWidget *parent )
     : mParent( parent ), mDocument( document )
@@ -38,57 +40,64 @@ void AnnotationPopup::exec( const QPoint &point )
 
     KMenu menu( mParent );
 
-    QAction *popoutWindow = 0;
-    QAction *deleteNote = 0;
-    QAction *showProperties = 0;
-    QAction *saveAttachment = 0;
+    QAction *action = 0;
     Okular::FileAttachmentAnnotation *fileAttachAnnot = 0;
 
-    const bool onlyOne = mAnnotations.count() == 1;
+    const char *actionTypeId = "actionType";
 
-    menu.addTitle( i18np( "Annotation", "%1 Annotations", mAnnotations.count() ) );
-    popoutWindow = menu.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) \
                );
-    popoutWindow->setEnabled( onlyOne );
-    deleteNote = menu.addAction( KIcon( "list-remove" ), i18n( "&Delete" ) );
-    deleteNote->setEnabled( mDocument->isAllowed( Okular::AllowNotes ) );
+    const QString openId = QString::fromLatin1( "open" );
+    const QString deleteId = QString::fromLatin1( "delete" );
+    const QString propertiesId = QString::fromLatin1( "properties" );
+    const QString saveId = QString::fromLatin1( "save" );
 
-    const AnnotPagePair &firstAnnotPagePair = mAnnotations.at(0);
     foreach ( const AnnotPagePair& pair, mAnnotations )
     {
-        if ( !mDocument->canRemovePageAnnotation(pair.annotation) )
-            deleteNote->setEnabled( false );
-    }
-
-    showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) );
-    showProperties->setEnabled( onlyOne );
-
-    if ( onlyOne && firstAnnotPagePair.annotation->subType() == \
                Okular::Annotation::AFileAttachment )
-    {
-        menu.addSeparator();
-        fileAttachAnnot = static_cast< Okular::FileAttachmentAnnotation * >( \
                firstAnnotPagePair.annotation );
-        const QString saveText = i18nc( "%1 is the name of the file to save", "&Save \
                '%1'...", fileAttachAnnot->embeddedFile()->name() );
-        saveAttachment = menu.addAction( KIcon( "document-save" ), saveText );
+        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 )
+        {
+            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 );
 
     // check if the user really selected an action
     if ( choice ) {
-        if ( choice == popoutWindow ) {
-            emit openAnnotationWindow( firstAnnotPagePair.annotation, \
                firstAnnotPagePair.pageNumber );
-        } else if( choice == deleteNote ) {
-            Q_FOREACH ( const AnnotPagePair& pair, mAnnotations )
-            {
-                if ( pair.pageNumber != -1 )
-                    mDocument->removePageAnnotation( pair.pageNumber, \
                pair.annotation );
-            }
-        } else if( choice == showProperties ) {
-            if ( firstAnnotPagePair.pageNumber != -1 ) {
-                AnnotsPropertiesDialog propdialog( mParent, mDocument, \
firstAnnotPagePair.pageNumber, firstAnnotPagePair.annotation ); +        const \
AnnotPagePair pair = choice->data().value<AnnotPagePair>(); +
+        const QString actionType = choice->property( actionTypeId ).toString();
+        if ( actionType == openId ) {
+            emit openAnnotationWindow( pair.annotation, pair.pageNumber );
+        } else if( actionType == deleteId ) {
+            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 );  propdialog.exec();
             }
-        } else if( choice == saveAttachment ) {
-            Q_ASSERT( fileAttachAnnot );
+        } else if( actionType == saveId ) {
+            const Okular::FileAttachmentAnnotation * fileAttachAnnot = static_cast< \
                Okular::FileAttachmentAnnotation * >( pair.annotation );
             GuiUtils::saveEmbeddedFile( fileAttachAnnot->embeddedFile(), mParent );
         }
     }
diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h
index e74284c..9856933 100644
--- a/ui/annotationpopup.h
+++ b/ui/annotationpopup.h
@@ -35,9 +35,11 @@ class AnnotationPopup : public QObject
     Q_SIGNALS:
         void openAnnotationWindow( Okular::Annotation *annotation, int pageNumber );
 
-    private:
-        QWidget *mParent;
+    public:
         struct AnnotPagePair {
+            AnnotPagePair() : annotation( 0 ),  pageNumber( -1 )
+            { }
+
             AnnotPagePair( Okular::Annotation *a, int pn ) : annotation( a ),  \
pageNumber( pn )  { }
             
@@ -50,6 +52,10 @@ class AnnotationPopup : public QObject
             Okular::Annotation* annotation;
             int pageNumber;
         };
+
+    private:
+        QWidget *mParent;
+
         QList< AnnotPagePair > mAnnotations;
         Okular::Document *mDocument;
 };
diff --git a/ui/pageview.cpp b/ui/pageview.cpp
index bcb4795..e158b60 100644
--- a/ui/pageview.cpp
+++ b/ui/pageview.cpp
@@ -2015,14 +2015,20 @@ void PageView::mousePressEvent( QMouseEvent * e )
                     const QRect & itemRect = pageItem->uncroppedGeometry();
                     double nX = pageItem->absToPageX(eventPos.x());
                     double nY = pageItem->absToPageY(eventPos.y());
-                    Okular::Annotation * ann = 0;
-                    const Okular::ObjectRect * orect = pageItem->page()->objectRect( \
                Okular::ObjectRect::OAnnotation, nX, nY, itemRect.width(), \
                itemRect.height() );
-                    if ( orect )
-                        ann = ( (Okular::AnnotationObjectRect *)orect \
                )->annotation();
-                    if ( ann )
+
+                    const QLinkedList< const Okular::ObjectRect *> orects = \
pageItem->page()->objectRects( Okular::ObjectRect::OAnnotation, nX, nY, \
itemRect.width(), itemRect.height() ); +
+                    if ( !orects.isEmpty() )
                     {
                         AnnotationPopup popup( d->document, this );
-                        popup.addAnnotation( ann, pageItem->pageNumber() );
+
+                        foreach ( const Okular::ObjectRect * orect, orects )
+                        {
+                            Okular::Annotation * ann = ( \
(Okular::AnnotationObjectRect *)orect )->annotation(); +                            \
if ( ann ) +                                popup.addAnnotation( ann, \
pageItem->pageNumber() ); +
+                        }
 
                         connect( &popup, \
                SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
                                  this, \
SLOT(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