2006-12-27 23:56:38 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2006 by Pino Toscano <pino@kde.org> *
|
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU General Public License as published by *
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
2007-04-19 18:30:20 +00:00
|
|
|
#include "annotationguiutils.h"
|
|
|
|
|
2006-12-27 23:56:38 +00:00
|
|
|
// qt/kde includes
|
|
|
|
#include <klocale.h>
|
|
|
|
|
|
|
|
// local includes
|
|
|
|
#include "core/annotations.h"
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
namespace AnnotationGuiUtils {
|
|
|
|
|
|
|
|
QString captionForAnnotation( const Okular::Annotation * ann )
|
2006-12-27 23:56:38 +00:00
|
|
|
{
|
2007-10-03 22:53:27 +00:00
|
|
|
Q_ASSERT( ann );
|
2006-12-27 23:56:38 +00:00
|
|
|
|
|
|
|
QString ret;
|
|
|
|
switch( ann->subType() )
|
|
|
|
{
|
|
|
|
case Okular::Annotation::AText:
|
|
|
|
if( ( (Okular::TextAnnotation*)ann )->textType() == Okular::TextAnnotation::Linked )
|
|
|
|
ret = i18n( "Note" );
|
|
|
|
else
|
2007-08-19 16:15:55 +00:00
|
|
|
ret = i18n( "Inline Note" );
|
2006-12-27 23:56:38 +00:00
|
|
|
break;
|
|
|
|
case Okular::Annotation::ALine:
|
|
|
|
ret = i18n( "Line" );
|
|
|
|
break;
|
|
|
|
case Okular::Annotation::AGeom:
|
2007-08-19 16:15:55 +00:00
|
|
|
ret = i18n( "Geometry" );
|
2006-12-27 23:56:38 +00:00
|
|
|
break;
|
|
|
|
case Okular::Annotation::AHighlight:
|
|
|
|
ret = i18n( "Highlight" );
|
|
|
|
break;
|
|
|
|
case Okular::Annotation::AStamp:
|
|
|
|
ret = i18n( "Stamp" );
|
|
|
|
break;
|
|
|
|
case Okular::Annotation::AInk:
|
|
|
|
ret = i18n( "Ink" );
|
|
|
|
break;
|
|
|
|
case Okular::Annotation::A_BASE:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
QString authorForAnnotation( const Okular::Annotation * ann )
|
2007-09-08 14:41:40 +00:00
|
|
|
{
|
2007-10-03 22:53:27 +00:00
|
|
|
Q_ASSERT( ann );
|
2007-09-08 14:41:40 +00:00
|
|
|
|
|
|
|
return !ann->author().isEmpty() ? ann->author() : i18nc( "Unknown author", "Unknown" );
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
QString contents( const Okular::Annotation * ann )
|
2006-12-28 00:40:09 +00:00
|
|
|
{
|
2007-10-03 22:53:27 +00:00
|
|
|
Q_ASSERT( ann );
|
2006-12-28 00:40:09 +00:00
|
|
|
|
|
|
|
// 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 )
|
|
|
|
{
|
2007-06-04 20:49:48 +00:00
|
|
|
const Okular::TextAnnotation * txtann = static_cast< const Okular::TextAnnotation * >( ann );
|
2006-12-28 00:40:09 +00:00
|
|
|
if ( txtann->textType() == Okular::TextAnnotation::InPlace )
|
|
|
|
{
|
|
|
|
ret = txtann->inplaceText();
|
|
|
|
if ( !ret.isEmpty() )
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// 3. contents
|
|
|
|
ret = ann->contents();
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
QString contentsHtml( const Okular::Annotation * ann )
|
2006-12-28 00:40:09 +00:00
|
|
|
{
|
|
|
|
return contents( ann ).replace( "\n", "<br>" );
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
QString prettyToolTip( const Okular::Annotation * ann )
|
2007-09-08 14:41:40 +00:00
|
|
|
{
|
2007-10-03 22:53:27 +00:00
|
|
|
Q_ASSERT( ann );
|
2007-09-08 14:41:40 +00:00
|
|
|
|
|
|
|
QString author = authorForAnnotation( ann );
|
|
|
|
QString contents = contentsHtml( ann );
|
|
|
|
|
|
|
|
QString tooltip = QString( "<qt><b>" ) + i18n( "Author: %1", author ) + QString( "</b>" );
|
|
|
|
if ( !contents.isEmpty() )
|
2007-10-03 22:45:20 +00:00
|
|
|
tooltip += QString( "<div style=\"font-size: 4px;\"><hr /></div>" ) + contents;
|
2007-09-08 14:41:40 +00:00
|
|
|
|
|
|
|
tooltip += "</qt>";
|
|
|
|
|
|
|
|
return tooltip;
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
bool canBeMoved( const Okular::Annotation * ann )
|
2007-07-17 20:58:38 +00:00
|
|
|
{
|
2007-10-03 22:53:27 +00:00
|
|
|
Q_ASSERT( ann );
|
2007-07-17 20:58:38 +00:00
|
|
|
|
|
|
|
switch( ann->subType() )
|
|
|
|
{
|
|
|
|
case Okular::Annotation::ALine:
|
|
|
|
case Okular::Annotation::AStamp:
|
|
|
|
case Okular::Annotation::AGeom:
|
2007-07-17 21:52:22 +00:00
|
|
|
case Okular::Annotation::AInk:
|
2007-07-22 20:20:24 +00:00
|
|
|
case Okular::Annotation::AText:
|
2007-07-17 20:58:38 +00:00
|
|
|
return true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2007-09-08 14:44:21 +00:00
|
|
|
}
|