From 3400f76dad3be8cd87cdf1f4e32683005fa17ec0 Mon Sep 17 00:00:00 2001 From: Sumit Sahrawat Date: Tue, 24 Nov 2015 01:10:46 +0100 Subject: [PATCH] Make inline annotation border width customizable, using a spin widget to accept input REVIEW: 125801 BUGS: 332887 --- conf/widgetannottools.cpp | 2 ++ ui/annotationwidgets.cpp | 11 +++++++++++ ui/annotationwidgets.h | 1 + ui/pagepainter.cpp | 19 +++++++++++++------ ui/pageviewannotator.cpp | 5 +++++ 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp index 6d05eed8b..d8cb451db 100644 --- a/conf/widgetannottools.cpp +++ b/conf/widgetannottools.cpp @@ -360,6 +360,7 @@ QDomDocument EditAnnotToolDialog::toolXml() const engineElement.setAttribute( "block", "true" ); annotationElement.setAttribute( "type", "FreeText" ); annotationElement.setAttribute( "color", color ); + annotationElement.setAttribute( "width", width ); if ( ta->inplaceAlignment() != 0 ) annotationElement.setAttribute( "align", ta->inplaceAlignment() ); if ( ta->textFont() != QApplication::font() ) @@ -495,6 +496,7 @@ void EditAnnotToolDialog::createStubAnnotation() { Okular::TextAnnotation * ta = new Okular::TextAnnotation(); ta->setTextType( Okular::TextAnnotation::InPlace ); + ta->style().setWidth( 1.0 ); ta->style().setColor( Qt::yellow ); m_stubann = ta; } diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp index 450e50ba0..c1d7c5560 100644 --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -289,8 +289,18 @@ QWidget * TextAnnotationWidget::createStyleWidget() m_textAlign->addItem( i18n("Right") ); m_textAlign->setCurrentIndex( m_textAnn->inplaceAlignment() ); + tmplabel = new QLabel( i18n( "Border Width:" ), widget ); + innerlay->addWidget( tmplabel, 2, 0, Qt::AlignRight ); + m_spinWidth = new QDoubleSpinBox( widget ); + innerlay->addWidget( m_spinWidth, 2, 1 ); + tmplabel->setBuddy( m_spinWidth ); + m_spinWidth->setRange( 0, 100 ); + m_spinWidth->setValue( m_textAnn->style().width() ); + m_spinWidth->setSingleStep( 0.1 ); + connect( m_fontReq, SIGNAL(fontSelected(QFont)), this, SIGNAL(dataChanged()) ); connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) ); + connect( m_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); } return widget; @@ -307,6 +317,7 @@ void TextAnnotationWidget::applyChanges() { m_textAnn->setTextFont( m_fontReq->font() ); m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() ); + m_textAnn->style().setWidth( m_spinWidth->value() ); } } diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h index 6e7a21839..6334b69c7 100644 --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -116,6 +116,7 @@ private: PixmapPreviewSelector * m_pixmapSelector; KFontRequester * m_fontReq; QComboBox * m_textAlign; + QDoubleSpinBox * m_spinWidth; }; class StampAnnotationWidget diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp index 6eed5b6e2..57e8620cd 100644 --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -694,19 +694,26 @@ void PagePainter::paintCroppedPageOnPainter( QPainter * destPainter, const Okula QImage image( annotBoundary.size(), QImage::Format_ARGB32 ); image.fill( acolor.rgba() ); QPainter painter( &image ); - painter.setPen( Qt::black ); painter.setFont( text->textFont() ); Qt::AlignmentFlag halign = ( text->inplaceAlignment() == 1 ? Qt::AlignHCenter : ( text->inplaceAlignment() == 2 ? Qt::AlignRight : Qt::AlignLeft ) ); const double invXScale = (double)page->width() / scaledWidth; const double invYScale = (double)page->height() / scaledHeight; + const double borderWidth = text->style().width(); painter.scale( 1 / invXScale, 1 / invYScale ); - painter.drawText( 2 * invXScale, 2 * invYScale, - (image.width() - 2) * invXScale, - (image.height() - 2) * invYScale, - Qt::AlignTop | halign | Qt::TextWordWrap, + painter.drawText( borderWidth * invXScale, borderWidth * invYScale, + (image.width() - 2 * borderWidth) * invXScale, + (image.height() - 2 * borderWidth) * invYScale, + Qt::AlignTop | halign | Qt::TextWrapAnywhere, text->contents() ); painter.resetTransform(); - painter.drawRect( 0, 0, image.width() - 1, image.height() - 1 ); + //Required as asking for a zero width pen results + //in a default width pen (1.0) being created + if ( borderWidth != 0 ) + { + QPen pen( Qt::black, borderWidth ); + painter.setPen( pen ); + painter.drawRect( 0, 0, image.width() - 1, image.height() - 1 ); + } painter.end(); mixedPainter->drawImage( annotBoundary.topLeft(), image ); diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp index 6f2ab389a..699f068c0 100644 --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -180,6 +180,11 @@ class PickPointEngine : public AnnotatorEngine f.fromString( m_annotElement.attribute( "font" ) ); ta->setTextFont( f ); } + //set width + if ( m_annotElement.hasAttribute( "width" ) ) + { + ta->style().setWidth( m_annotElement.attribute( "width" ).toDouble() ); + } //set boundary rect.left = qMin(startpoint.x,point.x); rect.top = qMin(startpoint.y,point.y);