diff --git a/part.cpp b/part.cpp index 7b3a92c42..cd0b69538 100644 --- a/part.cpp +++ b/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 ); diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp index fb6327755..e665bdcd7 100644 --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -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 ) { diff --git a/ui/annotationpopup.h b/ui/annotationpopup.h index 6b81f1798..e74284c5d 100644 --- a/ui/annotationpopup.h +++ b/ui/annotationpopup.h @@ -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; diff --git a/ui/annotwindow.cpp b/ui/annotwindow.cpp index cf3aa9c20..3f8cf2e3c 100644 --- a/ui/annotwindow.cpp +++ b/ui/annotwindow.cpp @@ -31,6 +31,7 @@ // local includes #include "core/annotations.h" +#include "core/document.h" #include "guiutils.h" #include "latexrenderer.h" #include @@ -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() ) diff --git a/ui/annotwindow.h b/ui/annotwindow.h index 3298fa91c..f7df9f60f 100644 --- a/ui/annotwindow.h +++ b/ui/annotwindow.h @@ -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 ); diff --git a/ui/pageview.cpp b/ui/pageview.cpp index b3c09824b..344a9443f 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -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() ); } } } diff --git a/ui/pageview.h b/ui/pageview.h index 4a8e2878a..df7ac33f3 100644 --- a/ui/pageview.h +++ b/ui/pageview.h @@ -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 diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index e73dd704b..3f2b38382 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -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 ) diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index 40a7adf3c..fc4b307ef 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -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 ) diff --git a/ui/side_reviews.h b/ui/side_reviews.h index 867db95a5..d063b7b7a 100644 --- a/ui/side_reviews.h +++ b/ui/side_reviews.h @@ -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& );