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/annotwindow.cpp
ui/annotationguiutils.cpp
ui/annotationpopup.cpp
ui/annotationpropertiesdialog.cpp
ui/annotationtools.cpp
ui/annotationwidgets.cpp

View file

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

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

View file

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

View file

@ -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"

View file

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