Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 3400f76d authored by Sumit Sahrawat's avatar Sumit Sahrawat Committed by Albert Astals Cid

Make inline annotation border width customizable, using a spin widget to accept input

REVIEW: 125801
BUGS: 332887
parent 16f07806
......@@ -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;
}
......
......@@ -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() );
}
}
......
......@@ -116,6 +116,7 @@ private:
PixmapPreviewSelector * m_pixmapSelector;
KFontRequester * m_fontReq;
QComboBox * m_textAlign;
QDoubleSpinBox * m_spinWidth;
};
class StampAnnotationWidget
......
......@@ -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 );
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment