Commit 0b05d7ce authored by Simone Gaiarin's avatar Simone Gaiarin Committed by Nate Graham
Browse files

Overhaul annotations UX

Create a new new annotation toolbar to replace the current one as discussed in the task T8076.
Fixes:
BUG: 386578
BUG: 374728
BUG: 352310
BUG: 330518
BUG: 341914
BUG: 157289
BUG: 358057
BUG: 412767
BUG: 413595
BUG: 420462
FIXED-IN: 1.11.0

Test Plan
Before testing this revision
Delete or Temporary move aside the following files:

~/.config/okularpartrc
~/.config/okularrc
~/.local/share/kxmlgui5/okular/part.rc
~/.local/share/kxmlgui5/okular/shell.rc

Nomenclature
Actions in the main toolbar:

Quick annotations
Actions in the annotation toolbar:

Annotation actions Highlighter, Underline, Squiggle, Strike out, Typewriter,
Inline note, Popup note, Freehand line, Arrow, Straight line, Rectangle, Ellipse,
Polygon, Stamp

Annotation config actions Line width, Color, Inner color, Opacity, Font, Annotation settings

Other actions Add to Quick Annotations, Pin

Autotests

 First run: annotation toolbar is not visible

 Selecting Tools > Annotations shows the annotation toolbar (below the ma...
parent daad6c9f
Pipeline #22469 passed with stage
in 13 minutes and 19 seconds
......@@ -401,6 +401,7 @@ if(BUILD_DESKTOP)
part.cpp
extensions.cpp
ui/embeddedfilesdialog.cpp
ui/annotationactionhandler.cpp
ui/annotwindow.cpp
ui/annotationmodel.cpp
ui/annotationpopup.cpp
......@@ -504,7 +505,7 @@ install(TARGETS okularpart DESTINATION ${KDE_INSTALL_PLUGINDIR})
########### install files ###############
install(FILES okular.upd DESTINATION ${KDE_INSTALL_DATADIR}/kconf_update)
install(FILES okular.upd DESTINATION ${KDE_INSTALL_KCONFUPDATEDIR})
install( FILES okular_part.desktop DESTINATION ${KDE_INSTALL_KSERVICES5DIR} )
install( FILES part.rc part-viewermode.rc DESTINATION ${KDE_INSTALL_KXMLGUI5DIR}/okular )
......
......@@ -89,6 +89,13 @@ if(KF5Activities_FOUND AND BUILD_DESKTOP)
target_compile_definitions(mainshelltest PRIVATE OKULAR_BINARY="$<TARGET_FILE:okular>")
endif()
if(BUILD_DESKTOP)
ecm_add_test(annotationtoolbartest.cpp ../shell/okular_main.cpp ../shell/shellutils.cpp ../shell/shell.cpp
TEST_NAME "annotationtoolbartest"
LINK_LIBRARIES Qt5::Test okularpart
)
endif()
ecm_add_test(generatorstest.cpp
TEST_NAME "generatorstest"
LINK_LIBRARIES Qt5::Test KF5::CoreAddons okularcore
......
/***************************************************************************
* Copyright (C) 2020 by Simone Gaiarin <simgunz@gmail.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
// clazy:excludeall=qstring-allocations
#include <QtTest>
#include <QWidget>
#include <QTabBar>
#include <QTabWidget>
#include <QToolBar>
#include <KActionCollection>
#include "../shell/okular_main.h"
#include "../shell/shell.h"
#include "../shell/shellutils.h"
#include "../core/page.h"
#include "../ui/pageview.h"
#include "../part.h"
#include "../settings.h"
namespace Okular {
class PartTest
{
public:
Okular::Document *partDocument(Okular::Part *part) const {
return part->m_document;
}
PageView *pageView(Okular::Part *part) const {
return part->m_pageView;
}
};
}
class AnnotationToolBarTest : public QObject, public Okular::PartTest
{
Q_OBJECT
public:
static void initMain();
static QTabWidget* tabWidget(Shell *s)
{
return s->m_tabWidget;
}
private slots:
void initTestCase();
void init();
void cleanup();
void testAnnotationToolBar();
void testAnnotationToolBar_data();
void testAnnotationToolBarActionsEnabledState();
void testAnnotationToolBarActionsEnabledState_data();
void testAnnotationToolBarConfigActionsEnabledState();
void testAnnotationToolBarConfigActionsEnabledState_data();
private:
bool simulateAddPopupAnnotation(Okular::Part * part, int mouseX, int mouseY);
};
Shell *findShell(Shell *ignore = nullptr)
{
const QWidgetList wList = QApplication::topLevelWidgets();
for (QWidget *widget : wList )
{
Shell *s = qobject_cast<Shell*>(widget);
if (s && s != ignore)
return s;
}
return nullptr;
}
void AnnotationToolBarTest::initMain()
{
// Ensure consistent configs/caches and Default UI
QTemporaryDir homeDir;
Q_ASSERT(homeDir.isValid());
QByteArray homePath = QFile::encodeName(homeDir.path());
qputenv("USERPROFILE", homePath);
qputenv("HOME", homePath);
qputenv("XDG_DATA_HOME", homePath + "/.local");
qputenv("XDG_CONFIG_HOME", homePath + "/.kde-unit-test/xdg/config");
}
void AnnotationToolBarTest::initTestCase()
{
QStandardPaths::setTestModeEnabled(true);
// Don't pollute people's okular settings
Okular::Settings::instance( QStringLiteral("annotationtoolbartest") );
}
void AnnotationToolBarTest::init()
{
// Default settings for every test
Okular::Settings::self()->setDefaults();
}
void AnnotationToolBarTest::cleanup()
{
Shell *s;
while ((s = findShell()))
{
delete s;
}
}
bool AnnotationToolBarTest::simulateAddPopupAnnotation(Okular::Part * part, int mouseX, int mouseY)
{
int annotationCount = partDocument(part)->page( 0 )->annotations().size();
QTest::mouseMove(pageView(part)->viewport(), QPoint(mouseX, mouseY));
QTest::mouseClick(pageView(part)->viewport(), Qt::LeftButton, Qt::NoModifier, QPoint(mouseX, mouseY));
bool annotationAdded = partDocument(part)->page( 0 )->annotations().size() == annotationCount + 1;
return annotationAdded;
}
void AnnotationToolBarTest::testAnnotationToolBar()
{
// Using tabs we test that the annotation toolbar works on each Okular::Part
Okular::Settings::self()->setShellOpenFileInTabs(true);
const QStringList paths = { QStringLiteral(KDESRCDIR "data/file1.pdf"),
QStringLiteral(KDESRCDIR "data/file2.pdf") };
QString serializedOptions = ShellUtils::serializeOptions(false, false, false, false, false, QString(), QString());
Okular::Status status = Okular::main(paths, serializedOptions);
QCOMPARE(status, Okular::Success);
Shell *s = findShell();
QVERIFY(s);
QVERIFY(QTest::qWaitForWindowExposed(s));
QFETCH(int, tabIndex);
s->m_tabWidget->tabBar()->setCurrentIndex(tabIndex);
Okular::Part *part = dynamic_cast<Okular::Part*>(s->m_tabs[tabIndex].part);
QVERIFY(part);
QToolBar *annToolBar = s->findChild<QToolBar*>(QStringLiteral("annotationToolBar"));
QVERIFY(annToolBar);
// Check config action default enabled states
QAction *aQuickTools = part->actionCollection()->action(QStringLiteral("annotation_favorites"));
QAction *aAddToQuickTools = part->actionCollection()->action(QStringLiteral("annotation_bookmark"));
QAction *aAdvancedSettings = part->actionCollection()->action(QStringLiteral("annotation_settings_advanced"));
QAction *aContinuousMode = part->actionCollection()->action(QStringLiteral("annotation_settings_pin"));
QVERIFY(aQuickTools->isEnabled());
QVERIFY(!aAddToQuickTools->isEnabled());
QVERIFY(!aAdvancedSettings->isEnabled());
QVERIFY(aContinuousMode->isEnabled());
// Test annotation toolbar visibility triggers
QAction *toggleAnnotationToolBar = part->actionCollection()->action(QStringLiteral("mouse_toggle_annotate"));
QAction *aHideToolBar = part->actionCollection()->action(QStringLiteral("hide_annotation_toolbar"));
QVERIFY(toggleAnnotationToolBar);
QVERIFY(aHideToolBar);
toggleAnnotationToolBar->setChecked(false);
QTRY_VERIFY(!annToolBar->isVisible());
toggleAnnotationToolBar->trigger();
QTRY_VERIFY2(annToolBar->isVisible(), "Annotation action failed to show.");
toggleAnnotationToolBar->trigger();
QTRY_VERIFY2(!annToolBar->isVisible(), "Annotation action failed to hide.");
toggleAnnotationToolBar->setChecked(true);
QTRY_VERIFY(annToolBar->isVisible());
aHideToolBar->trigger();
QTRY_VERIFY2(!annToolBar->isVisible(), "Hide toolbar action failed to hide.");
toggleAnnotationToolBar->setChecked(false);
QTRY_VERIFY(!annToolBar->isVisible());
QTest::keyClick(part->widget(), Qt::Key_1);
QTRY_VERIFY2(annToolBar->isVisible(), "ToolBar not shown when triggering annotation using shortcut.");
toggleAnnotationToolBar->setChecked(false);
QTRY_VERIFY(!annToolBar->isVisible());
QTest::keyClick(part->widget(), Qt::Key_3, Qt::AltModifier);
QTRY_VERIFY2(annToolBar->isVisible(), "ToolBar not shown when triggering quick annotation using shortcut.");
// Click an annotation action to enable it
QAction *aPopupNote = part->actionCollection()->action(QStringLiteral("annotation_popup_note"));
QVERIFY(aPopupNote);
aPopupNote->trigger();
int mouseX = 350;
int mouseY = 100;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
// Click again the same annotation action to disable it
aPopupNote->trigger();
mouseY = 150;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), false);
// Trigger the action using a shortcut
QTest::keyClick(part->widget(), Qt::Key_7);
mouseY = 200;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
// Click Esc to disable all annotations
QTest::keyClick(pageView(part), Qt::Key_Escape);
mouseY = 250;
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), false);
// Trigger the action using a quick annotation shortcut
QTest::keyClick(part->widget(), Qt::Key_6, Qt::AltModifier);
QTRY_COMPARE(Okular::Settings::mouseMode(), static_cast<int>(Okular::Settings::EnumMouseMode::Browse));
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
// Test pin/continuous mode action
QVERIFY(aContinuousMode->isEnabled());
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
aContinuousMode->trigger();
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), true);
QCOMPARE(simulateAddPopupAnnotation(part, mouseX, mouseY), false);
}
void AnnotationToolBarTest::testAnnotationToolBar_data()
{
QTest::addColumn<int>("tabIndex");
QTest::addRow("first tab") << 0;
QTest::addRow("second tab") << 1;
}
void AnnotationToolBarTest::testAnnotationToolBarActionsEnabledState()
{
QFETCH(QString, document);
const QStringList paths = { document };
QString serializedOptions = ShellUtils::serializeOptions(false, false, false, false, false, QString(), QString());
Okular::Status status = Okular::main(paths, serializedOptions);
QCOMPARE(status, Okular::Success);
Shell *s = findShell();
QVERIFY(s);
QVERIFY(QTest::qWaitForWindowExposed(s));
Okular::Part *part = s->findChild<Okular::Part*>();
QVERIFY(part);
KActionCollection *ac = part->actionCollection();
QAction *aHighlighter = ac->action(QStringLiteral("annotation_highlighter"));
QAction *aUnderline = ac->action(QStringLiteral("annotation_underline"));
QAction *aSquiggle = ac->action(QStringLiteral("annotation_squiggle"));
QAction *aStrikeout = ac->action(QStringLiteral("annotation_strike_out"));
QAction *aTypewriter = ac->action(QStringLiteral("annotation_typewriter"));
QAction *aInlineNote = ac->action(QStringLiteral("annotation_inline_note"));
QAction *aPopupNote = ac->action(QStringLiteral("annotation_popup_note"));
QAction *aFreehandLine = ac->action(QStringLiteral("annotation_freehand_line"));
QAction *aGeomShapes = ac->action(QStringLiteral("annotation_geometrical_shape"));
QAction *aStamp = ac->action(QStringLiteral("annotation_stamp"));
QFETCH(bool, aHighlighterEnabled);
QFETCH(bool, aUnderlineEnabled);
QFETCH(bool, aSquiggleEnabled);
QFETCH(bool, aStrikeoutEnabled);
QFETCH(bool, aTypewriterEnabled);
QFETCH(bool, aInlineNoteEnabled);
QFETCH(bool, aPopupNoteEnabled);
QFETCH(bool, aFreehandLineEnabled);
QFETCH(bool, aGeomShapesEnabled);
QFETCH(bool, aStampEnabled);
QCOMPARE(aHighlighter->isEnabled(), aHighlighterEnabled);
QCOMPARE(aUnderline->isEnabled(), aUnderlineEnabled);
QCOMPARE(aSquiggle->isEnabled(), aSquiggleEnabled);
QCOMPARE(aStrikeout->isEnabled(), aStrikeoutEnabled);
QCOMPARE(aTypewriter->isEnabled(), aTypewriterEnabled);
QCOMPARE(aInlineNote->isEnabled(), aInlineNoteEnabled);
QCOMPARE(aPopupNote->isEnabled(), aPopupNoteEnabled);
QCOMPARE(aFreehandLine->isEnabled(), aFreehandLineEnabled);
QCOMPARE(aGeomShapes->isEnabled(), aGeomShapesEnabled);
QCOMPARE(aStamp->isEnabled(), aStampEnabled);
}
void AnnotationToolBarTest::testAnnotationToolBarActionsEnabledState_data()
{
QTest::addColumn<QString>("document");
QTest::addColumn<bool>("aHighlighterEnabled");
QTest::addColumn<bool>("aUnderlineEnabled");
QTest::addColumn<bool>("aSquiggleEnabled");
QTest::addColumn<bool>("aStrikeoutEnabled");
QTest::addColumn<bool>("aTypewriterEnabled");
QTest::addColumn<bool>("aInlineNoteEnabled");
QTest::addColumn<bool>("aPopupNoteEnabled");
QTest::addColumn<bool>("aFreehandLineEnabled");
QTest::addColumn<bool>("aGeomShapesEnabled");
QTest::addColumn<bool>("aStampEnabled");
QTest::addRow("pdf") << QStringLiteral(KDESRCDIR "data/file1.pdf")
<< true << true << true << true << true << true << true << true << true << true;
QTest::addRow("protected-pdf") << QStringLiteral(KDESRCDIR "data/protected.pdf")
<< false << false << false << false << false << false << false << false << false << false;
QTest::addRow("image") << QStringLiteral(KDESRCDIR "data/potato.jpg")
<< false << false << false << false << true << true << true << true << true << true;
}
void AnnotationToolBarTest::testAnnotationToolBarConfigActionsEnabledState()
{
const QStringList paths = { QStringLiteral(KDESRCDIR "data/file1.pdf") };
QString serializedOptions = ShellUtils::serializeOptions(false, false, false, false, false, QString(), QString());
Okular::Status status = Okular::main(paths, serializedOptions);
QCOMPARE(status, Okular::Success);
Shell *s = findShell();
QVERIFY(s);
QVERIFY(QTest::qWaitForWindowExposed(s));
Okular::Part *part = s->findChild<Okular::Part*>();
QVERIFY(part);
KActionCollection *ac = part->actionCollection();
QAction *aWidth = ac->action(QStringLiteral("annotation_settings_width"));
QAction *aColor = ac->action(QStringLiteral("annotation_settings_color"));
QAction *aInnerColor = ac->action(QStringLiteral("annotation_settings_inner_color"));
QAction *aOpacity = ac->action(QStringLiteral("annotation_settings_opacity"));
QAction *aFont = ac->action(QStringLiteral("annotation_settings_font"));
QFETCH(QString, annotationActionName);
QFETCH(bool, widthEnabled);
QFETCH(bool, colorEnabled);
QFETCH(bool, innerColorEnabled);
QFETCH(bool, opacityEnabled);
QFETCH(bool, fontEnabled);
QAction *annotationAction = ac->action(annotationActionName);
annotationAction->trigger();
QCOMPARE(aWidth->isEnabled(), widthEnabled);
QCOMPARE(aColor->isEnabled(), colorEnabled);
QCOMPARE(aInnerColor->isEnabled(), innerColorEnabled);
QCOMPARE(aOpacity->isEnabled(), opacityEnabled);
QCOMPARE(aFont->isEnabled(), fontEnabled);
}
void AnnotationToolBarTest::testAnnotationToolBarConfigActionsEnabledState_data()
{
QTest::addColumn<QString>("annotationActionName");
QTest::addColumn<bool>("widthEnabled");
QTest::addColumn<bool>("colorEnabled");
QTest::addColumn<bool>("innerColorEnabled");
QTest::addColumn<bool>("opacityEnabled");
QTest::addColumn<bool>("fontEnabled");
QTest::addRow("annotation_highlighter") << QStringLiteral("annotation_highlighter")
<< false << true << false << true << false;
QTest::addRow("annotation_underline") << QStringLiteral("annotation_underline")
<< false << true << false << true << false;
QTest::addRow("annotation_squiggle") << QStringLiteral("annotation_squiggle")
<< false << true << false << true << false;
QTest::addRow("annotation_strike_out") << QStringLiteral("annotation_strike_out")
<< false << true << false << true << false;
QTest::addRow("annotation_typewriter") << QStringLiteral("annotation_typewriter")
<< false << true << false << true << true;
QTest::addRow("annotation_inline_note") << QStringLiteral("annotation_inline_note")
<< false << true << false << true << true;
QTest::addRow("annotation_popup_note") << QStringLiteral("annotation_popup_note")
<< false << true << false << true << false;
QTest::addRow("annotation_freehand_line") << QStringLiteral("annotation_freehand_line")
<< true << true << false << true << false;
QTest::addRow("annotation_line") << QStringLiteral("annotation_straight_line")
<< true << true << false << true << false;
QTest::addRow("annotation_rectangle") << QStringLiteral("annotation_rectangle")
<< true << true << true << true << false;
}
QTEST_MAIN( AnnotationToolBarTest )
#include "annotationtoolbartest.moc"
......@@ -311,7 +311,7 @@ void PartTest::testClickInternalLink()
const int height = part.m_pageView->verticalScrollBar()->maximum() +
part.m_pageView->viewport()->height();
QMetaObject::invokeMethod(part.m_pageView, "slotSetMouseNormal");
QMetaObject::invokeMethod(part.m_pageView, "slotMouseNormalToggled", Q_ARG(bool, true));
QCOMPARE(part.m_document->currentPage(), 0u);
QTest::mouseMove(part.m_pageView->viewport(), QPoint(width * 0.17, height * 0.05));
......@@ -1374,7 +1374,7 @@ void PartTest::test388288()
part.widget()->show();
QVERIFY(QTest::qWaitForWindowExposed(part.widget()));
QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator", Q_ARG( bool, true ));
QMetaObject::invokeMethod(part.m_pageView, "slotMouseNormalToggled", Q_ARG(bool, true));
auto annot = new Okular::HighlightAnnotation();
annot->setHighlightType( Okular::HighlightAnnotation::Highlight );
......@@ -1560,7 +1560,7 @@ void PartTest::testAnnotWindow()
part.m_document->setViewportPage(0);
QMetaObject::invokeMethod(part.m_pageView, "slotSetMouseNormal");
QMetaObject::invokeMethod(part.m_pageView, "slotMouseNormalToggled", Q_ARG(bool, true));
QCOMPARE(part.m_document->currentPage(), 0u);
......@@ -1791,24 +1791,17 @@ void PartTest::testTypewriterAnnotTool()
QVERIFY(QTest::qWaitForWindowExposed(part.widget()));
const int width = part.m_pageView->horizontalScrollBar()->maximum() +
part.m_pageView->viewport()->width();
part.m_pageView->viewport()->width();
const int height = part.m_pageView->verticalScrollBar()->maximum() +
part.m_pageView->viewport()->height();
part.m_pageView->viewport()->height();
part.m_document->setViewportPage(0);
QMetaObject::invokeMethod(part.m_pageView, "slotToggleAnnotator", Q_ARG( bool, true ));
// Find the button for the TypeWriter annotation
QList<QToolButton *> toolbuttonList = part.m_pageView->findChildren<QToolButton *>();
auto it = std::find_if( toolbuttonList.begin(),
toolbuttonList.end(),
[](const QToolButton * x) { return x->toolTip().contains("Typewriter"); } );
QVERIFY(it != toolbuttonList.end());
QToolButton* typewriterButton = *it;
// Find the TypeWriter annotation
QAction * typeWriterAction = part.actionCollection()->action( QStringLiteral("annotation_typewriter") );
QVERIFY( typeWriterAction );
typewriterButton->click();
typeWriterAction->trigger();
QTest::qWait(1000); // Wait for the "add new note" dialog to appear
TestingUtils::CloseDialogHelper closeDialogHelper( QDialogButtonBox::Ok );
......
......@@ -20,9 +20,9 @@ DlgAnnotations::DlgAnnotations( QWidget * parent )
Ui_DlgAnnotationsBase dlg;
dlg.setupUi( this );
WidgetAnnotTools * kcfg_AnnotationTools = new WidgetAnnotTools( dlg.annotToolsGroup );
dlg.annotToolsPlaceholder->addWidget( kcfg_AnnotationTools );
kcfg_AnnotationTools->setObjectName( QStringLiteral("kcfg_AnnotationTools") );
WidgetAnnotTools * kcfg_QuickAnnotationTools = new WidgetAnnotTools( dlg.annotToolsGroup );
dlg.annotToolsPlaceholder->addWidget( kcfg_QuickAnnotationTools );
kcfg_QuickAnnotationTools->setObjectName( QStringLiteral("kcfg_QuickAnnotationTools") );
KConfigDialogManager::changedMap()->insert( QStringLiteral("WidgetAnnotTools") , SIGNAL(changed()) );
}
......@@ -84,7 +84,7 @@
<item>
<widget class="QGroupBox" name="annotToolsGroup">
<property name="title">
<string>Annotation tools</string>
<string>Quick annotation tools</string>
</property>
<layout class="QVBoxLayout" name="annotToolsPlaceholder" />
</widget>
......
......@@ -34,9 +34,11 @@
#include "ui/pageviewannotator.h"
EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState )
EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState, bool builtinTool )
: QDialog( parent ), m_stubann( nullptr ), m_annotationWidget( nullptr )
{
m_builtinTool = builtinTool;
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
QVBoxLayout *mainLayout = new QVBoxLayout;
setLayout(mainLayout);
......@@ -54,8 +56,8 @@ EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &in
mainLayout->addWidget(widget);
mainLayout->addWidget(buttonBox);
m_name = new KLineEdit( widget );
m_name->setReadOnly( m_builtinTool );
mainLayout->addWidget(m_name);
tmplabel = new QLabel( i18n( "&Name:" ), widget );
mainLayout->addWidget(tmplabel);
......@@ -64,11 +66,13 @@ EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &in
widgetLayout->addWidget( m_name, 0, 1 );
m_type = new KComboBox( false, widget );
m_type->setVisible( !m_builtinTool );
mainLayout->addWidget(m_type);
connect(m_type, static_cast<void (KComboBox::*)(int)>(&KComboBox::currentIndexChanged), this, &EditAnnotToolDialog::slotTypeChanged);
tmplabel = new QLabel( i18n( "&Type:" ), widget );
mainLayout->addWidget(tmplabel);
tmplabel->setBuddy( m_type );
tmplabel->setVisible( !m_builtinTool );
widgetLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
widgetLayout->addWidget( m_type, 1, 1 );
......@@ -381,6 +385,7 @@ void EditAnnotToolDialog::rebuildAppearanceBox()
}
m_annotationWidget = AnnotationWidgetFactory::widgetFor( m_stubann );
m_annotationWidget->setAnnotTypeEditable( !m_builtinTool );
m_appearanceBox->layout()->addWidget( m_annotationWidget->appearanceWidget() );
connect(m_annotationWidget, &AnnotationWidget::dataChanged, this, &EditAnnotToolDialog::slotDataChanged);
......
......@@ -43,7 +43,9 @@ class EditAnnotToolDialog : public QDialog
ToolTypewriter
};
explicit EditAnnotToolDialog( QWidget *parent = nullptr, const QDomElement &initialState = QDomElement() );
explicit EditAnnotToolDialog( QWidget *parent = nullptr,
const QDomElement &initialState = QDomElement(),
bool builtinTool = false );
~EditAnnotToolDialog() override;
QString name() const;
QDomDocument toolXml() const;
......@@ -63,6 +65,8 @@ class EditAnnotToolDialog : public QDialog
Okular::Annotation *m_stubann;
AnnotationWidget *m_annotationWidget;
bool m_builtinTool;
private Q_SLOTS:
void slotTypeChanged();
void slotDataChanged();
......
......@@ -117,6 +117,47 @@
</code>
<default code="true">annotationTools</default>
</entry>
<entry key="QuickAnnotationTools" type="StringList">
<code>
QStringList quickAnnotationTools;
// load the default tool list from the 'xml tools definition' file
QFile quickAnnFile( QStandardPaths::locate(QStandardPaths::GenericDataLocation, "okular/toolsQuick.xml") );
if ( quickAnnFile.exists() &amp;&amp; quickAnnFile.open( QIODevice::ReadOnly ) )
{
QDomDocument doc;
if ( doc.setContent( &amp;quickAnnFile ) )
{
QDomElement toolsDefinition = doc.elementsByTagName("quickAnnotatingTools").item( 0 ).toElement();
// create the quickAnnotationTools list from the XML dom tree
QDomNode toolDescription = toolsDefinition.firstChild();
while ( toolDescription.isElement() )
{
QDomElement toolElement = toolDescription.toElement();
if ( toolElement.tagName() == "tool" )
{
QDomDocument temp;
temp.appendChild( temp.importNode( toolElement, true) );
// add each &lt;tool&gt;...&lt;/tool&gt; as XML string
quickAnnotationTools &lt;&lt; temp.toString(-1);
}
toolDescription = toolDescription.nextSibling();
}
}
else
{
qWarning() &lt;&lt; "QuickAnnotatingTools XML file seems to be damaged";
}
}
else