mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-24 18:35:37 +00:00
Small rework of AnnotWindow
* We do not keep them around any more time than needed (they are cheap to create) * AnnotWindow::slotsaveWindowText calls m_document->modifyPageAnnotation so edition of inline notes happens immediately
This commit is contained in:
parent
52d118fc4b
commit
b2dfb910e8
6
part.cpp
6
part.cpp
|
@ -419,10 +419,8 @@ m_cliPresentation(false), m_embedMode(detectEmbedMode(parentWidget, parent, args
|
|||
connect( m_findBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
|
||||
connect( m_miniBar, SIGNAL(forwardKeyPressEvent(QKeyEvent*)), m_pageView, SLOT(externalKeyPressEvent(QKeyEvent*)));
|
||||
|
||||
connect( m_reviewsWidget, SIGNAL(setAnnotationWindow(Okular::Annotation*)),
|
||||
m_pageView, SLOT(setAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( m_reviewsWidget, SIGNAL(removeAnnotationWindow(Okular::Annotation*)),
|
||||
m_pageView, SLOT(removeAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( m_reviewsWidget, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
|
||||
m_pageView, SLOT(openAnnotationWindow(Okular::Annotation*,int)) );
|
||||
|
||||
// add document observers
|
||||
m_document->addObserver( this );
|
||||
|
|
|
@ -72,14 +72,12 @@ void AnnotationPopup::exec( const QPoint &point )
|
|||
// check if the user really selected an action
|
||||
if ( choice ) {
|
||||
if ( choice == popoutWindow ) {
|
||||
emit setAnnotationWindow( firstAnnotPagePair.annotation );
|
||||
emit openAnnotationWindow( firstAnnotPagePair.annotation, firstAnnotPagePair.pageNumber );
|
||||
} else if( choice == deleteNote ) {
|
||||
Q_FOREACH ( const AnnotPagePair& pair, mAnnotations )
|
||||
{
|
||||
if ( pair.pageNumber != -1 )
|
||||
mDocument->removePageAnnotation( pair.pageNumber, pair.annotation );
|
||||
|
||||
emit removeAnnotationWindow( pair.annotation );
|
||||
}
|
||||
} else if( choice == showProperties ) {
|
||||
if ( firstAnnotPagePair.pageNumber != -1 ) {
|
||||
|
|
|
@ -33,8 +33,7 @@ class AnnotationPopup : public QObject
|
|||
void exec( const QPoint &point = QPoint() );
|
||||
|
||||
Q_SIGNALS:
|
||||
void setAnnotationWindow( Okular::Annotation *annotation );
|
||||
void removeAnnotationWindow( Okular::Annotation *annotation );
|
||||
void openAnnotationWindow( Okular::Annotation *annotation, int pageNumber );
|
||||
|
||||
private:
|
||||
QWidget *mParent;
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
// local includes
|
||||
#include "core/annotations.h"
|
||||
#include "core/document.h"
|
||||
#include "guiutils.h"
|
||||
#include "latexrenderer.h"
|
||||
#include <core/utils.h>
|
||||
|
@ -80,7 +81,7 @@ public:
|
|||
dateLabel->setCursor( Qt::SizeAllCursor );
|
||||
buttonlay->addWidget( dateLabel );
|
||||
CloseButton * close = new CloseButton( this );
|
||||
connect( close, SIGNAL(clicked()), parent, SLOT(hide()) );
|
||||
connect( close, SIGNAL(clicked()), parent, SLOT(close()) );
|
||||
buttonlay->addWidget( close );
|
||||
// option button row
|
||||
QHBoxLayout * optionlay = new QHBoxLayout();
|
||||
|
@ -182,11 +183,12 @@ private:
|
|||
|
||||
|
||||
// Qt::SubWindow is needed to make QSizeGrip work
|
||||
AnnotWindow::AnnotWindow( QWidget * parent, Okular::Annotation * annot)
|
||||
: QFrame( parent, Qt::SubWindow ), m_annot( annot )
|
||||
AnnotWindow::AnnotWindow( QWidget * parent, Okular::Annotation * annot, Okular::Document *document, int page )
|
||||
: QFrame( parent, Qt::SubWindow ), m_annot( annot ), m_document( document ), m_page( page )
|
||||
{
|
||||
setAutoFillBackground( true );
|
||||
setFrameStyle( Panel | Raised );
|
||||
setAttribute( Qt::WA_DeleteOnClose );
|
||||
|
||||
textEdit = new KTextEdit( this );
|
||||
textEdit->setAcceptRichText( false );
|
||||
|
@ -238,6 +240,11 @@ void AnnotWindow::reloadInfo()
|
|||
m_title->setDate( m_annot->modificationDate() );
|
||||
}
|
||||
|
||||
Okular::Annotation* AnnotWindow::annotation() const
|
||||
{
|
||||
return m_annot;
|
||||
}
|
||||
|
||||
void AnnotWindow::showEvent( QShowEvent * event )
|
||||
{
|
||||
QFrame::showEvent( event );
|
||||
|
@ -269,6 +276,9 @@ void AnnotWindow::slotOptionBtn()
|
|||
void AnnotWindow::slotsaveWindowText()
|
||||
{
|
||||
const QString newText = textEdit->toPlainText();
|
||||
|
||||
// 0. tell the document
|
||||
m_document->modifyPageAnnotation( m_page, m_annot );
|
||||
|
||||
// 1. window text
|
||||
if ( !m_annot->window().text().isEmpty() )
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
namespace Okular {
|
||||
class Annotation;
|
||||
class Document;
|
||||
}
|
||||
|
||||
namespace GuiUtils {
|
||||
|
@ -29,18 +30,20 @@ class AnnotWindow : public QFrame
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
AnnotWindow( QWidget * parent, Okular::Annotation * annot);
|
||||
AnnotWindow( QWidget * parent, Okular::Annotation * annot, Okular::Document * document, int page );
|
||||
~AnnotWindow();
|
||||
|
||||
void reloadInfo();
|
||||
Okular::Annotation* annotation() const;
|
||||
|
||||
private:
|
||||
MovableTitle * m_title;
|
||||
QTextEdit *textEdit;
|
||||
QColor m_color;
|
||||
GuiUtils::LatexRenderer *m_latexRenderer;
|
||||
public:
|
||||
Okular::Annotation* m_annot;
|
||||
Okular::Document* m_document;
|
||||
int m_page;
|
||||
|
||||
protected:
|
||||
virtual void showEvent( QShowEvent * event );
|
||||
|
|
|
@ -618,7 +618,7 @@ void PageView::fitPageWidth( int page )
|
|||
setFocus();
|
||||
}
|
||||
|
||||
void PageView::setAnnotationWindow( Okular::Annotation * annotation )
|
||||
void PageView::openAnnotationWindow( Okular::Annotation * annotation, int pageNumber )
|
||||
{
|
||||
if ( !annotation )
|
||||
return;
|
||||
|
@ -633,7 +633,8 @@ void PageView::setAnnotationWindow( Okular::Annotation * annotation )
|
|||
|
||||
if ( existWindow == 0 )
|
||||
{
|
||||
existWindow = new AnnotWindow( this, annotation );
|
||||
existWindow = new AnnotWindow( this, annotation, d->document, pageNumber );
|
||||
connect(existWindow, SIGNAL(destroyed(QObject*)), this, SLOT(slotAnnotationWindowDestroyed(QObject*)));
|
||||
|
||||
d->m_annowindows.insert( annotation, existWindow );
|
||||
}
|
||||
|
@ -641,13 +642,20 @@ void PageView::setAnnotationWindow( Okular::Annotation * annotation )
|
|||
existWindow->show();
|
||||
}
|
||||
|
||||
void PageView::removeAnnotationWindow( Okular::Annotation *annotation )
|
||||
void PageView::slotAnnotationWindowDestroyed( QObject * window )
|
||||
{
|
||||
QHash< Okular::Annotation *, AnnotWindow * >::Iterator it = d->m_annowindows.find( annotation );
|
||||
if ( it != d->m_annowindows.end() )
|
||||
QHash< Okular::Annotation*, AnnotWindow * >::Iterator it = d->m_annowindows.begin();
|
||||
QHash< Okular::Annotation*, AnnotWindow * >::Iterator itEnd = d->m_annowindows.end();
|
||||
while ( it != itEnd )
|
||||
{
|
||||
delete *it;
|
||||
d->m_annowindows.erase( it );
|
||||
if ( it.value() == window )
|
||||
{
|
||||
it = d->m_annowindows.erase( it );
|
||||
}
|
||||
else
|
||||
{
|
||||
++it;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1129,8 +1137,12 @@ void PageView::notifyPageChanged( int pageNumber, int changedFlags )
|
|||
}
|
||||
else
|
||||
{
|
||||
delete *it;
|
||||
AnnotWindow *w = *it;
|
||||
it = d->m_annowindows.erase( it );
|
||||
// Need to delete after removing from the list
|
||||
// otherwise deleting will call slotAnnotationWindowDestroyed wich will mess
|
||||
// the list and the iterators
|
||||
delete w;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1968,10 +1980,8 @@ void PageView::mousePressEvent( QMouseEvent * e )
|
|||
AnnotationPopup popup( d->document, this );
|
||||
popup.addAnnotation( ann, pageItem->pageNumber() );
|
||||
|
||||
connect( &popup, SIGNAL(setAnnotationWindow(Okular::Annotation*)),
|
||||
this, SLOT(setAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( &popup, SIGNAL(removeAnnotationWindow(Okular::Annotation*)),
|
||||
this, SLOT(removeAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( &popup, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
|
||||
this, SLOT(openAnnotationWindow(Okular::Annotation*,int)) );
|
||||
|
||||
popup.exec( e->globalPos() );
|
||||
}
|
||||
|
@ -2782,7 +2792,7 @@ void PageView::mouseDoubleClickEvent( QMouseEvent * e )
|
|||
ann = ( (Okular::AnnotationObjectRect *)orect )->annotation();
|
||||
if ( ann )
|
||||
{
|
||||
setAnnotationWindow( ann );
|
||||
openAnnotationWindow( ann, pageItem->pageNumber() );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -126,9 +126,7 @@ Q_OBJECT
|
|||
void copyTextSelection() const;
|
||||
void selectAll();
|
||||
|
||||
void setAnnotationWindow( Okular::Annotation *annotation );
|
||||
|
||||
void removeAnnotationWindow( Okular::Annotation *annotation );
|
||||
void openAnnotationWindow( Okular::Annotation *annotation, int pageNumber );
|
||||
|
||||
signals:
|
||||
void urlDropped( const KUrl& );
|
||||
|
@ -246,6 +244,7 @@ Q_OBJECT
|
|||
void slotStopSpeaks();
|
||||
void slotAction( Okular::Action *action );
|
||||
void externalKeyPressEvent( QKeyEvent *e );
|
||||
void slotAnnotationWindowDestroyed( QObject *window );
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -782,7 +782,7 @@ QRect PageViewAnnotator::routeEvent( QMouseEvent * e, PageViewItem * item )
|
|||
m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation );
|
||||
|
||||
if ( annotation->openDialogAfterCreation() )
|
||||
m_pageView->setAnnotationWindow( annotation );
|
||||
m_pageView->openAnnotationWindow( annotation, item->pageNumber() );
|
||||
}
|
||||
|
||||
if ( m_continuousMode )
|
||||
|
|
|
@ -253,10 +253,8 @@ QModelIndexList Reviews::retrieveAnnotations(const QModelIndex& idx) const
|
|||
void Reviews::contextMenuRequested( const QPoint &pos )
|
||||
{
|
||||
AnnotationPopup popup( m_document, this );
|
||||
connect( &popup, SIGNAL(setAnnotationWindow(Okular::Annotation*)),
|
||||
this, SIGNAL(setAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( &popup, SIGNAL(removeAnnotationWindow(Okular::Annotation*)),
|
||||
this, SIGNAL(removeAnnotationWindow(Okular::Annotation*)) );
|
||||
connect( &popup, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)),
|
||||
this, SIGNAL(openAnnotationWindow(Okular::Annotation*,int)) );
|
||||
|
||||
QModelIndexList indexes = m_view->selectionModel()->selectedIndexes();
|
||||
Q_FOREACH ( const QModelIndex &index, indexes )
|
||||
|
|
|
@ -52,8 +52,7 @@ class Reviews : public QWidget, public Okular::DocumentObserver
|
|||
void slotCurrentPageOnly( bool );
|
||||
|
||||
Q_SIGNALS:
|
||||
void setAnnotationWindow( Okular::Annotation *annotation );
|
||||
void removeAnnotationWindow( Okular::Annotation *annotation );
|
||||
void openAnnotationWindow( Okular::Annotation *annotation, int pageNumber );
|
||||
|
||||
private Q_SLOTS:
|
||||
void activated( const QModelIndex& );
|
||||
|
|
Loading…
Reference in a new issue