diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp index da91ee1e5..e23dec5fc 100644 --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -8,12 +8,14 @@ ***************************************************************************/ // qt/kde includes +#include #include #include #include #include #include #include +#include #include #include #include @@ -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" diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h index f9c2f7bd1..53fb6ba6e 100644 --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -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 diff --git a/ui/data/tools.xml b/ui/data/tools.xml index bbdeee919..d5d4cef58 100644 --- a/ui/data/tools.xml +++ b/ui/data/tools.xml @@ -80,4 +80,11 @@ Engine/Annotation Types [specific attributes]: 9 + + A cyan ellipse + + + + 10 + diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index c51baa359..25c74dcfc 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -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 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() ) diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index ea9881ee9..b4cf15ca2 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -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 )