From 5397f99262479bcc86aa5e65334f760086fe19ea Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Fri, 27 Jul 2012 04:39:14 +0200 Subject: [PATCH] Made polygon annotations' inner color configurable --- conf/widgetannottools.cpp | 11 ++++-- ui/annotationwidgets.cpp | 77 +++++++++++++++++++++++++++++---------- ui/annotationwidgets.h | 2 + ui/pageviewannotator.cpp | 6 +++ 4 files changed, 73 insertions(+), 23 deletions(-) diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index 18c6899b1..67e047784 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -312,12 +312,17 @@ QString NewAnnotToolDialog::toolXml() const else if ( toolType == "polygon" ) { Okular::LineAnnotation * la = static_cast( m_stubann ); - Q_UNUSED( la ); + + QString innerColor; + if ( la->lineInnerColor().isValid() ) + innerColor = QString( "innerColor=\"%1\"" ).arg( la->lineInnerColor().name() ); + return QString( "" "" - "" + "" "" - "" ).arg( color ).arg( opacity ).arg( width ); + "" ).arg( color ).arg( opacity ).arg( width ) + .arg( innerColor ); } else if ( toolType == "text-markup" ) { diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp index 90854579f..ea711d521 100644 --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -371,20 +371,20 @@ QWidget * LineAnnotationWidget::createStyleWidget() lay->setMargin( 0 ); if ( m_lineType == 0 ) { - QGroupBox * gb = new QGroupBox( widget ); - lay->addWidget( gb ); - gb->setTitle( i18n( "Line Extensions" ) ); - QGridLayout * gridlay = new QGridLayout( gb ); - QLabel * tmplabel = new QLabel( i18n( "Leader Line Length:" ), gb ); - gridlay->addWidget( tmplabel, 0, 0, Qt::AlignRight ); - m_spinLL = new QDoubleSpinBox( gb ); - gridlay->addWidget( m_spinLL, 0, 1 ); - tmplabel->setBuddy( m_spinLL ); - tmplabel = new QLabel( i18n( "Leader Line Extensions Length:" ), gb ); - gridlay->addWidget( tmplabel, 1, 0, Qt::AlignRight ); - m_spinLLE = new QDoubleSpinBox( gb ); - gridlay->addWidget( m_spinLLE, 1, 1 ); - tmplabel->setBuddy( m_spinLLE ); + QGroupBox * gb = new QGroupBox( widget ); + lay->addWidget( gb ); + gb->setTitle( i18n( "Line Extensions" ) ); + QGridLayout * gridlay = new QGridLayout( gb ); + QLabel * tmplabel = new QLabel( i18n( "Leader Line Length:" ), gb ); + gridlay->addWidget( tmplabel, 0, 0, Qt::AlignRight ); + m_spinLL = new QDoubleSpinBox( gb ); + gridlay->addWidget( m_spinLL, 0, 1 ); + tmplabel->setBuddy( m_spinLL ); + tmplabel = new QLabel( i18n( "Leader Line Extensions Length:" ), gb ); + gridlay->addWidget( tmplabel, 1, 0, Qt::AlignRight ); + m_spinLLE = new QDoubleSpinBox( gb ); + gridlay->addWidget( m_spinLLE, 1, 1 ); + tmplabel->setBuddy( m_spinLLE ); } QGroupBox * gb2 = new QGroupBox( widget ); @@ -397,20 +397,46 @@ QWidget * LineAnnotationWidget::createStyleWidget() gridlay2->addWidget( m_spinSize, 0, 1 ); tmplabel2->setBuddy( m_spinSize ); + if ( m_lineType == 1 ) + { + m_useColor = new QCheckBox( i18n( "Inner color:" ), gb2 ); + gridlay2->addWidget( m_useColor, 1, 0 ); + m_innerColor = new KColorButton( gb2 ); + gridlay2->addWidget( m_innerColor, 1, 1 ); + } + if ( m_lineType == 0 ) { - m_spinLL->setRange( -500, 500 ); - m_spinLL->setValue( m_lineAnn->lineLeadingForwardPoint() ); - m_spinLLE->setRange( 0, 500 ); - m_spinLLE->setValue( m_lineAnn->lineLeadingBackwardPoint() ); + m_spinLL->setRange( -500, 500 ); + m_spinLL->setValue( m_lineAnn->lineLeadingForwardPoint() ); + m_spinLLE->setRange( 0, 500 ); + m_spinLLE->setValue( m_lineAnn->lineLeadingBackwardPoint() ); + } + else if ( m_lineType == 1 ) + { + m_innerColor->setColor( m_lineAnn->lineInnerColor() ); + if ( m_lineAnn->lineInnerColor().isValid() ) + { + m_useColor->setChecked( true ); + } + else + { + m_innerColor->setEnabled( false ); + } } m_spinSize->setRange( 1, 100 ); m_spinSize->setValue( m_lineAnn->style().width() ); if ( m_lineType == 0 ) { - connect( m_spinLL, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); - connect( m_spinLLE, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); + connect( m_spinLL, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); + connect( m_spinLLE, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); + } + else if ( m_lineType == 1 ) + { + connect( m_innerColor, SIGNAL(changed(QColor)), this, SIGNAL(dataChanged()) ); + connect( m_useColor, SIGNAL(toggled(bool)), this, SIGNAL(dataChanged()) ); + connect( m_useColor, SIGNAL(toggled(bool)), m_innerColor, SLOT(setEnabled(bool)) ); } connect( m_spinSize, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); @@ -425,6 +451,17 @@ void LineAnnotationWidget::applyChanges() m_lineAnn->setLineLeadingForwardPoint( m_spinLL->value() ); m_lineAnn->setLineLeadingBackwardPoint( m_spinLLE->value() ); } + else if ( m_lineType == 1 ) + { + if ( !m_useColor->isChecked() ) + { + m_lineAnn->setLineInnerColor( QColor() ); + } + else + { + m_lineAnn->setLineInnerColor( m_innerColor->color() ); + } + } m_lineAnn->style().setWidth( m_spinSize->value() ); } diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h index 7f66415c4..3aaa7b0b1 100644 --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -153,6 +153,8 @@ private: int m_lineType; QDoubleSpinBox * m_spinLL; QDoubleSpinBox * m_spinLLE; + QCheckBox * m_useColor; + KColorButton * m_innerColor; QDoubleSpinBox * m_spinSize; }; diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 9ec898c1b..c2eaa4d4e 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -416,7 +416,11 @@ class PolyLineEngine : public AnnotatorEngine la->setLinePoints( list ); if ( numofpoints == -1 ) + { la->setLineClosed( true ); + if ( m_annotElement.hasAttribute( "innerColor" ) ) + la->setLineInnerColor( QColor( m_annotElement.attribute( "innerColor" ) ) ); + } la->setBoundingRectangle( normRect ); @@ -1083,6 +1087,8 @@ QPixmap PageViewAnnotator::makeToolPixmap( const QDomElement &toolElement ) path.lineTo( 23, 14 ); path.lineTo( 23, 20 ); path.lineTo( 0, 20 ); + if ( innerColor.isValid() ) + p.setBrush( innerColor ); p.setPen( QPen( engineColor, 1 ) ); p.drawPath( path ); }