Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 815ac386 authored by Pino Toscano's avatar Pino Toscano

move the annotation tooltip creation procedure in a single place

svn path=/trunk/KDE/kdegraphics/okular/; revision=709910
parent 0bfbda88
......@@ -50,6 +50,14 @@ QString AnnotationGuiUtils::captionForAnnotation( Okular::Annotation * ann )
return ret;
}
QString AnnotationGuiUtils::authorForAnnotation( const Okular::Annotation * ann )
{
if ( !ann )
return QString();
return !ann->author().isEmpty() ? ann->author() : i18nc( "Unknown author", "Unknown" );
}
QString AnnotationGuiUtils::contents( const Okular::Annotation * ann )
{
if ( !ann )
......@@ -82,6 +90,23 @@ QString AnnotationGuiUtils::contentsHtml( const Okular::Annotation * ann )
return contents( ann ).replace( "\n", "<br>" );
}
QString AnnotationGuiUtils::prettyToolTip( const Okular::Annotation * ann )
{
if ( !ann )
return QString();
QString author = authorForAnnotation( ann );
QString contents = contentsHtml( ann );
QString tooltip = QString( "<qt><b>" ) + i18n( "Author: %1", author ) + QString( "</b>" );
if ( !contents.isEmpty() )
tooltip += QString( "<hr />" ) + contents;
tooltip += "</qt>";
return tooltip;
}
bool AnnotationGuiUtils::canBeMoved( Okular::Annotation * ann )
{
if ( !ann )
......
......@@ -23,10 +23,13 @@ class AnnotationGuiUtils
* Returns the translated string with the type of the given @p annotation.
*/
static QString captionForAnnotation( Okular::Annotation * annotation );
static QString authorForAnnotation( const Okular::Annotation * annotation );
static QString contents( const Okular::Annotation * annotation );
static QString contentsHtml( const Okular::Annotation * annotation );
static QString prettyToolTip( const Okular::Annotation * annotation );
static bool canBeMoved( Okular::Annotation * annotation );
};
......
......@@ -185,9 +185,7 @@ protected:
{
QRect r = rect->boundingRect( pageItem->width(), pageItem->height() );
r.translate( pageItem->geometry().left(), pageItem->geometry().top() );
QString contents = AnnotationGuiUtils::contentsHtml( ann );
QString tip = QString( "<qt><b>%1</b><hr>%2</qt>" )
.arg( i18n( "Author: %1", ann->author() ), contents );
QString tip = AnnotationGuiUtils::prettyToolTip( ann );
QToolTip::showText( he->globalPos(), tip, this, r );
}
else if ( link )
......
......@@ -322,7 +322,7 @@ void Reviews::addContents( const Okular::Page * page )
authorItem = new QTreeWidgetItem( pageItem );
else
authorItem = new QTreeWidgetItem( m_listView );
authorItem->setText( 0, !author.isEmpty() ? author : i18nc( "Unknown author", "Unknown" ) );
authorItem->setText( 0, AnnotationGuiUtils::authorForAnnotation( annotation ) );
authorItem->setIcon( 0, KIcon( !author.isEmpty() ? "personal" : "presence_away" ) );
authorItem->setData( 0, AuthorRole, author );
}
......@@ -361,12 +361,7 @@ void Reviews::itemEntered( QTreeWidgetItem * item, int /*column*/ )
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 );
QString tooltip = AnnotationGuiUtils::prettyToolTip( annItem->annotation() );
QToolTip::showText( QCursor::pos(), tooltip, m_listView, m_listView->visualItemRect( annItem ) );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment