diff --git a/conf/editannottooldialog.h b/conf/editannottooldialog.h --- a/conf/editannottooldialog.h +++ b/conf/editannottooldialog.h @@ -40,7 +40,8 @@ ToolPolygon, ToolTextMarkup, ToolGeometricalShape, - ToolStamp + ToolStamp, + ToolTypewriter }; explicit EditAnnotToolDialog( QWidget *parent = nullptr, const QDomElement &initialState = QDomElement() ); diff --git a/conf/editannottooldialog.cpp b/conf/editannottooldialog.cpp --- a/conf/editannottooldialog.cpp +++ b/conf/editannottooldialog.cpp @@ -92,6 +92,7 @@ m_type->addItem( i18n("Text markup"), qVariantFromValue( ToolTextMarkup ) ); m_type->addItem( i18n("Geometrical shape"), qVariantFromValue( ToolGeometricalShape ) ); m_type->addItem( i18n("Stamp"), qVariantFromValue( ToolStamp ) ); + m_type->addItem( i18n("Typewriter"), qVariantFromValue( ToolTypewriter ) ); createStubAnnotation(); @@ -265,6 +266,19 @@ annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Stamp") ); annotationElement.setAttribute( QStringLiteral("icon"), sa->stampIconName() ); } + else if ( toolType == ToolTypewriter ) + { + Okular::TextAnnotation * ta = static_cast( m_stubann ); + toolElement.setAttribute( QStringLiteral("type"), QStringLiteral("typewriter") ); + engineElement.setAttribute( QStringLiteral("type"), QStringLiteral("PickPoint") ); + engineElement.setAttribute( QStringLiteral("color"), color ); + engineElement.setAttribute( QStringLiteral("block"), QStringLiteral("true") ); + annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Typewriter") ); + annotationElement.setAttribute( QStringLiteral("color"), color ); + annotationElement.setAttribute( QStringLiteral("width"), width ); + if ( ta->textFont() != QApplication::font() ) + annotationElement.setAttribute( QStringLiteral("font"), ta->textFont().toString() ); + } if ( opacity != QStringLiteral("1") ) annotationElement.setAttribute( QStringLiteral("opacity"), opacity ); @@ -341,6 +355,15 @@ sa->setStampIconName( QStringLiteral("okular") ); m_stubann = sa; } + else if ( toolType == ToolTypewriter ) + { + Okular::TextAnnotation * ta = new Okular::TextAnnotation(); + ta->setTextType( Okular::TextAnnotation::InPlace ); + ta->setInplaceIntent( Okular::TextAnnotation::TypeWriter ); + ta->style().setWidth( 0.0 ); + ta->style().setColor( QColor(255,255,255,0) ); + m_stubann = ta; + } } void EditAnnotToolDialog::rebuildAppearanceBox() @@ -471,6 +494,17 @@ Okular::HighlightAnnotation * ha = static_cast( m_stubann ); ha->setHighlightType( Okular::HighlightAnnotation::Underline ); } + else if ( annotType == QLatin1String("typewriter") ) + { + setToolType( ToolTypewriter ); + Okular::TextAnnotation * ta = static_cast( m_stubann ); + if ( annotationElement.hasAttribute( QStringLiteral("font") ) ) + { + QFont f; + f.fromString( annotationElement.attribute( QStringLiteral("font") ) ); + ta->setTextFont( f ); + } + } // Common properties if ( annotationElement.hasAttribute( QStringLiteral("color") ) ) diff --git a/ui/annotationpropertiesdialog.cpp b/ui/annotationpropertiesdialog.cpp --- a/ui/annotationpropertiesdialog.cpp +++ b/ui/annotationpropertiesdialog.cpp @@ -117,7 +117,12 @@ if(((Okular::TextAnnotation*)m_annot)->textType()==Okular::TextAnnotation::Linked) captiontext = i18n( "Pop-up Note Properties" ); else - captiontext = i18n( "Inline Note Properties" ); + { + if(((Okular::TextAnnotation*)m_annot)->inplaceIntent()==Okular::TextAnnotation::TypeWriter) + captiontext = i18n( "Typewriter Properties" ); + else + captiontext = i18n( "Inline Note Properties" ); + } break; case Okular::Annotation::ALine: if ( ((Okular::LineAnnotation*)m_annot)->linePoints().count() == 2 ) diff --git a/ui/annotationwidgets.h b/ui/annotationwidgets.h --- a/ui/annotationwidgets.h +++ b/ui/annotationwidgets.h @@ -91,13 +91,20 @@ virtual QWidget * createStyleWidget(); virtual QWidget * createExtraWidget(); +private: + virtual bool hasColorButton() const { return true; } + virtual bool hasOpacityBox() const { return true; } + Okular::Annotation * m_ann; - QWidget * m_appearanceWidget; - QWidget * m_extraWidget; - KColorButton *m_colorBn; - QSpinBox *m_opacity; + QWidget * m_appearanceWidget { nullptr }; + QWidget * m_extraWidget { nullptr }; + KColorButton *m_colorBn { nullptr }; + QSpinBox *m_opacity { nullptr }; }; +class QVBoxLayout; +class QGridLayout; + class TextAnnotationWidget : public AnnotationWidget { @@ -112,11 +119,24 @@ QWidget * createStyleWidget() override; private: + virtual bool hasColorButton() const override; + virtual bool hasOpacityBox() const override; + + void createPopupNoteStyleUi( QWidget * widget, QVBoxLayout * layout ); + void createInlineNoteStyleUi( QWidget * widget, QVBoxLayout * layout ); + void createTypewriterStyleUi( QWidget * widget, QVBoxLayout * layout ); + void addPixmapSelector( QWidget * widget, QLayout * layout ); + void addFontRequester( QWidget * widget, QGridLayout * layout ); + void addTextAlignComboBox( QWidget * widget, QGridLayout * layout ); + void addWidthSpinBox( QWidget * widget, QGridLayout * layout ); + + inline bool isTypewriter() const { return ( m_textAnn->inplaceIntent() == Okular::TextAnnotation::TypeWriter ); } + Okular::TextAnnotation * m_textAnn; - PixmapPreviewSelector * m_pixmapSelector; - KFontRequester * m_fontReq; - QComboBox * m_textAlign; - QDoubleSpinBox * m_spinWidth; + PixmapPreviewSelector * m_pixmapSelector { nullptr }; + KFontRequester * m_fontReq { nullptr }; + QComboBox * m_textAlign { nullptr }; + QDoubleSpinBox * m_spinWidth { nullptr }; }; class StampAnnotationWidget diff --git a/ui/annotationwidgets.cpp b/ui/annotationwidgets.cpp --- a/ui/annotationwidgets.cpp +++ b/ui/annotationwidgets.cpp @@ -157,7 +157,7 @@ AnnotationWidget::AnnotationWidget( Okular::Annotation * ann ) - : QObject(), m_ann( ann ), m_appearanceWidget( nullptr ), m_extraWidget( nullptr ) + : m_ann( ann ) { } @@ -190,39 +190,47 @@ void AnnotationWidget::applyChanges() { - m_ann->style().setColor( m_colorBn->color() ); - m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 ); + if (m_colorBn) + m_ann->style().setColor( m_colorBn->color() ); + if (m_opacity) + m_ann->style().setOpacity( (double)m_opacity->value() / 100.0 ); } QWidget * AnnotationWidget::createAppearanceWidget() { QWidget * widget = new QWidget(); QGridLayout * gridlayout = new QGridLayout( widget ); - - QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget ); - gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); - m_colorBn = new KColorButton( widget ); - m_colorBn->setColor( m_ann->style().color() ); - tmplabel->setBuddy( m_colorBn ); - gridlayout->addWidget( m_colorBn, 0, 1 ); - - tmplabel = new QLabel( i18n( "&Opacity:" ), widget ); - gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); - m_opacity = new QSpinBox( widget ); - m_opacity->setRange( 0, 100 ); - m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) ); - m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) ); - tmplabel->setBuddy( m_opacity ); - gridlayout->addWidget( m_opacity, 1, 1 ); + if ( hasColorButton() ) + { + QLabel * tmplabel = new QLabel( i18n( "&Color:" ), widget ); + gridlayout->addWidget( tmplabel, 0, 0, Qt::AlignRight ); + m_colorBn = new KColorButton( widget ); + m_colorBn->setColor( m_ann->style().color() ); + tmplabel->setBuddy( m_colorBn ); + gridlayout->addWidget( m_colorBn, 0, 1 ); + } + if ( hasOpacityBox() ) + { + QLabel * tmplabel = new QLabel( i18n( "&Opacity:" ), widget ); + gridlayout->addWidget( tmplabel, 1, 0, Qt::AlignRight ); + m_opacity = new QSpinBox( widget ); + m_opacity->setRange( 0, 100 ); + m_opacity->setValue( (int)( m_ann->style().opacity() * 100 ) ); + m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) ); + tmplabel->setBuddy( m_opacity ); + gridlayout->addWidget( m_opacity, 1, 1 ); + } QWidget * styleWidget = createStyleWidget(); if ( styleWidget ) gridlayout->addWidget( styleWidget, 2, 0, 1, 2 ); gridlayout->addItem( new QSpacerItem( 5, 5, QSizePolicy::Fixed, QSizePolicy::MinimumExpanding ), 3, 0 ); - connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); - connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) ); + if ( m_colorBn ) + connect( m_colorBn, &KColorButton::changed, this, &AnnotationWidget::dataChanged ); + if ( m_opacity ) + connect( m_opacity, SIGNAL(valueChanged(int)), this, SIGNAL(dataChanged()) ); return widget; } @@ -239,75 +247,40 @@ TextAnnotationWidget::TextAnnotationWidget( Okular::Annotation * ann ) - : AnnotationWidget( ann ), m_pixmapSelector( nullptr ) + : AnnotationWidget( ann ) { m_textAnn = static_cast< Okular::TextAnnotation * >( ann ); } QWidget * TextAnnotationWidget::createStyleWidget() { QWidget * widget = new QWidget(); - QVBoxLayout * lay = new QVBoxLayout( widget ); - lay->setMargin( 0 ); + QVBoxLayout * layout = new QVBoxLayout( widget ); + layout->setMargin( 0 ); if ( m_textAnn->textType() == Okular::TextAnnotation::Linked ) { - QGroupBox * gb = new QGroupBox( widget ); - lay->addWidget( gb ); - gb->setTitle( i18n( "Icon" ) ); - QHBoxLayout * gblay = new QHBoxLayout( gb ); - m_pixmapSelector = new PixmapPreviewSelector( gb ); - gblay->addWidget( m_pixmapSelector ); - - m_pixmapSelector->addItem( i18n( "Comment" ), QStringLiteral("Comment") ); - m_pixmapSelector->addItem( i18n( "Help" ), QStringLiteral("Help") ); - m_pixmapSelector->addItem( i18n( "Insert" ), QStringLiteral("Insert") ); - m_pixmapSelector->addItem( i18n( "Key" ), QStringLiteral("Key") ); - m_pixmapSelector->addItem( i18n( "New Paragraph" ), QStringLiteral("NewParagraph") ); - m_pixmapSelector->addItem( i18n( "Note" ), QStringLiteral("Note") ); - m_pixmapSelector->addItem( i18n( "Paragraph" ), QStringLiteral("Paragraph") ); - m_pixmapSelector->setIcon( m_textAnn->textIcon() ); - - connect( m_pixmapSelector, &PixmapPreviewSelector::iconChanged, this, &AnnotationWidget::dataChanged ); + createPopupNoteStyleUi( widget, layout ); } else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) { - QGridLayout * innerlay = new QGridLayout(); - lay->addLayout( innerlay ); - - QLabel * tmplabel = new QLabel( i18n( "Font:" ), widget ); - innerlay->addWidget( tmplabel, 0, 0 ); - m_fontReq = new KFontRequester( widget ); - innerlay->addWidget( m_fontReq, 0, 1 ); - m_fontReq->setFont( m_textAnn->textFont() ); - - tmplabel = new QLabel( i18n( "Align:" ), widget ); - innerlay->addWidget( tmplabel, 1, 0 ); - m_textAlign = new KComboBox( widget ); - innerlay->addWidget( m_textAlign, 1, 1 ); - m_textAlign->addItem( i18n("Left") ); - m_textAlign->addItem( i18n("Center") ); - 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, &KFontRequester::fontSelected, this, &AnnotationWidget::dataChanged ); - - connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) ); - connect( m_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); + if ( isTypewriter() ) + createTypewriterStyleUi( widget, layout ); + else + createInlineNoteStyleUi( widget, layout ); } return widget; } +bool TextAnnotationWidget::hasColorButton() const { + return !isTypewriter(); +} + +bool TextAnnotationWidget::hasOpacityBox() const { + return !isTypewriter(); +} + void TextAnnotationWidget::applyChanges() { AnnotationWidget::applyChanges(); @@ -318,11 +291,86 @@ else if ( m_textAnn->textType() == Okular::TextAnnotation::InPlace ) { m_textAnn->setTextFont( m_fontReq->font() ); - m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() ); - m_textAnn->style().setWidth( m_spinWidth->value() ); + if ( !isTypewriter() ) + { + m_textAnn->setInplaceAlignment( m_textAlign->currentIndex() ); + m_textAnn->style().setWidth( m_spinWidth->value() ); + } } } +void TextAnnotationWidget::createPopupNoteStyleUi( QWidget * widget, QVBoxLayout * layout ) { + QGroupBox * gb = new QGroupBox( widget ); + layout->addWidget( gb ); + QHBoxLayout * gblay = new QHBoxLayout( gb ); + gb->setTitle( i18n( "Icon" ) ); + addPixmapSelector( gb, gblay ); +} + +void TextAnnotationWidget::createInlineNoteStyleUi( QWidget * widget, QVBoxLayout * layout ) { + QGridLayout * innerlay = new QGridLayout(); + layout->addLayout( innerlay ); + addFontRequester(widget, innerlay); + addTextAlignComboBox(widget, innerlay); + addWidthSpinBox(widget, innerlay); +} + +void TextAnnotationWidget::createTypewriterStyleUi( QWidget * widget, QVBoxLayout * layout ) { + QGridLayout * innerlay = new QGridLayout(); + layout->addLayout( innerlay ); + addFontRequester(widget, innerlay); +} + +void TextAnnotationWidget::addPixmapSelector( QWidget * widget, QLayout * layout ) +{ + m_pixmapSelector = new PixmapPreviewSelector( widget ); + layout->addWidget( m_pixmapSelector ); + m_pixmapSelector->addItem( i18n( "Comment" ), QStringLiteral("Comment") ); + m_pixmapSelector->addItem( i18n( "Help" ), QStringLiteral("Help") ); + m_pixmapSelector->addItem( i18n( "Insert" ), QStringLiteral("Insert") ); + m_pixmapSelector->addItem( i18n( "Key" ), QStringLiteral("Key") ); + m_pixmapSelector->addItem( i18n( "New Paragraph" ), QStringLiteral("NewParagraph") ); + m_pixmapSelector->addItem( i18n( "Note" ), QStringLiteral("Note") ); + m_pixmapSelector->addItem( i18n( "Paragraph" ), QStringLiteral("Paragraph") ); + m_pixmapSelector->setIcon( m_textAnn->textIcon() ); + connect( m_pixmapSelector, &PixmapPreviewSelector::iconChanged, this, &AnnotationWidget::dataChanged ); +} + +void TextAnnotationWidget::addFontRequester( QWidget * widget, QGridLayout * layout ) +{ + QLabel * tmplabel = new QLabel( i18n( "Font:" ), widget ); + layout->addWidget( tmplabel, 0, 0 ); + m_fontReq = new KFontRequester( widget ); + layout->addWidget( m_fontReq, 0, 1 ); + m_fontReq->setFont( m_textAnn->textFont() ); + connect( m_fontReq, &KFontRequester::fontSelected, this, &AnnotationWidget::dataChanged ); +} + +void TextAnnotationWidget::addTextAlignComboBox( QWidget * widget, QGridLayout * layout ) +{ + QLabel * tmplabel = new QLabel( i18n( "Align:" ), widget ); + layout->addWidget( tmplabel, 1, 0 ); + m_textAlign = new KComboBox( widget ); + layout->addWidget( m_textAlign, 1, 1 ); + m_textAlign->addItem( i18n("Left") ); + m_textAlign->addItem( i18n("Center") ); + m_textAlign->addItem( i18n("Right") ); + m_textAlign->setCurrentIndex( m_textAnn->inplaceAlignment() ); + connect( m_textAlign, SIGNAL(currentIndexChanged(int)), this, SIGNAL(dataChanged()) ); +} + +void TextAnnotationWidget::addWidthSpinBox( QWidget * widget, QGridLayout * layout ) +{ + QLabel * tmplabel = new QLabel( i18n( "Border Width:" ), widget ); + layout->addWidget( tmplabel, 2, 0, Qt::AlignRight ); + m_spinWidth = new QDoubleSpinBox( widget ); + layout->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_spinWidth, SIGNAL(valueChanged(double)), this, SIGNAL(dataChanged()) ); +} StampAnnotationWidget::StampAnnotationWidget( Okular::Annotation * ann ) : AnnotationWidget( ann ), m_pixmapSelector( nullptr ) diff --git a/ui/annotwindow.cpp b/ui/annotwindow.cpp --- a/ui/annotwindow.cpp +++ b/ui/annotwindow.cpp @@ -259,7 +259,15 @@ void AnnotWindow::reloadInfo() { - const QColor newcolor = m_annot->style().color().isValid() ? m_annot->style().color() : Qt::yellow; + QColor newcolor; + if ( m_annot->subType() == Okular::Annotation::AText ) + { + Okular::TextAnnotation * textAnn = static_cast< Okular::TextAnnotation * >( m_annot ); + if ( textAnn->textType() == Okular::TextAnnotation::InPlace && textAnn->inplaceIntent() == Okular::TextAnnotation::TypeWriter ) + newcolor = QColor("#fdfd96"); + } + if ( !newcolor.isValid() ) + newcolor = m_annot->style().color().isValid() ? QColor(m_annot->style().color().red(), m_annot->style().color().green(), m_annot->style().color().blue(), 255) : Qt::yellow; if ( newcolor != m_color ) { m_color = newcolor; diff --git a/ui/data/CMakeLists.txt b/ui/data/CMakeLists.txt --- a/ui/data/CMakeLists.txt +++ b/ui/data/CMakeLists.txt @@ -21,6 +21,8 @@ tool-note-inline.png tool-note-inline-okular-colorizable.png tool-note-inline-okular-colorizable@2x.png + tool-typewriter-okular-colorizable.png + tool-typewriter-okular-colorizable@2x.png DESTINATION ${KDE_INSTALL_DATADIR}/okular/pics) # install annotation page images install(FILES diff --git a/ui/data/sources/tool-typewriter-okular-colorizable.svgz b/ui/data/sources/tool-typewriter-okular-colorizable.svgz new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@ - + 1 - + 2 - + 3 - + 4 - + 5 - + 6 @@ -60,15 +60,20 @@ 7 - + 8 - + 9 + + + + + diff --git a/ui/guiutils.cpp b/ui/guiutils.cpp --- a/ui/guiutils.cpp +++ b/ui/guiutils.cpp @@ -73,7 +73,12 @@ if( ( (Okular::TextAnnotation*)ann )->textType() == Okular::TextAnnotation::Linked ) ret = i18n( "Pop-up Note" ); else - ret = i18n( "Inline Note" ); + { + if( ( (Okular::TextAnnotation*)ann )->inplaceIntent() == Okular::TextAnnotation::TypeWriter ) + ret = i18n( "Typewriter" ); + else + ret = i18n( "Inline Note" ); + } break; case Okular::Annotation::ALine: if( ( (Okular::LineAnnotation*)ann )->linePoints().count() == 2 ) diff --git a/ui/pagepainter.cpp b/ui/pagepainter.cpp --- a/ui/pagepainter.cpp +++ b/ui/pagepainter.cpp @@ -656,7 +656,7 @@ Okular::Annotation * a = *aIt; // honor opacity settings on supported types - unsigned int opacity = (unsigned int)( 255.0 * a->style().opacity() ); + unsigned int opacity = (unsigned int)( a->style().color().alpha() * a->style().opacity() ); // skip the annotation drawing if all the annotation is fully // transparent, but not with text annotations if ( opacity <= 0 && a->subType() != Okular::Annotation::AText ) diff --git a/ui/pageviewannotator.cpp b/ui/pageviewannotator.cpp --- a/ui/pageviewannotator.cpp +++ b/ui/pageviewannotator.cpp @@ -141,6 +141,44 @@ } } + void addInPlaceTextAnnotation( Okular::Annotation * &ann, const QString summary, const QString content, Okular::TextAnnotation::InplaceIntent inplaceIntent ) + { + Okular::TextAnnotation * ta = new Okular::TextAnnotation(); + ann = ta; + ta->setFlags( ta->flags() | Okular::Annotation::FixedRotation ); + ta->setContents( content ); + ta->setTextType( Okular::TextAnnotation::InPlace ); + ta->setInplaceIntent( inplaceIntent ); + //set alignment + if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) + ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); + //set font + if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) + { + QFont f; + f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); + ta->setTextFont( f ); + } + //set width + if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) + { + ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); + } + //set boundary + rect.left = qMin(startpoint.x,point.x); + rect.top = qMin(startpoint.y,point.y); + rect.right = qMax(startpoint.x,point.x); + rect.bottom = qMax(startpoint.y,point.y); + qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; + static const int padding = 2; + const QFontMetricsF mf(ta->textFont()); + const QRectF rcf = mf.boundingRect( Okular::NormalizedRect( rect.left, rect.top, 1.0, 1.0 ).geometry( (int)pagewidth, (int)pageheight ).adjusted( padding, padding, -padding, -padding ), + Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); + rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); + rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); + ta->window().setSummary( summary ); + } + QList< Okular::Annotation* > end() override { // find out annotation's description node @@ -154,52 +192,22 @@ // find out annotation's type Okular::Annotation * ann = nullptr; const QString typeString = m_annotElement.attribute( QStringLiteral("type") ); - // create TextAnnotation from path - if ( typeString == QLatin1String("FreeText")) //setFlags( ta->flags() | Okular::Annotation::FixedRotation ); - ta->setContents( note ); - ta->setTextType( Okular::TextAnnotation::InPlace ); - //set alignment - if ( m_annotElement.hasAttribute( QStringLiteral("align") ) ) - ta->setInplaceAlignment( m_annotElement.attribute( QStringLiteral("align") ).toInt() ); - //set font - if ( m_annotElement.hasAttribute( QStringLiteral("font") ) ) - { - QFont f; - f.fromString( m_annotElement.attribute( QStringLiteral("font") ) ); - ta->setTextFont( f ); - } - //set width - if ( m_annotElement.hasAttribute( QStringLiteral ( "width" ) ) ) - { - ta->style().setWidth( m_annotElement.attribute( QStringLiteral ( "width" ) ).toDouble() ); - } - //set boundary - rect.left = qMin(startpoint.x,point.x); - rect.top = qMin(startpoint.y,point.y); - rect.right = qMax(startpoint.x,point.x); - rect.bottom = qMax(startpoint.y,point.y); - qCDebug(OkularUiDebug).nospace() << "xyScale=" << xscale << "," << yscale; - static const int padding = 2; - const QFontMetricsF mf(ta->textFont()); - const QRectF rcf = mf.boundingRect( Okular::NormalizedRect( rect.left, rect.top, 1.0, 1.0 ).geometry( (int)pagewidth, (int)pageheight ).adjusted( padding, padding, -padding, -padding ), - Qt::AlignTop | Qt::AlignLeft | Qt::TextWordWrap, ta->contents() ); - rect.right = qMax(rect.right, rect.left+(rcf.width()+padding*2)/pagewidth); - rect.bottom = qMax(rect.bottom, rect.top+(rcf.height()+padding*2)/pageheight); - ta->window().setSummary( i18n( "Inline Note" ) ); - } + const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); + if( resok ) + addInPlaceTextAnnotation( ann, i18n("Inline Note"), content, Okular::TextAnnotation::Unknown ); } - else if ( typeString == QLatin1String("Text")) + else if ( typeString == QLatin1String("Typewriter") ) + { + bool resok; + const QString content = QInputDialog::getMultiLineText(nullptr, i18n( "New Text Note" ), i18n( "Text of the new note:" ), QString(), &resok); + if( resok ) + addInPlaceTextAnnotation( ann, i18n("Typewriter"), content, Okular::TextAnnotation::TypeWriter ); + } + else if ( typeString == QLatin1String("Text") ) { Okular::TextAnnotation * ta = new Okular::TextAnnotation(); ann = ta; @@ -1028,6 +1036,8 @@ tip = i18nc( "Annotation tool", "Strike out text" ); else if ( annotType == QLatin1String("underline") ) tip = i18nc( "Annotation tool", "Underline text" ); + else if ( annotType == QLatin1String("typewriter") ) + tip = i18nc( "Annotation tool", "Typewriter Annotation (drag to select a zone)" ); if ( !tip.isEmpty() && !m_continuousMode ) m_pageView->displayMessage( tip, QString(), PageViewMessage::Annotation ); @@ -1089,6 +1099,8 @@ return i18n( "Strike out" ); else if ( annotType == QLatin1String("underline") ) return i18n( "Underline" ); + else if ( annotType == QLatin1String("typewriter") ) + return i18n( "Typewriter" ); else return QString(); } @@ -1109,7 +1121,7 @@ pixmap.load( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-base-okular" + imageVariant + ".png") ) ); /* Parse color, innerColor and icon (if present) */ - QColor engineColor, innerColor; + QColor engineColor, innerColor, annotColor; QString icon; QDomNodeList engineNodeList = toolElement.elementsByTagName( QStringLiteral("engine") ); if ( engineNodeList.size() > 0 ) @@ -1122,6 +1134,8 @@ if ( annotationNodeList.size() > 0 ) { QDomElement annotationEl = annotationNodeList.item( 0 ).toElement(); + if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("color") ) ) + annotColor = annotationEl.attribute( QStringLiteral("color") ); if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("innerColor") ) ) innerColor = QColor( annotationEl.attribute( QStringLiteral("innerColor") ) ); if ( !annotationEl.isNull() && annotationEl.hasAttribute( QStringLiteral("icon") ) ) @@ -1231,6 +1245,13 @@ p.drawLine( 1, 13, 16, 13 ); p.drawLine( 0, 20, 19, 20 ); } + else if ( annotType == QLatin1String("typewriter") ) + { + QImage overlay( QStandardPaths::locate(QStandardPaths::GenericDataLocation, QString("okular/pics/tool-typewriter-okular-colorizable" + imageVariant + ".png") ) ); + /* Here we want to colorize the icon with font color instead of background color. Font color is black a.t.m. */ + GuiUtils::colorizeImage( overlay, Qt::black ); + p.drawImage( QPoint(-2,2), overlay ); + } else { /* Unrecognized annotation type -- It shouldn't happen */