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
This commit is contained in:
Tobias Koenig 2012-08-15 19:21:25 +02:00
parent 58eb957f26
commit 719a0df886
4 changed files with 72 additions and 13 deletions

View file

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

View file

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

View file

@ -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 )
{

View file

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