2005-03-04 23:06:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* Copyright (C) 2005 by Enrico Ros <eros.kde@email.it> *
|
|
|
|
* *
|
|
|
|
* 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 "pageviewannotator.h"
|
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
// qt / kde includes
|
|
|
|
#include <qfile.h>
|
|
|
|
#include <qcolor.h>
|
|
|
|
#include <qevent.h>
|
2006-10-22 16:43:55 +00:00
|
|
|
#include <qlist.h>
|
2005-03-04 23:06:24 +00:00
|
|
|
#include <qpainter.h>
|
2006-10-22 20:53:56 +00:00
|
|
|
#include <qset.h>
|
2006-09-08 23:06:22 +00:00
|
|
|
#include <qvariant.h>
|
2005-03-04 23:06:24 +00:00
|
|
|
#include <kiconloader.h>
|
|
|
|
#include <klocale.h>
|
|
|
|
#include <kstandarddirs.h>
|
2005-03-13 17:23:12 +00:00
|
|
|
#include <kinputdialog.h>
|
|
|
|
#include <kuser.h>
|
2005-03-04 23:06:24 +00:00
|
|
|
#include <kdebug.h>
|
2006-08-08 15:31:13 +00:00
|
|
|
#include <kmenu.h>
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
// system includes
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
// local includes
|
2006-10-22 20:53:56 +00:00
|
|
|
#include "core/area.h"
|
2005-03-04 23:06:24 +00:00
|
|
|
#include "core/document.h"
|
|
|
|
#include "core/page.h"
|
|
|
|
#include "core/annotations.h"
|
2006-03-28 22:22:10 +00:00
|
|
|
#include "settings.h"
|
2006-11-01 15:23:11 +00:00
|
|
|
#include "annotationtools.h"
|
2005-03-04 23:06:24 +00:00
|
|
|
#include "pageview.h"
|
|
|
|
|
|
|
|
/** @short PickPointEngine */
|
|
|
|
class PickPointEngine : public AnnotatorEngine
|
|
|
|
{
|
|
|
|
public:
|
2005-04-01 14:00:59 +00:00
|
|
|
PickPointEngine( const QDomElement & engineElement )
|
2006-11-18 23:51:20 +00:00
|
|
|
: AnnotatorEngine( engineElement ), clicked( false ), pixmap( 0 ),
|
|
|
|
xscale( 1.0 ), yscale( 1.0 )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2005-04-01 14:00:59 +00:00
|
|
|
// parse engine specific attributes
|
2006-09-10 16:10:40 +00:00
|
|
|
pixmapName = engineElement.attribute( "hoverIcon" );
|
2006-09-11 11:51:10 +00:00
|
|
|
QString stampname = m_annotElement.attribute( "icon" );
|
|
|
|
if ( m_annotElement.attribute( "type" ) == "Stamp" && !stampname.simplified().isEmpty() )
|
|
|
|
pixmapName = stampname;
|
2006-09-08 23:06:22 +00:00
|
|
|
center = QVariant( engineElement.attribute( "center" ) ).toBool();
|
2006-09-10 16:10:40 +00:00
|
|
|
bool ok = true;
|
|
|
|
size = engineElement.attribute( "size", "32" ).toInt( &ok );
|
|
|
|
if ( !ok )
|
|
|
|
size = 32;
|
2007-03-24 22:45:14 +00:00
|
|
|
m_block = QVariant( engineElement.attribute( "block" ) ).toBool();
|
2005-04-01 14:00:59 +00:00
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// create engine objects
|
2006-11-18 23:51:20 +00:00
|
|
|
if ( !pixmapName.simplified().isEmpty() )
|
2006-11-18 21:24:25 +00:00
|
|
|
pixmap = new QPixmap( DesktopIcon( pixmapName, size ) );
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
2005-04-01 14:00:59 +00:00
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
~PickPointEngine()
|
|
|
|
{
|
|
|
|
delete pixmap;
|
|
|
|
}
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
QRect event( EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * page )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2006-08-08 15:31:13 +00:00
|
|
|
xscale=xScale;
|
|
|
|
yscale=yScale;
|
2006-09-16 21:16:58 +00:00
|
|
|
pagewidth = page->width();
|
|
|
|
pageheight = page->height();
|
2005-03-04 23:06:24 +00:00
|
|
|
// only proceed if pressing left button
|
2006-08-08 15:31:13 +00:00
|
|
|
if ( button != Left )
|
|
|
|
return QRect();
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
// start operation on click
|
|
|
|
if ( type == Press && clicked == false )
|
|
|
|
{
|
|
|
|
clicked = true;
|
2006-08-10 15:12:37 +00:00
|
|
|
startpoint.x=nX;
|
|
|
|
startpoint.y=nY;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
// repaint if moving while pressing
|
|
|
|
else if ( type == Move && clicked == true )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
// operation finished on release
|
|
|
|
else if ( type == Release && clicked == true )
|
|
|
|
{
|
|
|
|
m_creationCompleted = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
return QRect();
|
2005-04-01 14:00:59 +00:00
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// update variables and extents (zoom invariant rect)
|
2005-03-04 23:06:24 +00:00
|
|
|
point.x = nX;
|
|
|
|
point.y = nY;
|
2006-11-18 21:24:25 +00:00
|
|
|
if ( center && pixmap )
|
2006-09-08 23:06:22 +00:00
|
|
|
{
|
2006-09-10 16:10:40 +00:00
|
|
|
rect.left = nX - ( pixmap->width() / ( xScale * 2.0 ) );
|
|
|
|
rect.top = nY - ( pixmap->height() / ( yScale * 2.0 ) );
|
2006-09-08 23:06:22 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect.left = nX;
|
|
|
|
rect.top = nY;
|
|
|
|
}
|
2006-11-18 21:24:25 +00:00
|
|
|
rect.right = rect.left + ( pixmap ? pixmap->width() / xScale : 0 );
|
|
|
|
rect.bottom = rect.top + ( pixmap ? pixmap->height() / yScale : 0 );
|
2007-03-24 22:45:14 +00:00
|
|
|
QRect boundrect = rect.geometry( (int)xScale, (int)yScale ).adjusted( 0, 0, 1, 1 );
|
|
|
|
if ( m_block )
|
|
|
|
{
|
|
|
|
Okular::NormalizedRect tmprect( qMin( startpoint.x, point.x ), qMin( startpoint.y, point.y ), qMax( startpoint.x, point.x ), qMax( startpoint.y, point.y ) );
|
|
|
|
boundrect |= tmprect.geometry( (int)xScale, (int)yScale ).adjusted( 0, 0, 1, 1 );
|
|
|
|
}
|
|
|
|
return boundrect;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ )
|
|
|
|
{
|
2007-03-24 22:45:14 +00:00
|
|
|
if ( clicked )
|
2005-04-01 14:00:59 +00:00
|
|
|
{
|
2007-03-24 22:45:14 +00:00
|
|
|
if ( m_block )
|
|
|
|
{
|
|
|
|
QPen origpen = painter->pen();
|
|
|
|
QPen pen = painter->pen();
|
|
|
|
pen.setStyle( Qt::DashLine );
|
|
|
|
painter->setPen( pen );
|
|
|
|
Okular::NormalizedRect tmprect( qMin( startpoint.x, point.x ), qMin( startpoint.y, point.y ), qMax( startpoint.x, point.x ), qMax( startpoint.y, point.y ) );
|
2007-12-09 10:38:14 +00:00
|
|
|
QRect realrect = tmprect.geometry( (int)xScale, (int)yScale );
|
2007-03-24 22:45:14 +00:00
|
|
|
painter->drawRect( realrect );
|
|
|
|
painter->setPen( origpen );
|
|
|
|
}
|
|
|
|
if ( pixmap )
|
|
|
|
painter->drawPixmap( QPointF( rect.left * xScale, rect.top * yScale ), *pixmap );
|
2005-04-01 14:00:59 +00:00
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
2006-10-22 16:43:55 +00:00
|
|
|
QList< Okular::Annotation* > end()
|
2006-08-08 15:31:13 +00:00
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
m_creationCompleted = false;
|
|
|
|
|
2006-08-08 15:31:13 +00:00
|
|
|
// find out annotation's description node
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( m_annotElement.isNull() )
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
2006-12-11 07:59:02 +00:00
|
|
|
|
2006-08-08 15:31:13 +00:00
|
|
|
// find out annotation's type
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * ann = 0;
|
2006-09-11 11:51:10 +00:00
|
|
|
QString typeString = m_annotElement.attribute( "type" );
|
2006-08-08 15:31:13 +00:00
|
|
|
// create TextAnnotation from path
|
|
|
|
if ( typeString == "FreeText") //<annotation type="Text"
|
|
|
|
{
|
|
|
|
//note dialog
|
2007-08-19 16:15:55 +00:00
|
|
|
QString prompt = i18n( "Text of the new note:" );
|
2006-08-08 15:31:13 +00:00
|
|
|
bool resok;
|
2007-08-19 16:15:55 +00:00
|
|
|
QString note = KInputDialog::getMultiLineText( i18n( "New Text Note" ), prompt, QString(), &resok );
|
2006-08-08 15:31:13 +00:00
|
|
|
if(resok)
|
|
|
|
{
|
|
|
|
//add note
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextAnnotation * ta = new Okular::TextAnnotation();
|
2006-08-08 15:31:13 +00:00
|
|
|
ann = ta;
|
2006-12-11 07:59:02 +00:00
|
|
|
ta->setInplaceText( note );
|
|
|
|
ta->setTextType( Okular::TextAnnotation::InPlace );
|
2006-08-08 15:31:13 +00:00
|
|
|
//set boundary
|
2006-08-10 15:12:37 +00:00
|
|
|
rect.left = qMin(startpoint.x,point.x);
|
|
|
|
rect.top = qMin(startpoint.y,point.y);
|
|
|
|
rect.right = qMax(startpoint.x,point.x);
|
|
|
|
rect.bottom = qMax(startpoint.y,point.y);
|
2007-07-31 10:19:48 +00:00
|
|
|
kDebug().nospace() << "xyScale=" << xscale << "," << yscale;
|
2006-09-10 16:10:40 +00:00
|
|
|
static int padding = 2;
|
2006-12-11 07:59:02 +00:00
|
|
|
QFontMetricsF mf(ta->textFont());
|
2006-09-21 08:45:36 +00:00
|
|
|
QRectF rcf = mf.boundingRect( Okular::NormalizedRect( rect.left, rect.top, 1.0, 1.0 ).geometry( (int)pagewidth, (int)pageheight ).adjusted( padding, padding, -padding, -padding ),
|
2006-12-11 07:59:02 +00:00
|
|
|
Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->inplaceText() );
|
2006-09-16 21:16:58 +00:00
|
|
|
rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth);
|
|
|
|
rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight);
|
2006-12-05 11:05:50 +00:00
|
|
|
ta->setBoundingRectangle( this->rect );
|
|
|
|
ta->window().setSummary( "TextBox" );
|
2006-08-08 15:31:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if ( typeString == "Text")
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::TextAnnotation * ta = new Okular::TextAnnotation();
|
2006-08-08 15:31:13 +00:00
|
|
|
ann = ta;
|
2006-12-11 07:59:02 +00:00
|
|
|
ta->setTextType( Okular::TextAnnotation::Linked );
|
2006-12-05 11:05:50 +00:00
|
|
|
ta->window().setText( QString() );
|
2006-09-21 08:45:36 +00:00
|
|
|
//ta->window.flags &= ~(Okular::Annotation::Hidden);
|
2006-08-10 15:12:37 +00:00
|
|
|
double iconhei=0.03;
|
|
|
|
rect.left = point.x;
|
|
|
|
rect.top = point.y;
|
|
|
|
rect.right=rect.left+iconhei;
|
|
|
|
rect.bottom=rect.top+iconhei*xscale/yscale;
|
2006-12-05 11:05:50 +00:00
|
|
|
ta->setBoundingRectangle( this->rect );
|
|
|
|
ta->window().setSummary( "Note" );
|
2006-08-08 15:31:13 +00:00
|
|
|
}
|
|
|
|
// create StampAnnotation from path
|
|
|
|
else if ( typeString == "Stamp" )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::StampAnnotation * sa = new Okular::StampAnnotation();
|
2006-08-08 15:31:13 +00:00
|
|
|
ann = sa;
|
2006-12-11 07:59:02 +00:00
|
|
|
sa->setStampIconName( pixmapName );
|
2006-09-10 16:10:40 +00:00
|
|
|
double stampxscale = size / xscale;
|
|
|
|
double stampyscale = size / yscale;
|
|
|
|
if ( center )
|
|
|
|
{
|
|
|
|
rect.left = point.x - stampxscale / 2;
|
|
|
|
rect.top = point.y - stampyscale / 2;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rect.left = point.x;
|
|
|
|
rect.top = point.y;
|
|
|
|
}
|
|
|
|
rect.right = rect.left + stampxscale;
|
|
|
|
rect.bottom = rect.top + stampyscale;
|
2006-12-05 11:05:50 +00:00
|
|
|
sa->setBoundingRectangle( rect );
|
2006-08-08 15:31:13 +00:00
|
|
|
}
|
2006-11-19 00:46:01 +00:00
|
|
|
// create GeomAnnotation
|
|
|
|
else if ( typeString == "GeomSquare" || typeString == "GeomCircle" )
|
|
|
|
{
|
|
|
|
Okular::GeomAnnotation * ga = new Okular::GeomAnnotation();
|
|
|
|
ann = ga;
|
|
|
|
// set the type
|
|
|
|
if ( typeString == "GeomSquare" )
|
2006-12-11 07:59:02 +00:00
|
|
|
ga->setGeometricalType( Okular::GeomAnnotation::InscribedSquare );
|
2006-11-19 00:46:01 +00:00
|
|
|
else
|
2006-12-11 07:59:02 +00:00
|
|
|
ga->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
|
|
|
|
ga->setGeometricalPointWidth( 18 );
|
2006-11-19 00:46:01 +00:00
|
|
|
//set boundary
|
|
|
|
rect.left = qMin( startpoint.x, point.x );
|
|
|
|
rect.top = qMin( startpoint.y, point.y );
|
|
|
|
rect.right = qMax( startpoint.x, point.x );
|
|
|
|
rect.bottom = qMax( startpoint.y, point.y );
|
2006-12-05 11:05:50 +00:00
|
|
|
ga->setBoundingRectangle( rect );
|
2006-11-19 00:46:01 +00:00
|
|
|
}
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// safety check
|
|
|
|
if ( !ann )
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// set common attributes
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setColor( m_annotElement.hasAttribute( "color" ) ?
|
|
|
|
m_annotElement.attribute( "color" ) : m_engineColor );
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( m_annotElement.hasAttribute( "opacity" ) )
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setOpacity( m_annotElement.attribute( "opacity", "1.0" ).toDouble() );
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// return annotation
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >() << ann;
|
2006-07-08 17:52:42 +00:00
|
|
|
}
|
2005-04-01 14:00:59 +00:00
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
private:
|
|
|
|
bool clicked;
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedRect rect;
|
|
|
|
Okular::NormalizedPoint startpoint;
|
|
|
|
Okular::NormalizedPoint point;
|
2005-03-04 23:06:24 +00:00
|
|
|
QPixmap * pixmap;
|
2006-09-10 16:10:40 +00:00
|
|
|
QString pixmapName;
|
|
|
|
int size;
|
2006-08-08 15:31:13 +00:00
|
|
|
double xscale,yscale;
|
2006-09-16 21:16:58 +00:00
|
|
|
double pagewidth, pageheight;
|
2006-09-08 23:06:22 +00:00
|
|
|
bool center;
|
2007-03-24 22:45:14 +00:00
|
|
|
bool m_block;
|
2005-03-04 23:06:24 +00:00
|
|
|
};
|
|
|
|
|
2006-09-11 11:51:10 +00:00
|
|
|
/** @short PolyLineEngine */
|
|
|
|
class PolyLineEngine : public AnnotatorEngine
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
|
|
|
public:
|
2006-09-11 11:51:10 +00:00
|
|
|
PolyLineEngine( const QDomElement & engineElement )
|
|
|
|
: AnnotatorEngine( engineElement ), last( false )
|
2005-04-01 14:00:59 +00:00
|
|
|
{
|
|
|
|
// parse engine specific attributes
|
|
|
|
m_block = engineElement.attribute( "block" ) == "true";
|
2006-09-11 11:51:10 +00:00
|
|
|
bool ok = true;
|
|
|
|
// numofpoints represents the max number of points for the current
|
|
|
|
// polygon/polyline, with a pair of exceptions:
|
|
|
|
// -1 means: the polyline must close on the first point (polygon)
|
|
|
|
// 0 means: construct as many points as you want, right-click
|
|
|
|
// to construct the last point
|
|
|
|
numofpoints = engineElement.attribute( "points" ).toInt( &ok );
|
|
|
|
if ( !ok )
|
|
|
|
numofpoints = -1;
|
2005-04-01 14:00:59 +00:00
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
QRect event( EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/ )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
|
|
|
// only proceed if pressing left button
|
2006-09-11 11:51:10 +00:00
|
|
|
// if ( button != Left )
|
|
|
|
// return rect;
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
// start operation
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( type == Press )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
- GIGANTIC 2700 line diff with LOTS OF FEATURES!
- 1. editor-like text selection, and I do mean it, its not pseudo-editor
(like the ones acroread and kviewshell have) it doesnt intersect the
selection area with words under it, no, it does a lot more, including
work on cursors and searching for the text area closest to the given
cursor
- 2. rotation support, change the orientation of the documents if
you need too :)
- 3. the kfaxview backend works beautifully, porting kviewshell backends
is damn easy ! djvu and dvi will be next!
- 4. Hardware Blending of selection rectangles! We now use XRender
instead of KImageEffect, makes a damn faster blend!
- 5. Overview mode - as seen in Kviewshell, but quite a bit extended,
the kviewshell is only one state, while we support it in both
continous and non-continous form
- BTW. I coded all those features myself, (apart from kfaxview backend library)
it is an impressive bit right? but oKular cant be run by only one person,
join in on the fun! i can introduce you into the code just mail niedakh@gmail.com
svn path=/trunk/playground/graphics/oKular/kpdf/; revision=509871
2006-02-15 18:54:49 +00:00
|
|
|
newPoint.x = nX;
|
|
|
|
newPoint.y = nY;
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( button == Right )
|
|
|
|
last = true;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
// move the second point
|
2006-09-11 11:51:10 +00:00
|
|
|
else if ( type == Move )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
movingpoint.x = nX;
|
|
|
|
movingpoint.y = nY;
|
|
|
|
QRect oldmovingrect = movingrect;
|
|
|
|
movingrect = rect | QRect( (int)( movingpoint.x * xScale ), (int)( movingpoint.y * yScale ), 1, 1 );
|
|
|
|
return oldmovingrect | movingrect;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
2006-09-11 11:51:10 +00:00
|
|
|
else if ( type == Release )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedPoint tmppoint;
|
2006-09-11 11:51:10 +00:00
|
|
|
tmppoint.x = nX;
|
|
|
|
tmppoint.y = nY;
|
|
|
|
if ( fabs( tmppoint.x - newPoint.x + tmppoint.y - newPoint.y ) > 1e-2 )
|
|
|
|
return rect;
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( numofpoints == -1 && points.count() > 1 && ( fabs( points[0].x - newPoint.x + points[0].y - newPoint.y ) < 1e-2 ) )
|
|
|
|
{
|
|
|
|
last = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
points.append( newPoint );
|
|
|
|
rect |= QRect( (int)( newPoint.x * xScale ), (int)( newPoint.y * yScale ), 1, 1 );
|
|
|
|
}
|
|
|
|
// end creation if we have constructed the last point of enough points
|
|
|
|
if ( last || points.count() == numofpoints )
|
|
|
|
{
|
|
|
|
m_creationCompleted = true;
|
|
|
|
last = false;
|
2006-09-21 08:45:36 +00:00
|
|
|
normRect = Okular::NormalizedRect( rect, xScale, yScale );
|
2006-09-11 11:51:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return rect;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ )
|
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( points.count() < 1 )
|
2005-03-04 23:06:24 +00:00
|
|
|
return;
|
|
|
|
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( m_block && points.count() == 2 )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedPoint first = points[0];
|
|
|
|
Okular::NormalizedPoint second = points[1];
|
2005-03-04 23:06:24 +00:00
|
|
|
// draw a semitransparent block around the 2 points
|
2005-04-01 14:00:59 +00:00
|
|
|
painter->setPen( m_engineColor );
|
|
|
|
painter->setBrush( QBrush( m_engineColor.light(), Qt::Dense4Pattern ) );
|
2005-03-04 23:06:24 +00:00
|
|
|
painter->drawRect( (int)(first.x * (double)xScale), (int)(first.y * (double)yScale),
|
|
|
|
(int)((second.x - first.x) * (double)xScale), (int)((second.y - first.y) * (double)yScale) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
// draw a polyline that connects the constructed points
|
2005-04-01 14:00:59 +00:00
|
|
|
painter->setPen( QPen( m_engineColor, 2 ) );
|
2006-09-11 11:51:10 +00:00
|
|
|
for ( int i = 1; i < points.count(); ++i )
|
|
|
|
painter->drawLine( (int)(points[i - 1].x * (double)xScale), (int)(points[i - 1].y * (double)yScale),
|
|
|
|
(int)(points[i].x * (double)xScale), (int)(points[i].y * (double)yScale) );
|
|
|
|
painter->drawLine( (int)(points.last().x * (double)xScale), (int)(points.last().y * (double)yScale),
|
|
|
|
(int)(movingpoint.x * (double)xScale), (int)(movingpoint.y * (double)yScale) );
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-22 16:43:55 +00:00
|
|
|
QList< Okular::Annotation* > end()
|
2006-08-08 15:31:13 +00:00
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
m_creationCompleted = false;
|
|
|
|
|
2006-12-11 07:59:02 +00:00
|
|
|
// find out annotation's description node
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( m_annotElement.isNull() )
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// find out annotation's type
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Annotation * ann = 0;
|
2006-09-11 11:51:10 +00:00
|
|
|
QString typeString = m_annotElement.attribute( "type" );
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// create LineAnnotation from path
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( typeString == "Line" || typeString == "Polyline" || typeString == "Polygon" )
|
2006-08-08 15:31:13 +00:00
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( points.count() < 2 )
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
2006-12-11 07:59:02 +00:00
|
|
|
|
2006-08-08 15:31:13 +00:00
|
|
|
//add note
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::LineAnnotation * la = new Okular::LineAnnotation();
|
2006-08-08 15:31:13 +00:00
|
|
|
ann = la;
|
2006-12-11 07:59:02 +00:00
|
|
|
QLinkedList<Okular::NormalizedPoint> list;
|
2006-09-11 11:51:10 +00:00
|
|
|
for ( int i = 0; i < points.count(); ++i )
|
2006-12-11 07:59:02 +00:00
|
|
|
list.append( points[ i ] );
|
|
|
|
|
|
|
|
la->setLinePoints( list );
|
|
|
|
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( numofpoints == -1 )
|
2006-12-11 07:59:02 +00:00
|
|
|
la->setLineClosed( true );
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
la->setBoundingRectangle( normRect );
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// safety check
|
|
|
|
if ( !ann )
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
2006-08-08 15:31:13 +00:00
|
|
|
|
|
|
|
// set common attributes
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setColor( m_annotElement.hasAttribute( "color" ) ?
|
|
|
|
m_annotElement.attribute( "color" ) : m_engineColor );
|
2006-09-11 11:51:10 +00:00
|
|
|
if ( m_annotElement.hasAttribute( "opacity" ) )
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setOpacity( m_annotElement.attribute( "opacity", "1.0" ).toDouble() );
|
2006-08-08 15:31:13 +00:00
|
|
|
// return annotation
|
2006-08-09 15:28:29 +00:00
|
|
|
|
2006-10-22 16:43:55 +00:00
|
|
|
return QList< Okular::Annotation* >() << ann;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2006-09-21 08:45:36 +00:00
|
|
|
QList<Okular::NormalizedPoint> points;
|
|
|
|
Okular::NormalizedPoint newPoint;
|
|
|
|
Okular::NormalizedPoint movingpoint;
|
2006-09-11 11:51:10 +00:00
|
|
|
QRect rect;
|
|
|
|
QRect movingrect;
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::NormalizedRect normRect;
|
2005-03-04 23:06:24 +00:00
|
|
|
bool m_block;
|
2006-09-11 11:51:10 +00:00
|
|
|
bool last;
|
|
|
|
int numofpoints;
|
2005-03-04 23:06:24 +00:00
|
|
|
};
|
|
|
|
|
2006-10-22 20:53:56 +00:00
|
|
|
/** @short TextSelectorEngine */
|
|
|
|
class TextSelectorEngine : public AnnotatorEngine
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextSelectorEngine( const QDomElement & engineElement, PageView * pageView )
|
2006-10-22 21:20:08 +00:00
|
|
|
: AnnotatorEngine( engineElement ), m_pageView( pageView ),
|
|
|
|
selection( 0 )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
|
|
|
// parse engine specific attributes
|
|
|
|
}
|
|
|
|
|
2007-12-25 14:21:49 +00:00
|
|
|
~TextSelectorEngine()
|
|
|
|
{
|
|
|
|
delete selection;
|
|
|
|
}
|
|
|
|
|
2006-10-22 20:53:56 +00:00
|
|
|
QRect event( EventType type, Button button, double nX, double nY, double xScale, double yScale, const Okular::Page * /*page*/ )
|
|
|
|
{
|
|
|
|
// only proceed if pressing left button
|
|
|
|
if ( button != Left )
|
|
|
|
return QRect();
|
|
|
|
|
|
|
|
if ( type == Press )
|
|
|
|
{
|
|
|
|
lastPoint.x = nX;
|
|
|
|
lastPoint.y = nY;
|
|
|
|
QRect oldrect = rect;
|
|
|
|
rect = QRect();
|
|
|
|
return oldrect;
|
|
|
|
}
|
|
|
|
else if ( type == Move )
|
|
|
|
{
|
|
|
|
if ( item() )
|
|
|
|
{
|
|
|
|
QPoint start( (int)( lastPoint.x * item()->width() ), (int)( lastPoint.y * item()->height() ) );
|
|
|
|
QPoint end( (int)( nX * item()->width() ), (int)( nY * item()->height() ) );
|
|
|
|
Okular::RegularAreaRect * newselection = m_pageView->textSelectionForItem( item(), start, end );
|
2006-12-27 17:10:06 +00:00
|
|
|
QList<QRect> geom = newselection->geometry( (int)xScale, (int)yScale );
|
2006-10-22 20:53:56 +00:00
|
|
|
QRect newrect;
|
2006-12-27 17:10:06 +00:00
|
|
|
foreach( const QRect& r, geom )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
2006-12-27 17:10:06 +00:00
|
|
|
if ( newrect.isNull() )
|
|
|
|
newrect = r;
|
|
|
|
else
|
|
|
|
newrect |= r;
|
2006-10-22 20:53:56 +00:00
|
|
|
}
|
|
|
|
rect |= newrect;
|
|
|
|
delete selection;
|
|
|
|
selection = newselection;
|
|
|
|
}
|
|
|
|
}
|
2006-11-18 15:22:16 +00:00
|
|
|
else if ( type == Release && selection )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
|
|
|
m_creationCompleted = true;
|
|
|
|
}
|
|
|
|
return rect;
|
|
|
|
}
|
|
|
|
|
|
|
|
void paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ )
|
|
|
|
{
|
|
|
|
if ( selection )
|
|
|
|
{
|
|
|
|
painter->setPen( Qt::NoPen );
|
2006-10-23 21:35:58 +00:00
|
|
|
QColor col = m_engineColor;
|
|
|
|
col.setAlphaF( 0.5 );
|
|
|
|
painter->setBrush( col );
|
2006-12-24 18:19:18 +00:00
|
|
|
foreach( const Okular::NormalizedRect & r, *selection )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
2006-12-24 18:19:18 +00:00
|
|
|
painter->drawRect( r.geometry( (int)xScale, (int)yScale ) );
|
2006-10-22 20:53:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
QList< Okular::Annotation* > end()
|
|
|
|
{
|
|
|
|
m_creationCompleted = false;
|
|
|
|
|
2006-11-18 15:22:16 +00:00
|
|
|
// safety checks
|
|
|
|
if ( m_annotElement.isNull() || !selection )
|
2006-10-22 20:53:56 +00:00
|
|
|
return QList< Okular::Annotation* >();
|
|
|
|
|
|
|
|
// find out annotation's type
|
|
|
|
Okular::Annotation * ann = 0;
|
|
|
|
QString typeString = m_annotElement.attribute( "type" );
|
|
|
|
|
|
|
|
Okular::HighlightAnnotation::HighlightType type = Okular::HighlightAnnotation::Highlight;
|
|
|
|
bool typevalid = false;
|
|
|
|
// create HighlightAnnotation's from the selected area
|
|
|
|
if ( typeString == "Highlight" )
|
|
|
|
{
|
|
|
|
type = Okular::HighlightAnnotation::Highlight;
|
|
|
|
typevalid = true;
|
|
|
|
}
|
|
|
|
else if ( typeString == "Squiggly" )
|
|
|
|
{
|
|
|
|
type = Okular::HighlightAnnotation::Squiggly;
|
|
|
|
typevalid = true;
|
|
|
|
}
|
|
|
|
else if ( typeString == "Underline" )
|
|
|
|
{
|
|
|
|
type = Okular::HighlightAnnotation::Underline;
|
|
|
|
typevalid = true;
|
|
|
|
}
|
|
|
|
else if ( typeString == "StrikeOut" )
|
|
|
|
{
|
|
|
|
type = Okular::HighlightAnnotation::StrikeOut;
|
|
|
|
typevalid = true;
|
|
|
|
}
|
|
|
|
if ( typevalid )
|
|
|
|
{
|
|
|
|
Okular::HighlightAnnotation * ha = new Okular::HighlightAnnotation();
|
2006-12-11 07:59:02 +00:00
|
|
|
ha->setHighlightType( type );
|
2006-12-05 11:05:50 +00:00
|
|
|
ha->setBoundingRectangle( Okular::NormalizedRect( rect, (int)item()->width(), (int)item()->height() ) );
|
2006-12-27 17:25:26 +00:00
|
|
|
foreach ( const Okular::NormalizedRect & r, *selection )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
|
|
|
Okular::HighlightAnnotation::Quad q;
|
2006-12-11 07:59:02 +00:00
|
|
|
q.setCapStart( false );
|
|
|
|
q.setCapEnd( false );
|
|
|
|
q.setFeather( 1.0 );
|
2006-12-27 17:25:26 +00:00
|
|
|
q.setPoint( Okular::NormalizedPoint( r.left, r.bottom ), 0 );
|
|
|
|
q.setPoint( Okular::NormalizedPoint( r.right, r.bottom ), 1 );
|
|
|
|
q.setPoint( Okular::NormalizedPoint( r.right, r.top ), 2 );
|
|
|
|
q.setPoint( Okular::NormalizedPoint( r.left, r.top ), 3 );
|
2006-12-11 07:59:02 +00:00
|
|
|
ha->highlightQuads().append( q );
|
2006-10-22 20:53:56 +00:00
|
|
|
}
|
|
|
|
ann = ha;
|
|
|
|
}
|
|
|
|
|
2007-03-26 00:01:22 +00:00
|
|
|
delete selection;
|
|
|
|
selection = 0;
|
|
|
|
|
2006-10-22 20:53:56 +00:00
|
|
|
// safety check
|
|
|
|
if ( !ann )
|
|
|
|
return QList< Okular::Annotation* >();
|
|
|
|
|
|
|
|
// set common attributes
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setColor( m_annotElement.hasAttribute( "color" ) ?
|
|
|
|
m_annotElement.attribute( "color" ) : m_engineColor );
|
2006-10-22 20:53:56 +00:00
|
|
|
if ( m_annotElement.hasAttribute( "opacity" ) )
|
2006-12-05 11:05:50 +00:00
|
|
|
ann->style().setOpacity( m_annotElement.attribute( "opacity", "1.0" ).toDouble() );
|
2006-10-22 20:53:56 +00:00
|
|
|
|
|
|
|
// return annotations
|
|
|
|
return QList< Okular::Annotation* >() << ann;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// data
|
|
|
|
PageView * m_pageView;
|
|
|
|
// TODO: support more pages
|
|
|
|
Okular::RegularAreaRect * selection;
|
|
|
|
Okular::NormalizedPoint lastPoint;
|
|
|
|
QRect rect;
|
|
|
|
};
|
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
/** PageViewAnnotator **/
|
|
|
|
|
2006-09-21 08:45:36 +00:00
|
|
|
PageViewAnnotator::PageViewAnnotator( PageView * parent, Okular::Document * storage )
|
2005-03-04 23:06:24 +00:00
|
|
|
: QObject( parent ), m_document( storage ), m_pageView( parent ),
|
2007-12-08 15:59:04 +00:00
|
|
|
m_toolBar( 0 ), m_engine( 0 ), m_textToolsEnabled( false ), m_toolsEnabled( false ),
|
|
|
|
m_lastToolID( -1 ), m_lockedItem( 0 )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
|
|
|
// load the tools from the 'xml tools definition' file. store the tree internally.
|
2006-07-04 23:09:39 +00:00
|
|
|
QFile infoFile( KStandardDirs::locate("data", "okular/tools.xml") );
|
2006-05-15 21:31:53 +00:00
|
|
|
if ( infoFile.exists() && infoFile.open( QIODevice::ReadOnly ) )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2005-04-12 20:30:17 +00:00
|
|
|
QDomDocument doc( "annotatingTools" );
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( doc.setContent( &infoFile ) )
|
2007-03-16 20:19:22 +00:00
|
|
|
{
|
2005-04-12 20:30:17 +00:00
|
|
|
m_toolsDefinition = doc.elementsByTagName("annotatingTools").item( 0 ).toElement();
|
2007-03-16 20:19:22 +00:00
|
|
|
|
2007-09-08 23:15:03 +00:00
|
|
|
// create the AnnotationToolItems from the XML dom tree
|
2007-03-16 20:19:22 +00:00
|
|
|
QDomNode toolDescription = m_toolsDefinition.firstChild();
|
|
|
|
while ( toolDescription.isElement() )
|
|
|
|
{
|
|
|
|
QDomElement toolElement = toolDescription.toElement();
|
|
|
|
if ( toolElement.tagName() == "tool" )
|
|
|
|
{
|
2007-09-08 23:15:03 +00:00
|
|
|
AnnotationToolItem item;
|
2007-03-16 20:19:22 +00:00
|
|
|
item.id = toolElement.attribute("id").toInt();
|
2007-12-09 12:15:57 +00:00
|
|
|
item.text = i18n( toolElement.attribute( "name" ).toUtf8() );
|
2007-03-16 20:19:22 +00:00
|
|
|
item.pixmap = toolElement.attribute("pixmap");
|
|
|
|
QDomNode shortcutNode = toolElement.elementsByTagName( "shortcut" ).item( 0 );
|
|
|
|
if ( shortcutNode.isElement() )
|
|
|
|
item.shortcut = shortcutNode.toElement().text();
|
2007-04-30 17:40:53 +00:00
|
|
|
QDomNodeList engineNodeList = toolElement.elementsByTagName( "engine" );
|
|
|
|
if ( engineNodeList.size() > 0 )
|
|
|
|
{
|
|
|
|
QDomElement engineEl = engineNodeList.item( 0 ).toElement();
|
|
|
|
if ( !engineEl.isNull() && engineEl.hasAttribute( "type" ) )
|
|
|
|
item.isText = engineEl.attribute( "type" ) == QLatin1String( "TextSelector" );
|
|
|
|
}
|
2007-03-16 20:19:22 +00:00
|
|
|
m_items.push_back( item );
|
|
|
|
}
|
|
|
|
toolDescription = toolDescription.nextSibling();
|
|
|
|
}
|
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
else
|
2007-07-31 10:19:48 +00:00
|
|
|
kWarning() << "AnnotatingTools XML file seems to be damaged";
|
2005-03-04 23:06:24 +00:00
|
|
|
infoFile.close();
|
|
|
|
}
|
|
|
|
else
|
2007-07-31 10:19:48 +00:00
|
|
|
kWarning() << "Unable to open AnnotatingTools XML definition";
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
PageViewAnnotator::~PageViewAnnotator()
|
|
|
|
{
|
|
|
|
delete m_engine;
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewAnnotator::setEnabled( bool on )
|
|
|
|
{
|
|
|
|
if ( !on )
|
|
|
|
{
|
|
|
|
// remove toolBar
|
|
|
|
if ( m_toolBar )
|
|
|
|
m_toolBar->hideAndDestroy();
|
|
|
|
m_toolBar = 0;
|
2006-12-27 19:22:22 +00:00
|
|
|
// deactivate the active tool, if any
|
|
|
|
slotToolSelected( -1 );
|
2005-03-04 23:06:24 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if no tools are defined, don't show the toolbar
|
|
|
|
if ( !m_toolsDefinition.hasChildNodes() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
// create toolBar
|
|
|
|
if ( !m_toolBar )
|
|
|
|
{
|
|
|
|
m_toolBar = new PageViewToolBar( m_pageView, m_pageView->viewport() );
|
2007-04-30 17:40:53 +00:00
|
|
|
m_toolBar->setSide( (PageViewToolBar::Side)Okular::Settings::editToolBarPlacement() );
|
2007-12-08 15:59:04 +00:00
|
|
|
m_toolBar->setItems( m_items );
|
|
|
|
m_toolBar->setToolsEnabled( m_toolsEnabled );
|
|
|
|
m_toolBar->setTextToolsEnabled( m_textToolsEnabled );
|
2005-03-04 23:06:24 +00:00
|
|
|
connect( m_toolBar, SIGNAL( toolSelected(int) ),
|
|
|
|
this, SLOT( slotToolSelected(int) ) );
|
|
|
|
connect( m_toolBar, SIGNAL( orientationChanged(int) ),
|
|
|
|
this, SLOT( slotSaveToolbarOrientation(int) ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// show the toolBar
|
2007-04-30 17:40:53 +00:00
|
|
|
m_toolBar->showAndAnimate();
|
2005-03-13 17:23:12 +00:00
|
|
|
|
|
|
|
// ask for Author's name if not already set
|
2006-11-02 22:19:32 +00:00
|
|
|
if ( Okular::Settings::identityAuthor().isEmpty() )
|
2005-03-13 17:23:12 +00:00
|
|
|
{
|
|
|
|
// get default username from the kdelibs/kdecore/KUser
|
|
|
|
KUser currentUser;
|
2007-10-03 12:43:44 +00:00
|
|
|
QString userName = currentUser.property( KUser::FullName ).toString();
|
2005-03-13 17:23:12 +00:00
|
|
|
// ask the user for confirmation/change
|
|
|
|
bool firstTry = true;
|
|
|
|
while ( firstTry || userName.isEmpty() )
|
|
|
|
{
|
|
|
|
QString prompt = firstTry ? i18n( "Please insert your name or initials:" ) :
|
|
|
|
i18n( "You must set this name:" );
|
|
|
|
userName = KInputDialog::getText( i18n("Annotations author"), prompt, userName );
|
|
|
|
firstTry = false;
|
|
|
|
}
|
|
|
|
// save the name
|
2006-11-02 22:19:32 +00:00
|
|
|
Okular::Settings::setIdentityAuthor( userName );
|
2007-05-23 21:59:12 +00:00
|
|
|
Okular::Settings::self()->writeConfig();
|
2005-03-13 17:23:12 +00:00
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
2007-04-30 17:40:53 +00:00
|
|
|
void PageViewAnnotator::setTextToolsEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
m_textToolsEnabled = enabled;
|
|
|
|
if ( m_toolBar )
|
2007-12-08 15:59:04 +00:00
|
|
|
m_toolBar->setTextToolsEnabled( m_textToolsEnabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewAnnotator::setToolsEnabled( bool enabled )
|
|
|
|
{
|
|
|
|
m_toolsEnabled = enabled;
|
|
|
|
if ( m_toolBar )
|
|
|
|
m_toolBar->setToolsEnabled( m_toolsEnabled );
|
2007-04-30 17:40:53 +00:00
|
|
|
}
|
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
bool PageViewAnnotator::routeEvents() const
|
|
|
|
{
|
|
|
|
return m_engine && m_toolBar;
|
|
|
|
}
|
|
|
|
|
2006-09-26 22:22:01 +00:00
|
|
|
QRect PageViewAnnotator::routeEvent( QMouseEvent * e, PageViewItem * item )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2006-09-26 22:22:01 +00:00
|
|
|
if ( !item ) return QRect();
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
// find out mouse event type
|
|
|
|
AnnotatorEngine::EventType eventType = AnnotatorEngine::Press;
|
|
|
|
if ( e->type() == QEvent::MouseMove )
|
|
|
|
eventType = AnnotatorEngine::Move;
|
|
|
|
else if ( e->type() == QEvent::MouseButtonRelease )
|
|
|
|
eventType = AnnotatorEngine::Release;
|
|
|
|
|
|
|
|
// find out the pressed button
|
|
|
|
AnnotatorEngine::Button button = AnnotatorEngine::None;
|
2006-09-27 10:04:17 +00:00
|
|
|
Qt::MouseButtons buttonState = ( eventType == AnnotatorEngine::Move ) ? e->buttons() : e->button();
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( buttonState == Qt::LeftButton )
|
|
|
|
button = AnnotatorEngine::Left;
|
|
|
|
else if ( buttonState == Qt::RightButton )
|
|
|
|
button = AnnotatorEngine::Right;
|
|
|
|
|
|
|
|
// find out normalized mouse coords inside current item
|
|
|
|
const QRect & itemRect = item->geometry();
|
|
|
|
double itemWidth = (double)itemRect.width();
|
|
|
|
double itemHeight = (double)itemRect.height();
|
|
|
|
double nX = (double)(e->x() - itemRect.left()) / itemWidth;
|
|
|
|
double nY = (double)(e->y() - itemRect.top()) / itemHeight;
|
|
|
|
|
2006-09-26 22:22:01 +00:00
|
|
|
QRect modifiedRect;
|
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// 1. lock engine to current item
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( m_lockedItem && item != m_lockedItem )
|
2006-09-26 22:22:01 +00:00
|
|
|
return QRect();
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( !m_lockedItem && eventType == AnnotatorEngine::Press )
|
2006-10-22 20:53:56 +00:00
|
|
|
{
|
2005-03-04 23:06:24 +00:00
|
|
|
m_lockedItem = item;
|
2006-10-22 20:53:56 +00:00
|
|
|
m_engine->setItem( m_lockedItem );
|
|
|
|
}
|
2006-08-10 08:59:58 +00:00
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// 2. use engine to perform operations
|
2006-09-16 21:16:58 +00:00
|
|
|
QRect paintRect = m_engine->event( eventType, button, nX, nY, itemWidth, itemHeight, item->page() );
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// 3. update absolute extents rect and send paint event(s)
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( paintRect.isValid() )
|
|
|
|
{
|
|
|
|
// 3.1. unite old and new painting regions
|
|
|
|
QRegion compoundRegion( m_lastDrawnRect );
|
|
|
|
m_lastDrawnRect = paintRect;
|
2006-03-29 16:46:09 +00:00
|
|
|
m_lastDrawnRect.translate( itemRect.left(), itemRect.top() );
|
2005-03-04 23:06:24 +00:00
|
|
|
// 3.2. decompose paint region in rects and send paint events
|
2006-03-24 20:40:02 +00:00
|
|
|
QVector<QRect> rects = compoundRegion.unite( m_lastDrawnRect ).rects();
|
|
|
|
for ( int i = 0; i < rects.count(); i++ )
|
2006-10-07 14:40:32 +00:00
|
|
|
m_pageView->widget()->update( rects[i] );
|
2006-09-26 22:22:01 +00:00
|
|
|
modifiedRect = compoundRegion.boundingRect() | m_lastDrawnRect;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// 4. if engine has finished, apply Annotation to the page
|
2005-03-04 23:06:24 +00:00
|
|
|
if ( m_engine->creationCompleted() )
|
|
|
|
{
|
2006-10-22 16:43:55 +00:00
|
|
|
// apply engine data to the Annotation's and reset engine
|
|
|
|
QList< Okular::Annotation* > annotations = m_engine->end();
|
|
|
|
// attach the newly filled annotations to the page
|
|
|
|
foreach ( Okular::Annotation * annotation, annotations )
|
2006-05-19 16:58:34 +00:00
|
|
|
{
|
2006-10-22 16:43:55 +00:00
|
|
|
if ( !annotation ) continue;
|
|
|
|
|
2006-12-05 11:05:50 +00:00
|
|
|
annotation->setCreationDate( QDateTime::currentDateTime() );
|
|
|
|
annotation->setModificationDate( QDateTime::currentDateTime() );
|
|
|
|
annotation->setAuthor( Okular::Settings::identityAuthor() );
|
2005-03-04 23:06:24 +00:00
|
|
|
m_document->addPageAnnotation( m_lockedItem->pageNumber(), annotation );
|
2006-05-19 16:58:34 +00:00
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// go on creating annotations of the same type
|
2007-10-28 11:14:41 +00:00
|
|
|
// for now, disable the "construct again the same annotation"
|
|
|
|
//slotToolSelected( m_lastToolID );
|
|
|
|
slotToolSelected( -1 );
|
|
|
|
m_toolBar->selectButton( -1 );
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
2006-09-26 22:22:01 +00:00
|
|
|
|
|
|
|
return modifiedRect;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
2007-09-23 17:45:36 +00:00
|
|
|
bool PageViewAnnotator::routeKeyEvent( QKeyEvent * event )
|
|
|
|
{
|
|
|
|
if ( event->key() == Qt::Key_Escape )
|
|
|
|
{
|
|
|
|
m_toolBar->selectButton( -1 );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
bool PageViewAnnotator::routePaints( const QRect & wantedRect ) const
|
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
return m_engine && m_toolBar && wantedRect.intersects( m_lastDrawnRect ) && m_lockedItem;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewAnnotator::routePaint( QPainter * painter, const QRect & paintRect )
|
|
|
|
{
|
2006-09-11 11:51:10 +00:00
|
|
|
// if there's no locked item, then there's no decided place to draw on
|
|
|
|
if ( !m_lockedItem )
|
|
|
|
return;
|
|
|
|
|
2005-03-04 23:06:24 +00:00
|
|
|
#ifndef NDEBUG
|
2005-04-12 20:30:17 +00:00
|
|
|
// [DEBUG] draw the paint region if enabled
|
2006-09-21 08:45:36 +00:00
|
|
|
if ( Okular::Settings::debugDrawAnnotationRect() )
|
2005-03-04 23:06:24 +00:00
|
|
|
painter->drawRect( paintRect );
|
|
|
|
#endif
|
|
|
|
// move painter to current itemGeometry rect
|
|
|
|
const QRect & itemGeometry = m_lockedItem->geometry();
|
|
|
|
painter->save();
|
|
|
|
painter->translate( itemGeometry.left(), itemGeometry.top() );
|
|
|
|
|
|
|
|
// transform cliprect from absolute to item relative coords
|
|
|
|
QRect annotRect = paintRect.intersect( m_lastDrawnRect );
|
2006-03-29 16:46:09 +00:00
|
|
|
annotRect.translate( itemGeometry.left(), itemGeometry.top() );
|
2005-03-04 23:06:24 +00:00
|
|
|
|
|
|
|
// use current engine for painting
|
|
|
|
m_engine->paint( painter, m_lockedItem->width(), m_lockedItem->height(), annotRect );
|
|
|
|
painter->restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewAnnotator::slotToolSelected( int toolID )
|
|
|
|
{
|
|
|
|
// terminate any previous operation
|
|
|
|
if ( m_engine )
|
|
|
|
{
|
|
|
|
delete m_engine;
|
|
|
|
m_engine = 0;
|
|
|
|
}
|
|
|
|
m_lockedItem = 0;
|
|
|
|
if ( m_lastDrawnRect.isValid() )
|
|
|
|
{
|
2006-10-07 14:40:32 +00:00
|
|
|
m_pageView->widget()->update( m_lastDrawnRect );
|
2005-03-04 23:06:24 +00:00
|
|
|
m_lastDrawnRect = QRect();
|
|
|
|
}
|
|
|
|
|
|
|
|
// store current tool for later usage
|
|
|
|
m_lastToolID = toolID;
|
|
|
|
|
|
|
|
// handle tool deselection
|
|
|
|
if ( toolID == -1 )
|
|
|
|
{
|
|
|
|
m_pageView->displayMessage( QString() );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-04-12 20:30:17 +00:00
|
|
|
// for the selected tool create the Engine
|
2005-04-01 14:00:59 +00:00
|
|
|
QDomNode toolNode = m_toolsDefinition.firstChild();
|
|
|
|
while ( toolNode.isElement() )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2005-04-01 14:00:59 +00:00
|
|
|
QDomElement toolElement = toolNode.toElement();
|
|
|
|
toolNode = toolNode.nextSibling();
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2005-04-01 14:00:59 +00:00
|
|
|
// only find out the element describing selected tool
|
|
|
|
if ( toolElement.tagName() != "tool" || toolElement.attribute("id").toInt() != toolID )
|
|
|
|
continue;
|
2005-03-04 23:06:24 +00:00
|
|
|
|
2005-04-01 14:00:59 +00:00
|
|
|
// parse tool properties
|
|
|
|
QDomNode toolSubNode = toolElement.firstChild();
|
|
|
|
while ( toolSubNode.isElement() )
|
|
|
|
{
|
|
|
|
QDomElement toolSubElement = toolSubNode.toElement();
|
|
|
|
toolSubNode = toolSubNode.nextSibling();
|
|
|
|
|
|
|
|
// create the AnnotatorEngine
|
|
|
|
if ( toolSubElement.tagName() == "engine" )
|
2005-03-04 23:06:24 +00:00
|
|
|
{
|
2005-04-01 14:00:59 +00:00
|
|
|
QString type = toolSubElement.attribute( "type" );
|
|
|
|
if ( type == "SmoothLine" )
|
|
|
|
m_engine = new SmoothPathEngine( toolSubElement );
|
|
|
|
else if ( type == "PickPoint" )
|
|
|
|
m_engine = new PickPointEngine( toolSubElement );
|
2006-09-11 11:51:10 +00:00
|
|
|
else if ( type == "PolyLine" )
|
|
|
|
m_engine = new PolyLineEngine( toolSubElement );
|
2006-10-22 20:53:56 +00:00
|
|
|
else if ( type == "TextSelector" )
|
|
|
|
m_engine = new TextSelectorEngine( toolSubElement, m_pageView );
|
2005-03-04 23:06:24 +00:00
|
|
|
else
|
2007-07-31 10:19:48 +00:00
|
|
|
kWarning().nospace() << "tools.xml: engine type:'" << type << "' is not defined!";
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
2005-04-01 14:00:59 +00:00
|
|
|
// display the tooltip
|
|
|
|
else if ( toolSubElement.tagName() == "tooltip" )
|
2007-03-24 22:56:32 +00:00
|
|
|
{
|
|
|
|
QString tip = toolSubElement.text();
|
|
|
|
if ( !tip.isEmpty() )
|
|
|
|
m_pageView->displayMessage( i18nc( "Annotation tool", tip.toUtf8() ), PageViewMessage::Annotation );
|
|
|
|
}
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
2005-04-01 14:00:59 +00:00
|
|
|
|
|
|
|
// consistancy warning
|
|
|
|
if ( !m_engine )
|
2007-07-31 10:19:48 +00:00
|
|
|
kWarning() << "tools.xml: couldn't find good engine description. check xml.";
|
2005-04-01 14:00:59 +00:00
|
|
|
|
|
|
|
// stop after parsing selected tool's node
|
|
|
|
break;
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void PageViewAnnotator::slotSaveToolbarOrientation( int side )
|
|
|
|
{
|
2006-09-21 08:45:36 +00:00
|
|
|
Okular::Settings::setEditToolBarPlacement( (int)side );
|
2007-05-23 21:59:12 +00:00
|
|
|
Okular::Settings::self()->writeConfig();
|
2005-03-04 23:06:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "pageviewannotator.moc"
|