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
This commit is contained in:
Tobias Koenig 2006-12-30 12:40:54 +00:00
parent 4fe8bdce53
commit 777877f2d2
8 changed files with 200 additions and 73 deletions

View file

@ -79,6 +79,7 @@ set(okularpart_SRCS
ui/embeddedfilesdialog.cpp ui/embeddedfilesdialog.cpp
ui/annotwindow.cpp ui/annotwindow.cpp
ui/annotationguiutils.cpp ui/annotationguiutils.cpp
ui/annotationpopup.cpp
ui/annotationpropertiesdialog.cpp ui/annotationpropertiesdialog.cpp
ui/annotationtools.cpp ui/annotationtools.cpp
ui/annotationwidgets.cpp ui/annotationwidgets.cpp

View file

@ -214,6 +214,11 @@ Part::Part(QWidget *parentWidget,
bottomBarLayout->addWidget( m_pageSizeLabel ); bottomBarLayout->addWidget( m_pageSizeLabel );
rightLayout->addWidget( bottomBar ); 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 // add document observers
m_document->addObserver( this ); m_document->addObserver( this );
m_document->addObserver( m_thumbnailList ); m_document->addObserver( m_thumbnailList );

70
ui/annotationpopup.cpp Normal file
View file

@ -0,0 +1,70 @@
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 <klocale.h>
#include <kmenu.h>
#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"

45
ui/annotationpopup.h Normal file
View file

@ -0,0 +1,45 @@
/***************************************************************************
* Copyright (C) 2006 by Tobias Koenig <tokoe@kde.org> *
* *
* 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 <QtCore/QObject>
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

View file

@ -59,7 +59,7 @@
#include "core/annotations.h" #include "core/annotations.h"
#include "annotwindow.h" //"embeddedannotationdialog.h" #include "annotwindow.h" //"embeddedannotationdialog.h"
#include "annotationguiutils.h" #include "annotationguiutils.h"
#include "annotationpropertiesdialog.h" #include "annotationpopup.h"
#include "pageviewannotator.h" #include "pageviewannotator.h"
#include "core/document.h" #include "core/document.h"
#include "core/page.h" #include "core/page.h"
@ -440,42 +440,49 @@ void PageView::fitPageWidth( int page )
setFocus(); setFocus();
} }
void PageView::setAnnotsWindow(Okular::Annotation * annot) void PageView::setAnnotationWindow( Okular::Annotation * annotation )
{ {
if(!annot) if ( !annotation )
return; return;
//find the annot window
AnnotWindow* existWindow=0; // find the annot window
foreach(AnnotWindow* tempwnd, d->m_annowindows) 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; 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<AnnotWindow *>::Iterator it = d->m_annowindows.begin();
QList<AnnotWindow *>::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<<existWindow;
}
existWindow->show();
//}
return;
} }
void PageView::displayMessage( const QString & message,PageViewMessage::Icon icon,int duration ) void PageView::displayMessage( const QString & message,PageViewMessage::Icon icon,int duration )
@ -555,7 +562,6 @@ void PageView::copyTextSelection() const
} }
} }
//BEGIN DocumentObserver inherited methods //BEGIN DocumentObserver inherited methods
void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool documentChanged ) void PageView::notifySetup( const QVector< Okular::Page * > & pageSet, bool documentChanged )
{ {
@ -1355,48 +1361,15 @@ void PageView::contentsMousePressEvent( QMouseEvent * e )
ann = ( (Okular::AnnotationObjectRect *)orect )->annotation(); ann = ( (Okular::AnnotationObjectRect *)orect )->annotation();
if ( ann ) if ( ann )
{ {
KMenu menu( this ); AnnotationPopup popup( ann, d->document, this );
QAction *popoutWindow = 0; popup.setPageNumber( pageItem->pageNumber() );
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..." ) );
QAction *choice = menu.exec( e->globalPos() ); connect( &popup, SIGNAL( setAnnotationWindow( Okular::Annotation* ) ),
// check if the user really selected an action this, SLOT( setAnnotationWindow( Okular::Annotation* ) ) );
if ( choice ) connect( &popup, SIGNAL( removeAnnotationWindow( Okular::Annotation* ) ),
{ this, SLOT( removeAnnotationWindow( Okular::Annotation* ) ) );
if ( choice == popoutWindow )
{ popup.exec( e->globalPos() );
//ann->window.flags ^= Annotation::Hidden;
setAnnotsWindow( ann );
}
else if( choice == deleteNote )
{
// find and close the annotwindow
QList<AnnotWindow *>::Iterator it = d->m_annowindows.begin();
QList<AnnotWindow *>::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();
}
}
} }
} }
} }

View file

@ -51,9 +51,6 @@ Q_OBJECT
PageView( QWidget *parent, Okular::Document *document ); PageView( QWidget *parent, Okular::Document *document );
~PageView(); ~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! ) // Zoom mode ( last 4 are internally used only! )
enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitText, enum ZoomMode { ZoomFixed = 0, ZoomFitWidth = 1, ZoomFitPage = 2, ZoomFitText,
ZoomIn, ZoomOut, ZoomRefreshCurrent }; ZoomIn, ZoomOut, ZoomRefreshCurrent };
@ -99,6 +96,10 @@ Q_OBJECT
void copyTextSelection() const; void copyTextSelection() const;
void setAnnotationWindow( Okular::Annotation *annotation );
void removeAnnotationWindow( Okular::Annotation *annotation );
signals: signals:
void urlDropped( const KUrl& ); void urlDropped( const KUrl& );
void rightClick( const Okular::Page *, const QPoint & ); void rightClick( const Okular::Page *, const QPoint & );

View file

@ -27,6 +27,7 @@
#include "core/page.h" #include "core/page.h"
#include "settings.h" #include "settings.h"
#include "annotationguiutils.h" #include "annotationguiutils.h"
#include "annotationpopup.h"
#include "side_reviews.h" #include "side_reviews.h"
@ -88,8 +89,15 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document )
m_listView->header()->hide(); m_listView->header()->hide();
m_listView->setIndentation( 16 ); m_listView->setIndentation( 16 );
m_listView->setMouseTracking( true ); 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 //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 ) ); 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" #include "side_reviews.moc"

View file

@ -39,15 +39,20 @@ class Reviews : public QWidget, public Okular::DocumentObserver
void notifyViewportChanged( bool smoothMove ); void notifyViewportChanged( bool smoothMove );
void notifyPageChanged( int pageNumber, int changedFlags ); void notifyPageChanged( int pageNumber, int changedFlags );
public slots: public Q_SLOTS:
void slotPageEnabled( bool ); void slotPageEnabled( bool );
void slotAuthorEnabled( bool ); void slotAuthorEnabled( bool );
void slotCurrentPageOnly( bool ); void slotCurrentPageOnly( bool );
void slotUpdateListView(); void slotUpdateListView();
private slots: Q_SIGNALS:
void setAnnotationWindow( Okular::Annotation *annotation );
void removeAnnotationWindow( Okular::Annotation *annotation );
private Q_SLOTS:
void itemActivated( QTreeWidgetItem *, int ); void itemActivated( QTreeWidgetItem *, int );
void itemEntered( QTreeWidgetItem *, int ); void itemEntered( QTreeWidgetItem *, int );
void contextMenuRequested( const QPoint &pos );
private: private:
// add all annotations of a page to the listView taking care of grouping // add all annotations of a page to the listView taking care of grouping