File indexing completed on 2024-04-28 15:51:43

0001 /*
0002     SPDX-FileCopyrightText: 2012 Fabio D 'Urso <fabiodurso@hotmail.it>
0003     SPDX-FileCopyrightText: 2015 Laurent Montel <montel@kde.org>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #include "editannottooldialog.h"
0009 
0010 #include <KColorButton>
0011 #include <KComboBox>
0012 #include <KLineEdit>
0013 #include <KLocalizedString>
0014 
0015 #include <KConfigGroup>
0016 #include <QApplication>
0017 #include <QDialogButtonBox>
0018 #include <QDomDocument>
0019 #include <QGroupBox>
0020 #include <QHBoxLayout>
0021 #include <QLabel>
0022 #include <QListWidget>
0023 #include <QListWidgetItem>
0024 #include <QPushButton>
0025 #include <QStackedWidget>
0026 #include <QVBoxLayout>
0027 
0028 #include "annotationwidgets.h"
0029 #include "core/annotations.h"
0030 #include "pageviewannotator.h"
0031 
0032 EditAnnotToolDialog::EditAnnotToolDialog(QWidget *parent, const QDomElement &initialState, bool builtinTool)
0033     : QDialog(parent)
0034     , m_stubann(nullptr)
0035     , m_annotationWidget(nullptr)
0036 {
0037     m_builtinTool = builtinTool;
0038 
0039     QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
0040     QVBoxLayout *mainLayout = new QVBoxLayout;
0041     setLayout(mainLayout);
0042     QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
0043     okButton->setDefault(true);
0044     okButton->setShortcut(Qt::CTRL | Qt::Key_Return); // NOLINT(bugprone-suspicious-enum-usage)
0045     connect(buttonBox, &QDialogButtonBox::accepted, this, &EditAnnotToolDialog::accept);
0046     connect(buttonBox, &QDialogButtonBox::rejected, this, &EditAnnotToolDialog::reject);
0047     okButton->setDefault(true);
0048 
0049     QLabel *tmplabel;
0050     QWidget *widget = new QWidget(this);
0051     QGridLayout *widgetLayout = new QGridLayout(widget);
0052 
0053     mainLayout->addWidget(widget);
0054     mainLayout->addWidget(buttonBox);
0055 
0056     m_name = new KLineEdit(widget);
0057     m_name->setReadOnly(m_builtinTool);
0058     mainLayout->addWidget(m_name);
0059     tmplabel = new QLabel(i18n("&Name:"), widget);
0060     mainLayout->addWidget(tmplabel);
0061     tmplabel->setBuddy(m_name);
0062     widgetLayout->addWidget(tmplabel, 0, 0, Qt::AlignRight);
0063     widgetLayout->addWidget(m_name, 0, 1);
0064 
0065     m_type = new KComboBox(false, widget);
0066     m_type->setVisible(!m_builtinTool);
0067     mainLayout->addWidget(m_type);
0068     connect(m_type, static_cast<void (KComboBox::*)(int)>(&KComboBox::currentIndexChanged), this, &EditAnnotToolDialog::slotTypeChanged);
0069     tmplabel = new QLabel(i18n("&Type:"), widget);
0070     mainLayout->addWidget(tmplabel);
0071     tmplabel->setBuddy(m_type);
0072     tmplabel->setVisible(!m_builtinTool);
0073     widgetLayout->addWidget(tmplabel, 1, 0, Qt::AlignRight);
0074     widgetLayout->addWidget(m_type, 1, 1);
0075 
0076     m_toolIcon = new QLabel(widget);
0077     mainLayout->addWidget(m_toolIcon);
0078     m_toolIcon->setAlignment(Qt::AlignRight | Qt::AlignTop);
0079     m_toolIcon->setMinimumSize(40, 32);
0080     widgetLayout->addWidget(m_toolIcon, 0, 2, 2, 1);
0081 
0082     m_appearanceBox = new QGroupBox(i18n("Appearance"), widget);
0083     mainLayout->addWidget(m_appearanceBox);
0084     m_appearanceBox->setLayout(new QVBoxLayout(m_appearanceBox));
0085     widgetLayout->addWidget(m_appearanceBox, 2, 0, 1, 3);
0086 
0087     // Populate combobox with annotation types
0088     m_type->addItem(i18n("Pop-up Note"), QVariant::fromValue(ToolNoteLinked));
0089     m_type->addItem(i18n("Inline Note"), QVariant::fromValue(ToolNoteInline));
0090     m_type->addItem(i18n("Freehand Line"), QVariant::fromValue(ToolInk));
0091     m_type->addItem(i18n("Straight Line"), QVariant::fromValue(ToolStraightLine));
0092     m_type->addItem(i18n("Polygon"), QVariant::fromValue(ToolPolygon));
0093     m_type->addItem(i18n("Text markup"), QVariant::fromValue(ToolTextMarkup));
0094     m_type->addItem(i18n("Geometrical shape"), QVariant::fromValue(ToolGeometricalShape));
0095     m_type->addItem(i18n("Stamp"), QVariant::fromValue(ToolStamp));
0096     m_type->addItem(i18n("Typewriter"), QVariant::fromValue(ToolTypewriter));
0097 
0098     createStubAnnotation();
0099 
0100     if (initialState.isNull()) {
0101         setWindowTitle(i18n("Create annotation tool"));
0102     } else {
0103         setWindowTitle(i18n("Edit annotation tool"));
0104         loadTool(initialState);
0105     }
0106 
0107     rebuildAppearanceBox();
0108     updateDefaultNameAndIcon();
0109 }
0110 
0111 EditAnnotToolDialog::~EditAnnotToolDialog()
0112 {
0113     delete m_stubann;
0114     delete m_annotationWidget;
0115 }
0116 
0117 QString EditAnnotToolDialog::name() const
0118 {
0119     return m_name->text();
0120 }
0121 
0122 QDomDocument EditAnnotToolDialog::toolXml() const
0123 {
0124     const ToolType toolType = m_type->itemData(m_type->currentIndex()).value<ToolType>();
0125 
0126     QDomDocument doc;
0127     QDomElement toolElement = doc.createElement(QStringLiteral("tool"));
0128     QDomElement engineElement = doc.createElement(QStringLiteral("engine"));
0129     QDomElement annotationElement = doc.createElement(QStringLiteral("annotation"));
0130     doc.appendChild(toolElement);
0131     toolElement.appendChild(engineElement);
0132     engineElement.appendChild(annotationElement);
0133 
0134     const QString color = m_stubann->style().color().name(QColor::HexArgb);
0135     const QString opacity = QString::number(m_stubann->style().opacity());
0136     const QString width = QString::number(m_stubann->style().width());
0137 
0138     if (toolType == ToolNoteLinked) {
0139         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0140         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("note-linked"));
0141         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PickPoint"));
0142         engineElement.setAttribute(QStringLiteral("color"), color);
0143         engineElement.setAttribute(QStringLiteral("hoverIcon"), QStringLiteral("tool-note"));
0144         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Text"));
0145         annotationElement.setAttribute(QStringLiteral("color"), color);
0146         annotationElement.setAttribute(QStringLiteral("icon"), ta->textIcon());
0147     } else if (toolType == ToolNoteInline) {
0148         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0149         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("note-inline"));
0150         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PickPoint"));
0151         engineElement.setAttribute(QStringLiteral("color"), color);
0152         engineElement.setAttribute(QStringLiteral("hoverIcon"), QStringLiteral("tool-note-inline"));
0153         engineElement.setAttribute(QStringLiteral("block"), QStringLiteral("true"));
0154         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("FreeText"));
0155         annotationElement.setAttribute(QStringLiteral("color"), color);
0156         annotationElement.setAttribute(QStringLiteral("width"), width);
0157         if (ta->inplaceAlignment() != 0) {
0158             annotationElement.setAttribute(QStringLiteral("align"), ta->inplaceAlignment());
0159         }
0160         if (ta->textFont() != QApplication::font()) {
0161             annotationElement.setAttribute(QStringLiteral("font"), ta->textFont().toString());
0162         }
0163     } else if (toolType == ToolInk) {
0164         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("ink"));
0165         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("SmoothLine"));
0166         engineElement.setAttribute(QStringLiteral("color"), color);
0167         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Ink"));
0168         annotationElement.setAttribute(QStringLiteral("color"), color);
0169         annotationElement.setAttribute(QStringLiteral("width"), width);
0170     } else if (toolType == ToolStraightLine) {
0171         Okular::LineAnnotation *la = static_cast<Okular::LineAnnotation *>(m_stubann);
0172         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("straight-line"));
0173         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PolyLine"));
0174         engineElement.setAttribute(QStringLiteral("color"), color);
0175         engineElement.setAttribute(QStringLiteral("points"), QStringLiteral("2"));
0176         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Line"));
0177         annotationElement.setAttribute(QStringLiteral("color"), color);
0178         annotationElement.setAttribute(QStringLiteral("width"), width);
0179         if (la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0) {
0180             annotationElement.setAttribute(QStringLiteral("leadFwd"), QString::number(la->lineLeadingForwardPoint()));
0181             annotationElement.setAttribute(QStringLiteral("leadBack"), QString::number(la->lineLeadingBackwardPoint()));
0182         }
0183         annotationElement.setAttribute(QStringLiteral("startStyle"), QString::number(la->lineStartStyle()));
0184         annotationElement.setAttribute(QStringLiteral("endStyle"), QString::number(la->lineEndStyle()));
0185     } else if (toolType == ToolPolygon) {
0186         Okular::LineAnnotation *la = static_cast<Okular::LineAnnotation *>(m_stubann);
0187         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("polygon"));
0188         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PolyLine"));
0189         engineElement.setAttribute(QStringLiteral("color"), color);
0190         engineElement.setAttribute(QStringLiteral("points"), QStringLiteral("-1"));
0191         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Line"));
0192         annotationElement.setAttribute(QStringLiteral("color"), color);
0193         annotationElement.setAttribute(QStringLiteral("width"), width);
0194         if (la->lineInnerColor().isValid()) {
0195             annotationElement.setAttribute(QStringLiteral("innerColor"), la->lineInnerColor().name());
0196         }
0197     } else if (toolType == ToolTextMarkup) {
0198         Okular::HighlightAnnotation *ha = static_cast<Okular::HighlightAnnotation *>(m_stubann);
0199 
0200         switch (ha->highlightType()) {
0201         case Okular::HighlightAnnotation::Highlight:
0202             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("highlight"));
0203             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Highlight"));
0204             break;
0205         case Okular::HighlightAnnotation::Squiggly:
0206             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("squiggly"));
0207             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Squiggly"));
0208             break;
0209         case Okular::HighlightAnnotation::Underline:
0210             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("underline"));
0211             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Underline"));
0212             break;
0213         case Okular::HighlightAnnotation::StrikeOut:
0214             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("strikeout"));
0215             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("StrikeOut"));
0216             break;
0217         }
0218 
0219         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("TextSelector"));
0220         engineElement.setAttribute(QStringLiteral("color"), color);
0221         annotationElement.setAttribute(QStringLiteral("color"), color);
0222     } else if (toolType == ToolGeometricalShape) {
0223         Okular::GeomAnnotation *ga = static_cast<Okular::GeomAnnotation *>(m_stubann);
0224 
0225         if (ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle) {
0226             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("ellipse"));
0227             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("GeomCircle"));
0228         } else {
0229             toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("rectangle"));
0230             annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("GeomSquare"));
0231         }
0232 
0233         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PickPoint"));
0234         engineElement.setAttribute(QStringLiteral("color"), color);
0235         engineElement.setAttribute(QStringLiteral("block"), QStringLiteral("true"));
0236         annotationElement.setAttribute(QStringLiteral("color"), color);
0237         annotationElement.setAttribute(QStringLiteral("width"), width);
0238 
0239         if (ga->geometricalInnerColor().isValid()) {
0240             annotationElement.setAttribute(QStringLiteral("innerColor"), ga->geometricalInnerColor().name());
0241         }
0242     } else if (toolType == ToolStamp) {
0243         Okular::StampAnnotation *sa = static_cast<Okular::StampAnnotation *>(m_stubann);
0244         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("stamp"));
0245         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PickPoint"));
0246         engineElement.setAttribute(QStringLiteral("hoverIcon"), sa->stampIconName());
0247         engineElement.setAttribute(QStringLiteral("size"), QStringLiteral("64"));
0248         engineElement.setAttribute(QStringLiteral("block"), QStringLiteral("true"));
0249         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Stamp"));
0250         annotationElement.setAttribute(QStringLiteral("icon"), sa->stampIconName());
0251     } else if (toolType == ToolTypewriter) {
0252         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0253         const QString textColor = ta->textColor().name();
0254         toolElement.setAttribute(QStringLiteral("type"), QStringLiteral("typewriter"));
0255         engineElement.setAttribute(QStringLiteral("type"), QStringLiteral("PickPoint"));
0256         engineElement.setAttribute(QStringLiteral("block"), QStringLiteral("true"));
0257         annotationElement.setAttribute(QStringLiteral("type"), QStringLiteral("Typewriter"));
0258         annotationElement.setAttribute(QStringLiteral("color"), color);
0259         annotationElement.setAttribute(QStringLiteral("textColor"), textColor);
0260         annotationElement.setAttribute(QStringLiteral("width"), width);
0261         if (ta->textFont() != QApplication::font()) {
0262             annotationElement.setAttribute(QStringLiteral("font"), ta->textFont().toString());
0263         }
0264     }
0265 
0266     if (opacity != QStringLiteral("1")) {
0267         annotationElement.setAttribute(QStringLiteral("opacity"), opacity);
0268     }
0269 
0270     return doc;
0271 }
0272 
0273 void EditAnnotToolDialog::createStubAnnotation()
0274 {
0275     const ToolType toolType = m_type->itemData(m_type->currentIndex()).value<ToolType>();
0276 
0277     // Delete previous stub annotation, if any
0278     delete m_stubann;
0279 
0280     // Create stub annotation
0281     if (toolType == ToolNoteLinked) {
0282         Okular::TextAnnotation *ta = new Okular::TextAnnotation();
0283         ta->setTextType(Okular::TextAnnotation::Linked);
0284         ta->setTextIcon(QStringLiteral("Note"));
0285         ta->style().setColor(Qt::yellow);
0286         m_stubann = ta;
0287     } else if (toolType == ToolNoteInline) {
0288         Okular::TextAnnotation *ta = new Okular::TextAnnotation();
0289         ta->setTextType(Okular::TextAnnotation::InPlace);
0290         ta->style().setWidth(1.0);
0291         ta->style().setColor(Qt::yellow);
0292         m_stubann = ta;
0293     } else if (toolType == ToolInk) {
0294         m_stubann = new Okular::InkAnnotation();
0295         m_stubann->style().setWidth(2.0);
0296         m_stubann->style().setColor(Qt::green);
0297     } else if (toolType == ToolStraightLine) {
0298         Okular::LineAnnotation *la = new Okular::LineAnnotation();
0299         la->setLinePoints({Okular::NormalizedPoint(0, 0), Okular::NormalizedPoint(1, 0)});
0300         la->style().setColor(QColor(0xff, 0xe0, 0x00));
0301         m_stubann = la;
0302     } else if (toolType == ToolPolygon) {
0303         Okular::LineAnnotation *la = new Okular::LineAnnotation();
0304         la->setLinePoints({Okular::NormalizedPoint(0, 0), Okular::NormalizedPoint(1, 0), Okular::NormalizedPoint(1, 1)});
0305         la->setLineClosed(true);
0306         la->style().setColor(QColor(0x00, 0x7e, 0xee));
0307         m_stubann = la;
0308     } else if (toolType == ToolTextMarkup) {
0309         m_stubann = new Okular::HighlightAnnotation();
0310         m_stubann->style().setColor(Qt::yellow);
0311     } else if (toolType == ToolGeometricalShape) {
0312         Okular::GeomAnnotation *ga = new Okular::GeomAnnotation();
0313         ga->setGeometricalType(Okular::GeomAnnotation::InscribedCircle);
0314         ga->style().setWidth(5.0);
0315         ga->style().setColor(Qt::cyan);
0316         m_stubann = ga;
0317     } else if (toolType == ToolStamp) {
0318         Okular::StampAnnotation *sa = new Okular::StampAnnotation();
0319         sa->setStampIconName(QStringLiteral("okular"));
0320         m_stubann = sa;
0321     } else if (toolType == ToolTypewriter) {
0322         Okular::TextAnnotation *ta = new Okular::TextAnnotation();
0323         ta->setTextType(Okular::TextAnnotation::InPlace);
0324         ta->setInplaceIntent(Okular::TextAnnotation::TypeWriter);
0325         ta->style().setWidth(0.0);
0326         ta->style().setColor(QColor(255, 255, 255, 0));
0327         ta->setTextColor(Qt::black);
0328         m_stubann = ta;
0329     }
0330 }
0331 
0332 void EditAnnotToolDialog::rebuildAppearanceBox()
0333 {
0334     // Remove previous widget (if any)
0335     if (m_annotationWidget) {
0336         delete m_annotationWidget->appearanceWidget();
0337         delete m_annotationWidget;
0338     }
0339 
0340     m_annotationWidget = AnnotationWidgetFactory::widgetFor(m_stubann);
0341     m_annotationWidget->setAnnotTypeEditable(!m_builtinTool);
0342     m_appearanceBox->layout()->addWidget(m_annotationWidget->appearanceWidget());
0343 
0344     connect(m_annotationWidget, &AnnotationWidget::dataChanged, this, &EditAnnotToolDialog::slotDataChanged);
0345 }
0346 
0347 void EditAnnotToolDialog::updateDefaultNameAndIcon()
0348 {
0349     QDomDocument doc = toolXml();
0350     QDomElement toolElement = doc.documentElement();
0351     m_name->setPlaceholderText(PageViewAnnotator::defaultToolName(toolElement));
0352     m_toolIcon->setPixmap(PageViewAnnotator::makeToolPixmap(toolElement));
0353 }
0354 
0355 void EditAnnotToolDialog::setToolType(ToolType newType)
0356 {
0357     int idx = -1;
0358 
0359     for (int i = 0; idx == -1 && i < m_type->count(); ++i) {
0360         if (m_type->itemData(i).value<ToolType>() == newType) {
0361             idx = i;
0362         }
0363     }
0364 
0365     // The following call also results in createStubAnnotation being called
0366     m_type->setCurrentIndex(idx);
0367 }
0368 
0369 void EditAnnotToolDialog::loadTool(const QDomElement &toolElement)
0370 {
0371     const QDomElement engineElement = toolElement.elementsByTagName(QStringLiteral("engine")).item(0).toElement();
0372     const QDomElement annotationElement = engineElement.elementsByTagName(QStringLiteral("annotation")).item(0).toElement();
0373     const QString annotType = toolElement.attribute(QStringLiteral("type"));
0374 
0375     if (annotType == QLatin1String("ellipse")) {
0376         setToolType(ToolGeometricalShape);
0377         Okular::GeomAnnotation *ga = static_cast<Okular::GeomAnnotation *>(m_stubann);
0378         ga->setGeometricalType(Okular::GeomAnnotation::InscribedCircle);
0379         if (annotationElement.hasAttribute(QStringLiteral("innerColor"))) {
0380             ga->setGeometricalInnerColor(QColor(annotationElement.attribute(QStringLiteral("innerColor"))));
0381         }
0382     } else if (annotType == QLatin1String("highlight")) {
0383         setToolType(ToolTextMarkup);
0384         Okular::HighlightAnnotation *ha = static_cast<Okular::HighlightAnnotation *>(m_stubann);
0385         ha->setHighlightType(Okular::HighlightAnnotation::Highlight);
0386     } else if (annotType == QLatin1String("ink")) {
0387         setToolType(ToolInk);
0388     } else if (annotType == QLatin1String("note-inline")) {
0389         setToolType(ToolNoteInline);
0390         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0391         if (annotationElement.hasAttribute(QStringLiteral("align"))) {
0392             ta->setInplaceAlignment(annotationElement.attribute(QStringLiteral("align")).toInt());
0393         }
0394         if (annotationElement.hasAttribute(QStringLiteral("font"))) {
0395             QFont f;
0396             f.fromString(annotationElement.attribute(QStringLiteral("font")));
0397             ta->setTextFont(f);
0398         }
0399     } else if (annotType == QLatin1String("note-linked")) {
0400         setToolType(ToolNoteLinked);
0401         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0402         ta->setTextIcon(annotationElement.attribute(QStringLiteral("icon")));
0403     } else if (annotType == QLatin1String("polygon")) {
0404         setToolType(ToolPolygon);
0405         Okular::LineAnnotation *la = static_cast<Okular::LineAnnotation *>(m_stubann);
0406         if (annotationElement.hasAttribute(QStringLiteral("innerColor"))) {
0407             la->setLineInnerColor(QColor(annotationElement.attribute(QStringLiteral("innerColor"))));
0408         }
0409     } else if (annotType == QLatin1String("rectangle")) {
0410         setToolType(ToolGeometricalShape);
0411         Okular::GeomAnnotation *ga = static_cast<Okular::GeomAnnotation *>(m_stubann);
0412         ga->setGeometricalType(Okular::GeomAnnotation::InscribedSquare);
0413         if (annotationElement.hasAttribute(QStringLiteral("innerColor"))) {
0414             ga->setGeometricalInnerColor(QColor(annotationElement.attribute(QStringLiteral("innerColor"))));
0415         }
0416     } else if (annotType == QLatin1String("squiggly")) {
0417         setToolType(ToolTextMarkup);
0418         Okular::HighlightAnnotation *ha = static_cast<Okular::HighlightAnnotation *>(m_stubann);
0419         ha->setHighlightType(Okular::HighlightAnnotation::Squiggly);
0420     } else if (annotType == QLatin1String("stamp")) {
0421         setToolType(ToolStamp);
0422         Okular::StampAnnotation *sa = static_cast<Okular::StampAnnotation *>(m_stubann);
0423         sa->setStampIconName(annotationElement.attribute(QStringLiteral("icon")));
0424     } else if (annotType == QLatin1String("straight-line")) {
0425         setToolType(ToolStraightLine);
0426         Okular::LineAnnotation *la = static_cast<Okular::LineAnnotation *>(m_stubann);
0427         if (annotationElement.hasAttribute(QStringLiteral("leadFwd"))) {
0428             la->setLineLeadingForwardPoint(annotationElement.attribute(QStringLiteral("leadFwd")).toDouble());
0429         }
0430         if (annotationElement.hasAttribute(QStringLiteral("leadBack"))) {
0431             la->setLineLeadingBackwardPoint(annotationElement.attribute(QStringLiteral("leadBack")).toDouble());
0432         }
0433         if (annotationElement.hasAttribute(QStringLiteral("startStyle"))) {
0434             la->setLineStartStyle((Okular::LineAnnotation::TermStyle)annotationElement.attribute(QStringLiteral("startStyle")).toInt());
0435         }
0436         if (annotationElement.hasAttribute(QStringLiteral("endStyle"))) {
0437             la->setLineEndStyle((Okular::LineAnnotation::TermStyle)annotationElement.attribute(QStringLiteral("endStyle")).toInt());
0438         }
0439     } else if (annotType == QLatin1String("strikeout")) {
0440         setToolType(ToolTextMarkup);
0441         Okular::HighlightAnnotation *ha = static_cast<Okular::HighlightAnnotation *>(m_stubann);
0442         ha->setHighlightType(Okular::HighlightAnnotation::StrikeOut);
0443     } else if (annotType == QLatin1String("underline")) {
0444         setToolType(ToolTextMarkup);
0445         Okular::HighlightAnnotation *ha = static_cast<Okular::HighlightAnnotation *>(m_stubann);
0446         ha->setHighlightType(Okular::HighlightAnnotation::Underline);
0447     } else if (annotType == QLatin1String("typewriter")) {
0448         setToolType(ToolTypewriter);
0449         Okular::TextAnnotation *ta = static_cast<Okular::TextAnnotation *>(m_stubann);
0450         if (annotationElement.hasAttribute(QStringLiteral("font"))) {
0451             QFont f;
0452             f.fromString(annotationElement.attribute(QStringLiteral("font")));
0453             ta->setTextFont(f);
0454         }
0455         if (annotationElement.hasAttribute(QStringLiteral("textColor"))) {
0456             ta->setTextColor(QColor(annotationElement.attribute(QStringLiteral("textColor"))));
0457         }
0458     }
0459 
0460     // Common properties
0461     if (annotationElement.hasAttribute(QStringLiteral("color"))) {
0462         m_stubann->style().setColor(QColor(annotationElement.attribute(QStringLiteral("color"))));
0463     }
0464     if (annotationElement.hasAttribute(QStringLiteral("opacity"))) {
0465         m_stubann->style().setOpacity(annotationElement.attribute(QStringLiteral("opacity")).toDouble());
0466     }
0467     if (annotationElement.hasAttribute(QStringLiteral("width"))) {
0468         m_stubann->style().setWidth(annotationElement.attribute(QStringLiteral("width")).toDouble());
0469     }
0470 
0471     if (toolElement.hasAttribute(QStringLiteral("name"))) {
0472         m_name->setText(toolElement.attribute(QStringLiteral("name")));
0473     }
0474 }
0475 
0476 void EditAnnotToolDialog::slotTypeChanged()
0477 {
0478     createStubAnnotation();
0479     rebuildAppearanceBox();
0480     updateDefaultNameAndIcon();
0481 }
0482 
0483 void EditAnnotToolDialog::slotDataChanged()
0484 {
0485     // Mirror changes back in the stub annotation
0486     m_annotationWidget->applyChanges();
0487 
0488     updateDefaultNameAndIcon();
0489 }