diff --git a/ui/annotationmodel.cpp b/ui/annotationmodel.cpp --- a/ui/annotationmodel.cpp +++ b/ui/annotationmodel.cpp @@ -341,14 +341,15 @@ } switch ( role ) { - case Qt::DisplayRole: - return GuiUtils::captionForAnnotation( item->annotation ); + case Qt::DisplayRole: { + return GuiUtils::captionForAnnotation( item->annotation, d->document->page(item->page) ); break; + } case Qt::DecorationRole: return QIcon::fromTheme( QStringLiteral("okular") ); break; case Qt::ToolTipRole: - return GuiUtils::prettyToolTip( item->annotation ); + return GuiUtils::prettyToolTip( item->annotation, d->document->page(item->page) ); break; case AuthorRole: return item->annotation->author(); diff --git a/ui/annotationpopup.cpp b/ui/annotationpopup.cpp --- a/ui/annotationpopup.cpp +++ b/ui/annotationpopup.cpp @@ -125,7 +125,7 @@ { foreach ( const AnnotPagePair& pair, mAnnotations ) { - menu.addAction( new OKMenuTitle( &menu, GuiUtils::captionForAnnotation( pair.annotation ) ) ); + menu.addAction( new OKMenuTitle( &menu, GuiUtils::captionForAnnotation( pair.annotation, mDocument->page(pair.pageNumber) ) ) ); action = menu.addAction( QIcon::fromTheme( QStringLiteral("comment") ), i18n( "&Open Pop-up Note" ) ); action->setData( QVariant::fromValue( pair ) ); diff --git a/ui/guiutils.h b/ui/guiutils.h --- a/ui/guiutils.h +++ b/ui/guiutils.h @@ -24,20 +24,22 @@ class Annotation; class EmbeddedFile; class Movie; +class Page; class ScreenAnnotation; } namespace GuiUtils { + QString highlightedTextForAnnotation(const Okular::Annotation * annotation, const Okular::Page * page); /** * Returns the translated string with the type of the given @p annotation. */ - QString captionForAnnotation( const Okular::Annotation * annotation ); + QString captionForAnnotation(const Okular::Annotation * annotation , const Okular::Page *page); QString authorForAnnotation( const Okular::Annotation * annotation ); QString contentsHtml( const Okular::Annotation * annotation ); - QString prettyToolTip( const Okular::Annotation * annotation ); + QString prettyToolTip( const Okular::Annotation * annotation, const Okular::Page * page ); QPixmap loadStamp( const QString& name, const QSize& size, int iconSize = 0 ); diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -23,6 +23,9 @@ #include "core/action.h" #include "core/annotations.h" #include "core/document.h" +#include "core/page.h" +#include "core/textpage.h" +#include "core/misc.h" #include @@ -60,7 +63,27 @@ namespace GuiUtils { -QString captionForAnnotation( const Okular::Annotation * ann ) +QString highlightedTextForAnnotation(const Okular::Annotation *ann, const Okular::Page *page) +{ + if (ann->subType() == Okular::Annotation::AHighlight) { + Okular::HighlightAnnotation *hAnn = (Okular::HighlightAnnotation*)ann; + QString text; + if (ann->subType() == Okular::Annotation::AHighlight) { + for (auto& quad : qAsConst(hAnn->highlightQuads())) { + auto leftTop = quad.point(0); + auto rightDown = quad.point(2); + Okular::TextSelection textSelection(leftTop, rightDown); + // TODO this does not seem to be very accurate :-( + text += page->text(page->textArea(&textSelection), Okular::TextPage::CentralPixelTextAreaInclusionBehaviour); + } + } + return text.replace('\n', ""); + } + + return QString{}; +} + +QString captionForAnnotation( const Okular::Annotation * ann, const Okular::Page * page ) { Q_ASSERT( ann ); @@ -89,23 +112,31 @@ case Okular::Annotation::AGeom: ret = hasComment ? i18n( "Geometry with Comment" ) : i18n( "Geometry" ); break; - case Okular::Annotation::AHighlight: + case Okular::Annotation::AHighlight: { + QString text = highlightedTextForAnnotation(ann, page); + switch ( ( (Okular::HighlightAnnotation*)ann )->highlightType() ) { case Okular::HighlightAnnotation::Highlight: - ret = hasComment ? i18n( "Highlight with Comment" ) : i18n( "Highlight" ); + ret = hasComment ? i18n( "Highlight with Comment" ) : + text.isEmpty() ? i18n( "Highlight" ) : i18n( "Highlight: %1", text); break; case Okular::HighlightAnnotation::Squiggly: - ret = hasComment ? i18n( "Squiggle with Comment" ) : i18n( "Squiggle" ); + ret = hasComment ? i18n( "Squiggle with Comment" ) : + text.isEmpty() ? i18n( "Squiggle" ) : i18n( "Squiggle: %1", text); break; case Okular::HighlightAnnotation::Underline: - ret = hasComment ? i18n( "Underline with Comment" ) : i18n( "Underline" ); + ret = hasComment ? i18n( "Underline with Comment" ) : + text.isEmpty() ? i18n( "Underline" ) : i18n( "Underline: %1", text); break; case Okular::HighlightAnnotation::StrikeOut: - ret = hasComment ? i18n( "Strike Out with Comment" ) : i18n( "Strike Out" ); + ret = hasComment ? i18n( "Strike Out with Comment" ) : + text.isEmpty() ? i18n( "Strike Out" ) : i18n( "Strike Out: %1", text); break; } + break; + } case Okular::Annotation::AStamp: ret = hasComment ? i18n( "Stamp with Comment" ) : i18n( "Stamp" ); break; @@ -153,7 +184,7 @@ return text; } -QString prettyToolTip( const Okular::Annotation * ann ) +QString prettyToolTip(const Okular::Annotation * ann , const Okular::Page *page) { Q_ASSERT( ann ); @@ -164,6 +195,10 @@ if ( !contents.isEmpty() ) tooltip += QStringLiteral( "

" ) + contents; + QString highlightedText = highlightedTextForAnnotation(ann, page); + if ( !highlightedText.isEmpty() ) + tooltip += QStringLiteral( "

" ) + highlightedText; + tooltip += QLatin1String(""); return tooltip; diff --git a/ui/pageview.h b/ui/pageview.h --- a/ui/pageview.h +++ b/ui/pageview.h @@ -100,7 +100,6 @@ Okular::RegularAreaRect * textSelectionForItem( const PageViewItem * item, const QPoint & startPoint = QPoint(), const QPoint & endPoint = QPoint() ); void reparseConfig(); - KActionCollection *actionCollection() const; QAction *toggleFormsAction() const; diff --git a/ui/pageviewmouseannotation.cpp b/ui/pageviewmouseannotation.cpp --- a/ui/pageviewmouseannotation.cpp +++ b/ui/pageviewmouseannotation.cpp @@ -265,7 +265,7 @@ /* content area to viewport */ boundingRect.translate( -m_pageView->contentAreaPosition() ); - const QString tip = GuiUtils::prettyToolTip( m_mouseOverAnnotation.annotation ); + const QString tip = GuiUtils::prettyToolTip( m_mouseOverAnnotation.annotation, m_document->page(m_mouseOverAnnotation.pageNumber) ); QToolTip::showText( helpEvent->globalPos(), tip, m_pageView->viewport(), boundingRect ); } }