From 777877f2d215c59451a0ced8638a5e079a599ca5 Mon Sep 17 00:00:00 2001 From: Tobias Koenig Date: Sat, 30 Dec 2006 12:40:54 +0000 Subject: [PATCH] Refactor the RMB menu for annotations, so we can use the menu for the PageView and the SideReview. BUGS: 137722 svn path=/trunk/playground/graphics/okular/; revision=617807 --- CMakeLists.txt | 1 + part.cpp | 5 ++ ui/annotationpopup.cpp | 70 +++++++++++++++++++++++++++ ui/annotationpopup.h | 45 ++++++++++++++++++ ui/pageview.cpp | 105 +++++++++++++++-------------------------- ui/pageview.h | 7 +-- ui/side_reviews.cpp | 31 +++++++++++- ui/side_reviews.h | 9 +++- 8 files changed, 200 insertions(+), 73 deletions(-) create mode 100644 ui/annotationpopup.cpp create mode 100644 ui/annotationpopup.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 46d284b12..e1b205f7f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -79,6 +79,7 @@ set(okularpart_SRCS ui/embeddedfilesdialog.cpp ui/annotwindow.cpp ui/annotationguiutils.cpp + ui/annotationpopup.cpp ui/annotationpropertiesdialog.cpp ui/annotationtools.cpp ui/annotationwidgets.cpp diff --git a/part.cpp b/part.cpp index 6a4d5e5de..3601a1303 100644 --- a/part.cpp +++ b/part.cpp @@ -214,6 +214,11 @@ Part::Part(QWidget *parentWidget, bottomBarLayout->addWidget( m_pageSizeLabel ); rightLayout->addWidget( bottomBar ); + connect( reviewsWidget, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ), + m_pageView, SLOT( setAnnotationWindow( Okular::Annotation* ) ) ); + connect( reviewsWidget, SIGNAL( removeAnnotationWindow( Okular::Annotation* ) ), + m_pageView, SLOT( removeAnnotationWindow( Okular::Annotation* ) ) ); + // add document observers m_document->addObserver( this ); m_document->addObserver( m_thumbnailList ); diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp new file mode 100644 index 000000000..1a0114691 --- /dev/null +++ b/ui/annotationpopup.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2006 by Tobias Koenig * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#include +#include + +#include "annotationpropertiesdialog.h" +#include "annotationpopup.h" + +#include "core/annotations.h" +#include "core/document.h" + +AnnotationPopup::AnnotationPopup( Okular::Annotation *annotation, + Okular::Document *document, + QWidget *parent ) + : mParent( parent ), mAnnotation( annotation ), + mDocument( document ), mPageNumber( -1 ) +{ +} + +void AnnotationPopup::setPageNumber( int pageNumber ) +{ + mPageNumber = pageNumber; +} + +void AnnotationPopup::exec( const QPoint &point ) +{ + KMenu menu( mParent ); + + QAction *popoutWindow = 0; + QAction *deleteNote = 0; + QAction *showProperties = 0; + + menu.addTitle( i18n( "Annotation" ) ); + popoutWindow = menu.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) ); + deleteNote = menu.addAction( KIcon( "remove" ), i18n( "&Delete" ) ); + + if ( mAnnotation->flags() & Okular::Annotation::DenyDelete ) + deleteNote->setEnabled( false ); + + showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties..." ) ); + + 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 ); + } else if( choice == deleteNote ) { + emit removeAnnotationWindow( mAnnotation ); + + if ( mPageNumber != -1 ) + mDocument->removePageAnnotation( mPageNumber, mAnnotation ); + + } else if( choice == showProperties ) { + if ( mPageNumber != -1 ) { + AnnotsPropertiesDialog propdialog( mParent, mDocument, mPageNumber, mAnnotation ); + propdialog.exec(); + } + } + } +} + +#include "annotationpopup.moc" diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h new file mode 100644 index 000000000..6976513f7 --- /dev/null +++ b/ui/annotationpopup.h @@ -0,0 +1,45 @@ +/*************************************************************************** + * Copyright (C) 2006 by Tobias Koenig * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + ***************************************************************************/ + +#ifndef ANNOTATIONPOPUP_H +#define ANNOTATIONPOPUP_H + +#include + +namespace Okular { +class Annotation; +class Document; +} + +class AnnotationPopup : public QObject +{ + Q_OBJECT + + public: + AnnotationPopup( Okular::Annotation *annotation, + Okular::Document *document, + QWidget *parent = 0 ); + + void setPageNumber( int pageNumber ); + + void exec( const QPoint &point = QPoint() ); + + Q_SIGNALS: + void setAnnotationWindow( Okular::Annotation *annotation ); + void removeAnnotationWindow( Okular::Annotation *annotation ); + + private: + QWidget *mParent; + Okular::Annotation *mAnnotation; + Okular::Document *mDocument; + int mPageNumber; +}; + + +#endif diff --git a/ui/pageview.cpp b/ui/pageview.cpp index 5ec71be22..24831f7cb 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -59,7 +59,7 @@ #include "core/annotations.h" #include "annotwindow.h" //"embeddedannotationdialog.h" #include "annotationguiutils.h" -#include "annotationpropertiesdialog.h" +#include "annotationpopup.h" #include "pageviewannotator.h" #include "core/document.h" #include "core/page.h" @@ -440,42 +440,49 @@ void PageView::fitPageWidth( int page ) setFocus(); } -void PageView::setAnnotsWindow(Okular::Annotation * annot) +void PageView::setAnnotationWindow( Okular::Annotation * annotation ) { - if(!annot) + if ( !annotation ) return; - //find the annot window - AnnotWindow* existWindow=0; - foreach(AnnotWindow* tempwnd, d->m_annowindows) + + // find the annot window + AnnotWindow* existWindow = 0; + foreach ( AnnotWindow* tempwnd, d->m_annowindows ) { - if(tempwnd) + if ( tempwnd ) { - if(tempwnd->m_annot==annot) + if ( tempwnd->m_annot == annotation ) { - existWindow=tempwnd; + existWindow = tempwnd; break; } } } - - /* if(annot->window.flags & Annotation::Hidden) + + if ( existWindow == 0 ) { - if(existWindow) + existWindow = new AnnotWindow( this, annotation ); + + d->m_annowindows << existWindow; + } + + existWindow->show(); +} + +void PageView::removeAnnotationWindow( Okular::Annotation *annotation ) +{ + QList::Iterator it = d->m_annowindows.begin(); + QList::Iterator itEnd = d->m_annowindows.end(); + for ( ; it != itEnd; ++it ) + { + if ( annotation == (*it)->m_annot ) { - existWindow->hide(); + delete *it; + d->m_annowindows.erase( it ); + + return; } } - else - {*/ - if(existWindow==0) - { - existWindow=new AnnotWindow(this,annot); - - d->m_annowindows<show(); - //} - return; } void PageView::displayMessage( const QString & message,PageViewMessage::Icon icon,int duration ) @@ -555,7 +562,6 @@ void PageView::copyTextSelection() const } } - //BEGIN DocumentObserver inherited methods void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool documentChanged ) { @@ -1355,48 +1361,15 @@ void PageView::contentsMousePressEvent( QMouseEvent * e ) ann = ( (Okular::AnnotationObjectRect *)orect )->annotation(); if ( ann ) { - KMenu menu( this ); - QAction *popoutWindow = 0; - QAction *deleteNote = 0; - QAction *showProperties = 0; - menu.addTitle( i18n( "Annotation" ) ); - popoutWindow = menu.addAction( KIcon( "comment" ), i18n( "&Open Pop-up Note" ) ); - deleteNote = menu.addAction( KIcon( "remove" ), i18n( "&Delete" ) ); - if ( ann->flags() & Okular::Annotation::DenyDelete ) - deleteNote->setEnabled( false ); - showProperties = menu.addAction( KIcon( "configure" ), i18n( "&Properties..." ) ); + AnnotationPopup popup( ann, d->document, this ); + popup.setPageNumber( pageItem->pageNumber() ); - QAction *choice = menu.exec( e->globalPos() ); - // check if the user really selected an action - if ( choice ) - { - if ( choice == popoutWindow ) - { - //ann->window.flags ^= Annotation::Hidden; - setAnnotsWindow( ann ); - } - else if( choice == deleteNote ) - { - // find and close the annotwindow - QList::Iterator it = d->m_annowindows.begin(); - QList::Iterator itEnd = d->m_annowindows.end(); - for ( ; it != itEnd; ++it ) - { - if ( ann == (*it)->m_annot ) - { - delete *it; - it = d->m_annowindows.erase( it ); - break; - } - } - d->document->removePageAnnotation( pageItem->page()->number(), ann ); - } - else if( choice == showProperties ) - { - AnnotsPropertiesDialog propdialog( this, d->document, pageItem->pageNumber(), ann ); - propdialog.exec(); - } - } + connect( &popup, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ), + this, SLOT( setAnnotationWindow( Okular::Annotation* ) ) ); + connect( &popup, SIGNAL( removeAnnotationWindow( Okular::Annotation* ) ), + this, SLOT( removeAnnotationWindow( Okular::Annotation* ) ) ); + + popup.exec( e->globalPos() ); } } } diff --git a/ui/pageview.h b/ui/pageview.h index cf9ec5f19..b4ecd9c77 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -51,9 +51,6 @@ Q_OBJECT PageView( QWidget *parent, Okular::Document *document ); ~PageView(); - //set pop-up annotation window states,such as hide/open ,position... - void setAnnotsWindow(Okular::Annotation * annot); - // Zoom mode ( last 4 are internally used only! ) enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitText, ZoomIn, ZoomOut, ZoomRefreshCurrent }; @@ -99,6 +96,10 @@ Q_OBJECT void copyTextSelection() const; + void setAnnotationWindow( Okular::Annotation *annotation ); + + void removeAnnotationWindow( Okular::Annotation *annotation ); + signals: void urlDropped( const KUrl& ); void rightClick( const Okular::Page *, const QPoint & ); diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index afa7d3188..7fdc243fd 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -27,6 +27,7 @@ #include "core/page.h" #include "settings.h" #include "annotationguiutils.h" +#include "annotationpopup.h" #include "side_reviews.h" @@ -88,8 +89,15 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document ) m_listView->header()->hide(); m_listView->setIndentation( 16 ); m_listView->setMouseTracking( true ); - connect( m_listView, SIGNAL( itemActivated( QTreeWidgetItem *, int ) ), this, SLOT( itemActivated( QTreeWidgetItem *, int ) ) ); - connect( m_listView, SIGNAL( itemEntered( QTreeWidgetItem *, int ) ), this, SLOT( itemEntered( QTreeWidgetItem *, int ) ) ); + + connect( m_listView, SIGNAL( itemActivated( QTreeWidgetItem *, int ) ), + this, SLOT( itemActivated( QTreeWidgetItem *, int ) ) ); + connect( m_listView, SIGNAL( itemEntered( QTreeWidgetItem *, int ) ), + this, SLOT( itemEntered( QTreeWidgetItem *, int ) ) ); + + m_listView->setContextMenuPolicy( Qt::CustomContextMenu ); + connect( m_listView, SIGNAL( customContextMenuRequested( const QPoint& ) ), + this, SLOT( contextMenuRequested( const QPoint& ) ) ); } //BEGIN DocumentObserver Notifies -> requestListViewUpdate @@ -367,4 +375,23 @@ void Reviews::itemEntered( QTreeWidgetItem * item, int /*column*/ ) QToolTip::showText( QCursor::pos(), tooltip, m_listView, m_listView->visualItemRect( annItem ) ); } +void Reviews::contextMenuRequested( const QPoint &pos ) +{ + AnnotationItem *item = dynamic_cast< AnnotationItem* >( m_listView->itemAt( pos ) ); + if ( item ) { + Okular::Annotation *annotation = item->annotation(); + int pageNumber = item->page(); + + AnnotationPopup popup( annotation, m_document, this ); + popup.setPageNumber( pageNumber ); + + connect( &popup, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ), + this, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ) ); + connect( &popup, SIGNAL( removeAnnotationWindow( Okular::Annotation* ) ), + this, SIGNAL( removeAnnotationWindow( Okular::Annotation* ) ) ); + + popup.exec( m_listView->viewport()->mapToGlobal( pos ) ); + } +} + #include "side_reviews.moc" diff --git a/ui/side_reviews.h b/ui/side_reviews.h index 11296c811..bd530ca8a 100644 --- a/ui/side_reviews.h +++ b/ui/side_reviews.h @@ -39,15 +39,20 @@ class Reviews : public QWidget, public Okular::DocumentObserver void notifyViewportChanged( bool smoothMove ); void notifyPageChanged( int pageNumber, int changedFlags ); - public slots: + public Q_SLOTS: void slotPageEnabled( bool ); void slotAuthorEnabled( bool ); void slotCurrentPageOnly( bool ); void slotUpdateListView(); - private slots: + Q_SIGNALS: + void setAnnotationWindow( Okular::Annotation *annotation ); + void removeAnnotationWindow( Okular::Annotation *annotation ); + + private Q_SLOTS: void itemActivated( QTreeWidgetItem *, int ); void itemEntered( QTreeWidgetItem *, int ); + void contextMenuRequested( const QPoint &pos ); private: // add all annotations of a page to the listView taking care of grouping