diff --git a/conf/editannottooldialog.cpp b/conf/editannottooldialog.cpp --- a/conf/editannottooldialog.cpp +++ b/conf/editannottooldialog.cpp @@ -133,6 +133,7 @@ engineElement.appendChild( annotationElement ); const QString color = m_stubann->style().color().name( QColor::HexArgb ); + const QString fontColor = static_cast< Okular::TextAnnotation * >( m_stubann )->textColor().name(); const QString opacity = QString::number( m_stubann->style().opacity() ); const QString width = QString::number( m_stubann->style().width() ); @@ -271,7 +272,7 @@ Okular::TextAnnotation * ta = static_cast( m_stubann ); toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("typewriter") ); engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); - engineElement.setAttribute( QStringLiteral("color"), QStringLiteral("#000000") ); + engineElement.setAttribute( QStringLiteral("color"), fontColor ); engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Typewriter") ); annotationElement.setAttribute( QStringLiteral("color"), color ); @@ -362,6 +363,7 @@ ta->setInplaceIntent( Okular::TextAnnotation::TypeWriter ); ta->style().setWidth( 0.0 ); ta->style().setColor( QColor(255,255,255,0) ); + ta->setTextColor( Qt::black ); m_stubann = ta; } } @@ -504,6 +506,8 @@ f.fromString( annotationElement.attribute( QStringLiteral("font") ) ); ta->setTextFont( f ); } + if ( engineElement.hasAttribute( QStringLiteral("color") ) ) + ta->setTextColor( QColor( engineElement.attribute( QStringLiteral("color") ) ) ); } // Common properties diff --git a/core/annotations.h b/core/annotations.h --- a/core/annotations.h +++ b/core/annotations.h @@ -819,6 +819,16 @@ */ QFont textFont() const; + /** + * Sets the @p color of the text annotation. + */ + void setTextColor( const QColor &color ); + + /** + * Returns the font color of the text annotation. + */ + QColor textColor() const; + /** * Sets the inplace @p alignment of the text annotation. */ diff --git a/core/annotations.cpp b/core/annotations.cpp --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -1028,6 +1028,7 @@ TextAnnotation::TextType m_textType; QString m_textIcon; QFont m_textFont; + QColor m_textColor; int m_inplaceAlign; NormalizedPoint m_inplaceCallout[3]; NormalizedPoint m_transformedInplaceCallout[3]; @@ -1087,6 +1088,18 @@ return d->m_textFont; } +void TextAnnotation::setTextColor( const QColor &color ) +{ + Q_D( TextAnnotation ); + d->m_textColor = color; +} + +QColor TextAnnotation::textColor() const +{ + Q_D( const TextAnnotation ); + return d->m_textColor; +} + void TextAnnotation::setInplaceAlignment( int alignment ) { Q_D( TextAnnotation ); @@ -1160,6 +1173,8 @@ textElement.setAttribute( QStringLiteral("icon"), d->m_textIcon ); if ( d->m_textFont != QApplication::font() ) textElement.setAttribute( QStringLiteral("font"), d->m_textFont.toString() ); + if ( d->m_textColor.isValid() ) + textElement.setAttribute( QStringLiteral("fontColor"), d->m_textColor.name() ); if ( d->m_inplaceAlign ) textElement.setAttribute( QStringLiteral("align"), d->m_inplaceAlign ); if ( d->m_inplaceIntent != Unknown ) @@ -1246,6 +1261,8 @@ m_textIcon = e.attribute( QStringLiteral("icon") ); if ( e.hasAttribute( QStringLiteral("font") ) ) m_textFont.fromString( e.attribute( QStringLiteral("font") ) ); + if ( e.hasAttribute( QStringLiteral("fontColor") ) ) + m_textColor = QColor( e.attribute( QStringLiteral("fontColor") ) ); if ( e.hasAttribute( QStringLiteral("align") ) ) m_inplaceAlign = e.attribute( QStringLiteral("align") ).toInt(); if ( e.hasAttribute( QStringLiteral("intent") ) ) diff --git a/generators/poppler/CMakeLists.txt b/generators/poppler/CMakeLists.txt --- a/generators/poppler/CMakeLists.txt +++ b/generators/poppler/CMakeLists.txt @@ -96,6 +96,17 @@ } " HAVE_POPPLER_0_65) +check_cxx_source_compiles(" +#include +#include +int main() +{ + Poppler::TextAnnotation *annot = new Poppler::TextAnnotation( Poppler::TextAnnotation::InPlace ); + annot->setTextColor( Qt::blue ); + return 0; +} +" HAVE_POPPLER_0_69) + configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/config-okular-poppler.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-okular-poppler.h diff --git a/generators/poppler/annots.cpp b/generators/poppler/annots.cpp --- a/generators/poppler/annots.cpp +++ b/generators/poppler/annots.cpp @@ -180,6 +180,9 @@ Poppler::TextAnnotation * ppl_txtann = static_cast(ppl_ann); ppl_txtann->setTextIcon( okl_txtann->textIcon() ); ppl_txtann->setTextFont( okl_txtann->textFont() ); + #ifdef HAVE_POPPLER_0_69 + ppl_txtann->setTextColor( okl_txtann->textColor() ); + #endif //HAVE_POPPLER_0_69 ppl_txtann->setInplaceAlign( okl_txtann->inplaceAlignment() ); ppl_txtann->setCalloutPoints( QVector() ); ppl_txtann->setInplaceIntent( (Poppler::TextAnnotation::InplaceIntent)okl_txtann->inplaceIntent() ); diff --git a/generators/poppler/config-okular-poppler.h.cmake b/generators/poppler/config-okular-poppler.h.cmake --- a/generators/poppler/config-okular-poppler.h.cmake +++ b/generators/poppler/config-okular-poppler.h.cmake @@ -30,3 +30,6 @@ /* Defined if we have the 0.65 version of the Poppler library */ #cmakedefine HAVE_POPPLER_0_65 1 + +/* Defined if we have the 0.69 version of the Poppler library */ +#cmakedefine HAVE_POPPLER_0_69 1 diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -192,7 +192,10 @@ void AnnotationWidget::applyChanges() { if ( m_textAnn->inplaceIntent() == Okular::TextAnnotation::TypeWriter ) + { + m_textAnn->setTextColor( m_colorBn->color() ); return; + } m_ann->style().setColor( m_colorBn->color() ); m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 ); } @@ -222,7 +225,17 @@ connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) ); } + else if ( m_textAnn->inplaceIntent() == Okular::TextAnnotation::TypeWriter ) + { + QLabel * tmplabel = new QLabel( i18n( "&Font Color:" ), widget ); + gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); + m_colorBn = new KColorButton( widget ); + m_colorBn->setColor( m_textAnn->textColor() ); + tmplabel->setBuddy( m_colorBn ); + gridlayout->addWidget( m_colorBn, 0, 1 ); + connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); + } QWidget * styleWidget = createStyleWidget(); if ( styleWidget ) gridlayout->addWidget( styleWidget, 2, 0, 1, 2 ); diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -686,6 +686,7 @@ image.fill( acolor.rgba() ); QPainter painter( &image ); painter.setFont( text->textFont() ); + painter.setPen( text->textColor() ); 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; diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -175,6 +175,14 @@ { ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); } + // set font color + if ( m_engineElement.hasAttribute( QStringLiteral("color") ) ) + { + if ( inplaceIntent == Okular::TextAnnotation::TypeWriter ) + ta->setTextColor( m_engineElement.attribute( QStringLiteral("color") ) ); + else + ta->setTextColor( Qt::black ); + } //set boundary rect.left = qMin(startpoint.x,point.x); rect.top = qMin(startpoint.y,point.y);