support more than one annotation in the annotation popup

svn path=/trunk/KDE/kdegraphics/okular/; revision=761316
This commit is contained in:
Pino Toscano 2008-01-14 13:39:23 +00:00
parent 048ca1d519
commit 51f34f3f9f
4 changed files with 32 additions and 24 deletions

View file

@ -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();
}
}

View file

@ -11,6 +11,8 @@
#define ANNOTATIONPOPUP_H
#include <QtCore/QObject>
#include <QtCore/QList>
#include <QtCore/QPair>
#include <QtCore/QPoint>
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;
};

View file

@ -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* ) ) );

View file

@ -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* ) ) );