From 51f34f3f9fab50bd2a00058888b66d6cb46b0a46 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 14 Jan 2008 13:39:23 +0000 Subject: [PATCH] support more than one annotation in the annotation popup svn path=/trunk/KDE/kdegraphics/okular/; revision=761316 --- ui/annotationpopup.cpp | 37 ++++++++++++++++++++++--------------- ui/annotationpopup.h | 11 ++++++----- ui/pageview.cpp | 4 ++-- ui/side_reviews.cpp | 4 ++-- 4 files changed, 32 insertions(+), 24 deletions(-) diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp index a3697c4f1..019923edc 100644 --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -17,52 +17,59 @@ #include "core/annotations.h" #include "core/document.h" -AnnotationPopup::AnnotationPopup( Okular::Annotation *annotation, - Okular::Document *document, +AnnotationPopup::AnnotationPopup( Okular::Document *document, QWidget *parent ) - : mParent( parent ), mAnnotation( annotation ), - mDocument( document ), mPageNumber( -1 ) + : mParent( parent ), mDocument( document ) { } -void AnnotationPopup::setPageNumber( int pageNumber ) +void AnnotationPopup::addAnnotation( Okular::Annotation* annotation, int pageNumber ) { - mPageNumber = pageNumber; + mAnnotations.append( qMakePair( annotation, pageNumber ) ); } void AnnotationPopup::exec( const QPoint &point ) { + if ( mAnnotations.isEmpty() ) + return; + KMenu menu( mParent ); QAction *popoutWindow = 0; QAction *deleteNote = 0; QAction *showProperties = 0; - menu.addTitle( i18n( "Annotation" ) ); + const bool onlyOne = mAnnotations.count() == 1; + + 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 ) ); - if ( mAnnotation->flags() & Okular::Annotation::DenyDelete ) + if ( onlyOne && mAnnotations.first().first->flags() & Okular::Annotation::DenyDelete ) deleteNote->setEnabled( false ); showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties" ) ); + showProperties->setEnabled( onlyOne ); QAction *choice = menu.exec( point.isNull() ? QCursor::pos() : point ); // check if the user really selected an action if ( choice ) { if ( choice == popoutWindow ) { - emit setAnnotationWindow( mAnnotation ); + emit setAnnotationWindow( mAnnotations.first().first ); } else if( choice == deleteNote ) { - emit removeAnnotationWindow( mAnnotation ); - - if ( mPageNumber != -1 ) - mDocument->removePageAnnotation( mPageNumber, mAnnotation ); + Q_FOREACH ( const AnnotPagePair& pair, mAnnotations ) + { + if ( pair.second != -1 ) + mDocument->removePageAnnotation( pair.second, pair.first ); + emit removeAnnotationWindow( pair.first ); + } } else if( choice == showProperties ) { - if ( mPageNumber != -1 ) { - AnnotsPropertiesDialog propdialog( mParent, mDocument, mPageNumber, mAnnotation ); + if ( mAnnotations.first().second != -1 ) { + AnnotsPropertiesDialog propdialog( mParent, mDocument, mAnnotations.first().second, mAnnotations.first().first ); propdialog.exec(); } } diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h index 178deccf8..307765291 100644 --- a/ui/annotationpopup.h +++ b/ui/annotationpopup.h @@ -11,6 +11,8 @@ #define ANNOTATIONPOPUP_H #include +#include +#include #include namespace Okular { @@ -23,11 +25,10 @@ class AnnotationPopup : public QObject Q_OBJECT public: - AnnotationPopup( Okular::Annotation *annotation, - Okular::Document *document, + AnnotationPopup( Okular::Document *document, QWidget *parent = 0 ); - void setPageNumber( int pageNumber ); + void addAnnotation( Okular::Annotation* annotation, int pageNumber ); void exec( const QPoint &point = QPoint() ); @@ -37,9 +38,9 @@ class AnnotationPopup : public QObject private: QWidget *mParent; - Okular::Annotation *mAnnotation; + typedef QPair< Okular::Annotation*, int > AnnotPagePair; + QList< AnnotPagePair > mAnnotations; Okular::Document *mDocument; - int mPageNumber; }; diff --git a/ui/pageview.cpp b/ui/pageview.cpp index eb04ec340..8417e69f3 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -1509,8 +1509,8 @@ void PageView::contentsMousePressEvent( QMouseEvent * e ) ann = ( (Okular::AnnotationObjectRect *)orect )->annotation(); if ( ann ) { - AnnotationPopup popup( ann, d->document, this ); - popup.setPageNumber( pageItem->pageNumber() ); + AnnotationPopup popup( d->document, this ); + popup.addAnnotation( ann, pageItem->pageNumber() ); connect( &popup, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ), this, SLOT( setAnnotationWindow( Okular::Annotation* ) ) ); diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index b7f0da5cb..58204afd3 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -225,8 +225,8 @@ void Reviews::contextMenuRequested( const QPoint &pos ) if ( annotation ) { int pageNumber = m_model->data( annotIndex, AnnotationModel::PageRole ).toInt(); - AnnotationPopup popup( annotation, m_document, this ); - popup.setPageNumber( pageNumber ); + AnnotationPopup popup( m_document, this ); + popup.addAnnotation( annotation, pageNumber ); connect( &popup, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ), this, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ) );