diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -173,6 +173,8 @@ QWidget * createStyleWidget() override; private: + static QIcon endStyleIcon( Okular::LineAnnotation::TermStyle endStyle ); + Okular::LineAnnotation * m_lineAnn; int m_lineType; QDoubleSpinBox * m_spinLL { nullptr }; diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -24,10 +24,12 @@ #include #include #include +#include #include #include "core/document.h" #include "guiutils.h" +#include "pagepainter.h" #define FILEATTACH_ICONSIZE 48 @@ -530,11 +532,25 @@ gridlay2->addWidget( m_startStyleCombo, 1, 1, Qt::AlignLeft ); gridlay2->addWidget( m_endStyleCombo, 2, 1, Qt::AlignLeft ); - for ( const QString &i: { i18n( "Square" ), i18n( "Circle" ), i18n( "Diamond" ), i18n( "Open Arrow" ), i18n( "Closed Arrow" ), - i18n( "None" ), i18n( "Butt" ), i18n( "Right Open Arrow" ), i18n( "Right Closed Arrow" ), i18n( "Slash" ) } ) + using TermStyleEntry = QPair; + for ( const TermStyleEntry &item: + { + TermStyleEntry { Okular::LineAnnotation::TermStyle::Square, i18n( "Square" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::Circle, i18n( "Circle" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::Diamond, i18n( "Diamond" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::OpenArrow, i18n( "Open Arrow" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::ClosedArrow, i18n( "Closed Arrow" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::None, i18n( "None" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::Butt, i18n( "Butt" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::ROpenArrow, i18n( "Right Open Arrow" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::RClosedArrow, i18n( "Right Closed Arrow" ) }, + TermStyleEntry { Okular::LineAnnotation::TermStyle::Slash, i18n( "Slash" ) } + } + ) { - m_startStyleCombo->addItem( i ); - m_endStyleCombo->addItem( i ); + QIcon icon = endStyleIcon( item.first ); + m_startStyleCombo->addItem( icon, item.second ); + m_endStyleCombo->addItem( icon, item.second ); } m_startStyleCombo->setCurrentIndex( m_lineAnn->lineStartStyle() ); @@ -590,6 +606,23 @@ m_lineAnn->style().setWidth( m_spinSize->value() ); } +QIcon LineAnnotationWidget::endStyleIcon( Okular::LineAnnotation::TermStyle endStyle ) { + const int iconSize { 48 }; + QImage image { iconSize, iconSize, QImage::Format_ARGB32}; + image.fill( qRgba(0, 0, 0, 0) ); + Okular::LineAnnotation prototype; + prototype.setLinePoints( { { 0, 0.5 }, { 0.65, 0.5 } } ); + prototype.setLineStartStyle(Okular::LineAnnotation::TermStyle::None); + prototype.setLineEndStyle( endStyle ); + prototype.style().setWidth( 4 ); + prototype.style().setColor( Qt::black ); + prototype.style().setLineStyle( Okular::Annotation::LineStyle::Solid ); + prototype.setBoundingRectangle( { 0, 0, 1, 1 } ); + LineAnnotPainter linepainter { &prototype, { iconSize, iconSize }, 1, QTransform() }; + linepainter.draw( image ); + return QIcon( QPixmap::fromImage( image ) ); +} + InkAnnotationWidget::InkAnnotationWidget( Okular::Annotation * ann )