Make okular able to construct and display Geometric (Rectangle/Ellipse) Annotations.

Extended the annotation properties dialog to choose the type (rect/ellipse) or the color for the inner part.
Added a button in the review toolbar to construct a cyan ellipse.

svn path=/trunk/playground/graphics/okular/; revision=606023
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent 73f0a7269d
commit 44a69612ef
  1. 66
      ui/annotationwidgets.cpp
  2. 22
      ui/annotationwidgets.h
  3. 7
      ui/data/tools.xml
  4. 31
      ui/pagepainter.cpp
  5. 18
      ui/pageviewannotator.cpp

@ -8,12 +8,14 @@
***************************************************************************/
// qt/kde includes
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qgroupbox.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qspinbox.h>
#include <qvariant.h>
#include <kcolorbutton.h>
#include <kiconloader.h>
#include <klocale.h>
#include <kdebug.h>
@ -108,6 +110,9 @@ AnnotationWidget * AnnotationWidgetFactory::widgetFor( Okular::Annotation * ann
case Okular::Annotation::AHighlight:
return new HighlightAnnotationWidget( ann );
break;
case Okular::Annotation::AGeom:
return new GeomAnnotationWidget( ann );
break;
// shut up gcc
default:
;
@ -338,4 +343,65 @@ void HighlightAnnotationWidget::applyChanges()
GeomAnnotationWidget::GeomAnnotationWidget( Okular::Annotation * ann )
: AnnotationWidget( ann ), m_widget( 0 )
{
m_geomAnn = static_cast< Okular::GeomAnnotation * >( ann );
}
QWidget * GeomAnnotationWidget::widget()
{
if ( m_widget )
return m_widget;
m_widget = new QWidget();
QGridLayout * lay = new QGridLayout( m_widget );
lay->setMargin( 0 );
QLabel * tmplabel = new QLabel( i18n( "Type:" ), m_widget );
lay->addWidget( tmplabel, 0, 0 );
m_typeCombo = new QComboBox( m_widget );
tmplabel->setBuddy( m_typeCombo );
lay->addWidget( m_typeCombo, 0, 1 );
m_useColor = new QCheckBox( i18n( "Inner color:" ), m_widget );
lay->addWidget( m_useColor, 1, 0 );
m_innerColor = new KColorButton( m_widget );
lay->addWidget( m_innerColor, 1, 1 );
m_typeCombo->addItem( i18n( "Rectangle" ) );
m_typeCombo->addItem( i18n( "Ellipse" ) );
m_typeCombo->setCurrentIndex( m_geomAnn->geomType );
m_innerColor->setColor( m_geomAnn->geomInnerColor );
if ( m_geomAnn->geomInnerColor.isValid() )
{
m_useColor->setChecked( true );
}
else
{
m_innerColor->setEnabled( false );
}
connect( m_typeCombo, SIGNAL( currentIndexChanged ( int ) ), this, SIGNAL( dataChanged() ) );
connect( m_innerColor, SIGNAL( changed( const QColor & ) ), this, SIGNAL( dataChanged() ) );
connect( m_useColor, SIGNAL( toggled( bool ) ), this, SIGNAL( dataChanged() ) );
connect( m_useColor, SIGNAL( toggled( bool ) ), m_innerColor, SLOT( setEnabled( bool ) ) );
return m_widget;
}
void GeomAnnotationWidget::applyChanges()
{
m_geomAnn->geomType = (Okular::GeomAnnotation::GeomType)m_typeCombo->currentIndex();
if ( !m_useColor->isChecked() )
{
m_geomAnn->geomInnerColor = QColor();
}
else
{
m_geomAnn->geomInnerColor = m_innerColor->color();
}
}
#include "annotationwidgets.moc"

@ -14,10 +14,12 @@
#include "core/annotations.h"
class QCheckBox;
class QComboBox;
class QDoubleSpinBox;
class QLabel;
class QWidget;
class KColorButton;
class AnnotationWidget;
class PixmapPreviewSelector
@ -157,4 +159,24 @@ private:
QComboBox * m_typeCombo;
};
class GeomAnnotationWidget
: public AnnotationWidget
{
Q_OBJECT
public:
GeomAnnotationWidget( Okular::Annotation * ann );
virtual QWidget * widget();
virtual void applyChanges();
private:
Okular::GeomAnnotation * m_geomAnn;
QWidget * m_widget;
QComboBox * m_typeCombo;
QCheckBox * m_useColor;
KColorButton * m_innerColor;
};
#endif

