From ea071caf9dc02c67238e937e917171d8d176c59f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 28 Dec 2006 00:40:09 +0000 Subject: [PATCH] Improve the way we get the contents of an annotation; dynamically change the tooltip of the annotation item in the side review pane. svn path=/trunk/playground/graphics/okular/; revision=617106 --- ui/annotationguiutils.cpp | 32 ++++++++++++++++++++++++++++++++ ui/annotationguiutils.h | 3 +++ ui/pageview.cpp | 5 +++-- ui/side_reviews.cpp | 21 +++++++++++++++++++-- ui/side_reviews.h | 1 + 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/ui/annotationguiutils.cpp b/ui/annotationguiutils.cpp index 6f5ecbfca..8a2d69968 100644 --- a/ui/annotationguiutils.cpp +++ b/ui/annotationguiutils.cpp @@ -49,3 +49,35 @@ QString AnnotationGuiUtils::captionForAnnotation( Okular::Annotation * ann ) return ret; } +QString AnnotationGuiUtils::contents( const Okular::Annotation * ann ) +{ + if ( !ann ) + return QString(); + + // 1. window text + QString ret = ann->window().text(); + if ( !ret.isEmpty() ) + return ret; + // 2. if Text and InPlace, the inplace text + if ( ann->subType() == Okular::Annotation::AText ) + { + const Okular::TextAnnotation * txtann = dynamic_cast< const Okular::TextAnnotation * >( ann ); + if ( txtann->textType() == Okular::TextAnnotation::InPlace ) + { + ret = txtann->inplaceText(); + if ( !ret.isEmpty() ) + return ret; + } + } + + // 3. contents + ret = ann->contents(); + + return ret; +} + +QString AnnotationGuiUtils::contentsHtml( const Okular::Annotation * ann ) +{ + return contents( ann ).replace( "\n", "
" ); +} + diff --git a/ui/annotationguiutils.h b/ui/annotationguiutils.h index 62667a1b6..2d5b093c3 100644 --- a/ui/annotationguiutils.h +++ b/ui/annotationguiutils.h @@ -21,6 +21,9 @@ class AnnotationGuiUtils * Returns the translated string with the type of the given @p annotation. */ static QString captionForAnnotation( Okular::Annotation * annotation ); + + static QString contents( const Okular::Annotation * annotation ); + static QString contentsHtml( const Okular::Annotation * annotation ); }; diff --git a/ui/pageview.cpp b/ui/pageview.cpp index ba9184416..5ec71be22 100644 --- a/ui/pageview.cpp +++ b/ui/pageview.cpp @@ -58,6 +58,7 @@ #include "pagepainter.h" #include "core/annotations.h" #include "annotwindow.h" //"embeddedannotationdialog.h" +#include "annotationguiutils.h" #include "annotationpropertiesdialog.h" #include "pageviewannotator.h" #include "core/document.h" @@ -185,9 +186,9 @@ protected: { QRect r = rect->boundingRect( pageItem->width(), pageItem->height() ); r.translate( pageItem->geometry().left(), pageItem->geometry().top() ); - QString contents = ( !ann->window().text().isEmpty() ? ann->window().text() : ann->contents() ); + QString contents = AnnotationGuiUtils::contentsHtml( ann ); QString tip = QString( "%1
%2
" ) - .arg( i18n( "Author: %1", ann->author() ), contents.replace( "\n", "
" ) ); + .arg( i18n( "Author: %1", ann->author() ), contents ); QToolTip::showText( he->globalPos(), tip, this, r ); } else if ( link ) diff --git a/ui/side_reviews.cpp b/ui/side_reviews.cpp index 5c65dd34c..afa7d3188 100644 --- a/ui/side_reviews.cpp +++ b/ui/side_reviews.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -86,7 +87,9 @@ Reviews::Reviews( QWidget * parent, Okular::Document * document ) m_listView->header()->setResizeMode( QHeaderView::Stretch ); 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 ) ) ); } //BEGIN DocumentObserver Notifies -> requestListViewUpdate @@ -189,8 +192,6 @@ class AnnotationItem : public QTreeWidgetItem { setText( 0, AnnotationGuiUtils::captionForAnnotation( m_ann ) ); setIcon( 0, KIcon( "okular" ) ); - setToolTip( 0, QString( "%1
%2
" ) - .arg( i18n( "Author: %1", m_ann->author() ), m_ann->contents() ) ); } Okular::Annotation * annotation() @@ -350,4 +351,20 @@ void Reviews::requestListViewUpdate( int delayms ) m_delayTimer->start( delayms ); } +void Reviews::itemEntered( QTreeWidgetItem * item, int /*column*/ ) +{ + AnnotationItem * annItem = dynamic_cast< AnnotationItem * >( item ); + if ( !annItem ) + return; + + QString contents = AnnotationGuiUtils::contentsHtml( annItem->annotation() ); + if ( contents.isEmpty() ) + return; + + QString tooltip = QString( "%1
%2
" ) + .arg( i18n( "Author: %1", annItem->annotation()->author() ), contents ); + + QToolTip::showText( QCursor::pos(), tooltip, m_listView, m_listView->visualItemRect( annItem ) ); +} + #include "side_reviews.moc" diff --git a/ui/side_reviews.h b/ui/side_reviews.h index f2c38816c..11296c811 100644 --- a/ui/side_reviews.h +++ b/ui/side_reviews.h @@ -47,6 +47,7 @@ class Reviews : public QWidget, public Okular::DocumentObserver private slots: void itemActivated( QTreeWidgetItem *, int ); + void itemEntered( QTreeWidgetItem *, int ); private: // add all annotations of a page to the listView taking care of grouping