mirror of
https://invent.kde.org/graphics/okular
synced 2024-10-05 15:39:47 +00:00
support more than one annotation in the annotation popup
svn path=/trunk/KDE/kdegraphics/okular/; revision=761316
This commit is contained in:
parent
048ca1d519
commit
51f34f3f9f
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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* ) ) );
|
||||
|
|
|
@ -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* ) ) );
|
||||
|
|
Loading…
Reference in a new issue