@ -80,4 +80,11 @@ Engine/Annotation Types [specific attributes]:
</engine>
<shortcut>9</shortcut>
</tool>
<tool id="10" name="Cyan Ellipse" pixmap="ellipse">
<tooltip>A cyan ellipse</tooltip>
<engine type="PickPoint" color="#00ffff">
<annotation type="GeomCircle" color="#00ffff" />
</engine>
<shortcut>10</shortcut>
</tool>
</annotatingTools>

@ -28,6 +28,7 @@
#include "core/area.h"
#include "core/page.h"
#include "core/annotations.h"
#include "core/utils.h"
#include "settings.h"
static KStaticDeleter<QPixmap> sd;
@ -595,6 +596,35 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page
mixedPainter->drawPixmap( annotRect.topLeft(), pixmap );
}
// draw GeomAnnotation
else if ( type == Okular::Annotation::AGeom )
{
Okular::GeomAnnotation * geom = (Okular::GeomAnnotation *)a;
QImage shape( annotBoundary.size(), QImage::Format_ARGB32 );
shape.fill( qRgba( 0, 0, 0, 0 ) );
// width is already divided by two
double width = geom->geomWidthPt * Okular::Utils::getDpiX() / ( 72.0 * 2.0 ) * scaledWidth / page->width();
QPainter p( &shape );
p.setPen( QPen( QBrush( QColor( a->style.color.red(), a->style.color.green(), a->style.color.blue(), opacity ) ), width * 2, Qt::SolidLine, Qt::SquareCap, Qt::MiterJoin ) );
QRectF r( .0, .0, annotBoundary.width(), annotBoundary.height() );
r.adjust( width, width, -width, -width );
if ( geom->geomType == Okular::GeomAnnotation::InscribedSquare )
p.drawRect( r );
else
p.drawEllipse( r );
if ( geom->geomInnerColor.isValid() )
{
p.setPen( Qt::NoPen );
p.setBrush( geom->geomInnerColor );
r.adjust( width, width, -width, -width );
if ( geom->geomType == Okular::GeomAnnotation::InscribedSquare )
p.drawRect( r );
else
p.drawEllipse( r );
}
p.end();
mixedPainter->drawImage( annotBoundary.topLeft(), shape );
}
#if 0
else // WARNING: TEMPORARY CODE! migrate everything to AGG
{
//GeomAnnotation * geom = (GeomAnnotation *)a;
@ -608,6 +638,7 @@ void PagePainter::paintPageOnPainter( QPainter * destPainter, const Okular::Page
//}
//else if ( geom->geomType == GeomAnnotation::InscribedCircle )
}
#endif
// draw extents rectangle
if ( Okular::Settings::debugDrawAnnotationRect() )

@ -199,6 +199,24 @@ class PickPointEngine : public AnnotatorEngine
rect.bottom = rect.top + stampyscale;
sa->boundary = rect;
}
// create GeomAnnotation
else if ( typeString == "GeomSquare" || typeString == "GeomCircle" )
{
Okular::GeomAnnotation * ga = new Okular::GeomAnnotation();
ann = ga;
// set the type
if ( typeString == "GeomSquare" )
ga->geomType = Okular::GeomAnnotation::InscribedSquare;
else
ga->geomType = Okular::GeomAnnotation::InscribedCircle;
ga->geomWidthPt = 18;
//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 );
ga->boundary = rect;
}
// safety check
if ( !ann )

Loading…
Cancel
Save