mirror of
https://invent.kde.org/graphics/okular
synced 2024-08-27 11:40:07 +00:00
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
This commit is contained in:
parent
48a772be4b
commit
ea071caf9d
|
@ -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", "<br>" );
|
||||
}
|
||||
|
||||
|
|
|
@ -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 );
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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( "<qt><b>%1</b><hr>%2</qt>" )
|
||||
.arg( i18n( "Author: %1", ann->author() ), contents.replace( "\n", "<br>" ) );
|
||||
.arg( i18n( "Author: %1", ann->author() ), contents );
|
||||
QToolTip::showText( he->globalPos(), tip, this, r );
|
||||
}
|
||||
else if ( link )
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <qstringlist.h>
|
||||
#include <qtimer.h>
|
||||
#include <qtoolbar.h>
|
||||
#include <qtooltip.h>
|
||||
#include <qtreewidget.h>
|
||||
#include <kaction.h>
|
||||
#include <klocale.h>
|
||||
|
@ -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( "<qt><b>%1</b><hr>%2</qt>" )
|
||||
.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( "<qt><b>%1</b><hr>%2</qt>" )
|
||||
.arg( i18n( "Author: %1", annItem->annotation()->author() ), contents );
|
||||
|
||||
QToolTip::showText( QCursor::pos(), tooltip, m_listView, m_listView->visualItemRect( annItem ) );
|
||||
}
|
||||
|
||||
#include "side_reviews.moc"
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue