summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Koenig <tokoe@kde.org>2015-08-22 14:00:04 (GMT)
committerAlbert Astals Cid <aacid@kde.org>2015-08-22 20:17:40 (GMT)
commit81f80ac3a4c7211fb0a8cd89dc8da27f6e47780e (patch)
treebde17fc9772748567ab6672e341a7e44a4c294e9
parent8b603c174dc288dcd83e19afb075853e459a82a7 (diff)
Implement drawing quick selection tool for presentation mode
REVIEW: 124687
-rw-r--r--CMakeLists.txt18
-rw-r--r--conf/autotests/CMakeLists.txt18
-rw-r--r--conf/autotests/editdrawingtooldialogtest.cpp49
-rw-r--r--conf/autotests/editdrawingtooldialogtest.h26
-rw-r--r--conf/dlgpresentation.cpp9
-rw-r--r--conf/dlgpresentationbase.ui231
-rw-r--r--conf/editannottooldialog.cpp491
-rw-r--r--conf/editannottooldialog.h73
-rw-r--r--conf/editdrawingtooldialog.cpp122
-rw-r--r--conf/editdrawingtooldialog.h37
-rw-r--r--conf/okular.kcfg41
-rw-r--r--conf/widgetannottools.cpp571
-rw-r--r--conf/widgetannottools.h86
-rw-r--r--conf/widgetconfigurationtoolsbase.cpp104
-rw-r--r--conf/widgetconfigurationtoolsbase.h51
-rw-r--r--conf/widgetdrawingtools.cpp144
-rw-r--r--conf/widgetdrawingtools.h31
-rw-r--r--part.cpp5
-rw-r--r--ui/annotationtools.cpp19
-rw-r--r--ui/annotationtools.h3
-rw-r--r--ui/data/CMakeLists.txt1
-rw-r--r--ui/data/drawingtools.xml41
-rw-r--r--ui/drawingtoolselectaction.cpp182
-rw-r--r--ui/drawingtoolselectaction.h42
-rw-r--r--ui/presentationwidget.cpp49
-rw-r--r--ui/presentationwidget.h6
26 files changed, 1647 insertions, 803 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 697a6cc..d06690e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -81,6 +81,7 @@ add_subdirectory( ui )
add_subdirectory( shell )
add_subdirectory( generators )
add_subdirectory( autotests )
+add_subdirectory( conf/autotests )
add_subdirectory(doc)
@@ -227,9 +228,7 @@ install(FILES core/okularGenerator.desktop DESTINATION ${KDE_INSTALL_KSERVICETYP
# okularpart
-set(okularpart_SRCS
- part.cpp
- extensions.cpp
+set(okularpart_conf_SRCS
conf/preferencesdialog.cpp
conf/dlgaccessibility.cpp
conf/dlgdebug.cpp
@@ -238,7 +237,17 @@ set(okularpart_SRCS
conf/dlgannotations.cpp
conf/dlgperformance.cpp
conf/dlgpresentation.cpp
+ conf/editannottooldialog.cpp
+ conf/editdrawingtooldialog.cpp
conf/widgetannottools.cpp
+ conf/widgetconfigurationtoolsbase.cpp
+ conf/widgetdrawingtools.cpp
+)
+
+set(okularpart_SRCS
+ ${okularpart_conf_SRCS}
+ part.cpp
+ extensions.cpp
ui/embeddedfilesdialog.cpp
ui/annotwindow.cpp
ui/annotationmodel.cpp
@@ -249,6 +258,7 @@ set(okularpart_SRCS
ui/annotationwidgets.cpp
ui/bookmarklist.cpp
ui/debug_ui.cpp
+ ui/drawingtoolselectaction.cpp
ui/fileprinterpreview.cpp
ui/findbar.cpp
ui/formwidgets.cpp
@@ -294,8 +304,6 @@ ki18n_wrap_ui(okularpart_SRCS
kconfig_add_kcfg_files(okularpart_SRCS conf/settings.kcfgc )
-#qt5_add_dbus_interfaces(okularpart_SRCS ${KDE4_DBUS_INTERFACES_DIR}/org.kde.KSpeech.xml)
-
add_library(okularpart MODULE ${okularpart_SRCS})
generate_export_header(okularpart BASE_NAME okularpart)
diff --git a/conf/autotests/CMakeLists.txt b/conf/autotests/CMakeLists.txt
new file mode 100644
index 0000000..13bf498
--- /dev/null
+++ b/conf/autotests/CMakeLists.txt
@@ -0,0 +1,18 @@
+macro(add_conf_unittest _source)
+ set(_test ${_source} ../editdrawingtooldialog.cpp)
+ get_filename_component(_name ${_source} NAME_WE)
+ add_executable( ${_name} ${_test} )
+ add_test( ${_name} ${_name} )
+ ecm_mark_as_test(okular-conf-${_name})
+ target_link_libraries( ${_name}
+ Qt5::Test
+ Qt5::Widgets
+ Qt5::Xml
+ KF5::I18n
+ KF5::Completion
+ KF5::WidgetsAddons
+ )
+endmacro ()
+
+add_conf_unittest(editdrawingtooldialogtest.cpp)
+
diff --git a/conf/autotests/editdrawingtooldialogtest.cpp b/conf/autotests/editdrawingtooldialogtest.cpp
new file mode 100644
index 0000000..c5322d1
--- /dev/null
+++ b/conf/autotests/editdrawingtooldialogtest.cpp
@@ -0,0 +1,49 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#include "editdrawingtooldialogtest.h"
+#include "../editdrawingtooldialog.h"
+
+#include <KColorButton>
+#include <KLineEdit>
+
+#include <QDialogButtonBox>
+#include <QSpinBox>
+#include <QTest>
+
+EditDrawingToolDialogTest::EditDrawingToolDialogTest(QObject *parent)
+ : QObject(parent)
+{
+}
+
+
+EditDrawingToolDialogTest::~EditDrawingToolDialogTest()
+{
+}
+
+void EditDrawingToolDialogTest::shouldHaveDefaultValues()
+{
+ EditDrawingToolDialog dlg;
+
+ const QDialogButtonBox *buttonBox = dlg.findChild<QDialogButtonBox *>(QStringLiteral("buttonbox"));
+ QVERIFY(buttonBox);
+
+ const KLineEdit *name = dlg.findChild<KLineEdit *>(QStringLiteral("name"));
+ QVERIFY(name);
+
+ const KColorButton *colorButton = dlg.findChild<KColorButton *>(QStringLiteral("colorbutton"));
+ QVERIFY(colorButton);
+
+ const QSpinBox *opacity = dlg.findChild<QSpinBox *>(QStringLiteral("opacity"));
+ QVERIFY(opacity);
+
+ QVERIFY(name->text().isEmpty());
+}
+
+QTEST_MAIN(EditDrawingToolDialogTest)
diff --git a/conf/autotests/editdrawingtooldialogtest.h b/conf/autotests/editdrawingtooldialogtest.h
new file mode 100644
index 0000000..3cc6552
--- /dev/null
+++ b/conf/autotests/editdrawingtooldialogtest.h
@@ -0,0 +1,26 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef EDITDRAWINGTOOLDIALOGTEST_H
+#define EDITDRAWINGTOOLDIALOGTEST_H
+
+#include <QObject>
+
+class EditDrawingToolDialogTest : public QObject
+{
+ Q_OBJECT
+public:
+ explicit EditDrawingToolDialogTest(QObject *parent = Q_NULLPTR);
+ ~EditDrawingToolDialogTest();
+
+private Q_SLOTS:
+ void shouldHaveDefaultValues();
+};
+
+#endif // EDITDRAWINGTOOLDIALOGTEST_H
diff --git a/conf/dlgpresentation.cpp b/conf/dlgpresentation.cpp
index 35e8bcc..7d1c04c 100644
--- a/conf/dlgpresentation.cpp
+++ b/conf/dlgpresentation.cpp
@@ -10,10 +10,11 @@
#include "dlgpresentation.h"
#include "ui_dlgpresentationbase.h"
+#include "widgetdrawingtools.h"
#include <qapplication.h>
#include <qdesktopwidget.h>
-
+#include <KConfigDialogManager>
#include <KLocalizedString>
#include "settings.h"
@@ -24,6 +25,12 @@ DlgPresentation::DlgPresentation( QWidget * parent )
m_dlg = new Ui_DlgPresentationBase();
m_dlg->setupUi( this );
+ WidgetDrawingTools * kcfg_DrawingTools = new WidgetDrawingTools( m_dlg->annotationToolsGroupBox );
+ m_dlg->verticalLayout_4->addWidget( kcfg_DrawingTools );
+ kcfg_DrawingTools->setObjectName( "kcfg_DrawingTools" );
+
+ KConfigDialogManager::changedMap()->insert( "WidgetDrawingTools", SIGNAL(changed()) );
+
QStringList choices;
choices.append( i18nc( "@label:listbox The current screen, for the presentation mode", "Current Screen" ) );
choices.append( i18nc( "@label:listbox The default screen for the presentation mode", "Default Screen" ) );
diff --git a/conf/dlgpresentationbase.ui b/conf/dlgpresentationbase.ui
index caf323c..2e29743 100644
--- a/conf/dlgpresentationbase.ui
+++ b/conf/dlgpresentationbase.ui
@@ -1,51 +1,79 @@
-<ui version="4.0" >
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
<class>DlgPresentationBase</class>
- <widget class="QWidget" name="DlgPresentationBase" >
- <property name="geometry" >
+ <widget class="QWidget" name="DlgPresentationBase">
+ <property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
- <height>446</height>
+ <height>525</height>
</rect>
</property>
- <layout class="QVBoxLayout" name="verticalLayout_2" >
- <property name="margin" >
+ <layout class="QVBoxLayout" name="verticalLayout_2">
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
<number>0</number>
</property>
<item>
- <widget class="QGroupBox" name="groupBox" >
- <property name="title" >
+ <widget class="QGroupBox" name="groupBox">
+ <property name="title">
<string>Navigation</string>
</property>
- <layout class="QVBoxLayout" >
- <property name="spacing" >
+ <layout class="QVBoxLayout">
+ <property name="spacing">
<number>6</number>
</property>
- <property name="margin" >
+ <property name="leftMargin">
+ <number>9</number>
+ </property>
+ <property name="topMargin">
+ <number>9</number>
+ </property>
+ <property name="rightMargin">
+ <number>9</number>
+ </property>
+ <property name="bottomMargin">
<number>9</number>
</property>
<item>
- <layout class="QHBoxLayout" >
- <property name="spacing" >
+ <layout class="QHBoxLayout">
+ <property name="spacing">
<number>6</number>
</property>
- <property name="margin" >
+ <property name="leftMargin">
+ <number>0</number>
+ </property>
+ <property name="topMargin">
+ <number>0</number>
+ </property>
+ <property name="rightMargin">
+ <number>0</number>
+ </property>
+ <property name="bottomMargin">
<number>0</number>
</property>
<item>
- <widget class="QCheckBox" name="kcfg_SlidesAdvance" >
- <property name="text" >
+ <widget class="QCheckBox" name="kcfg_SlidesAdvance">
+ <property name="text">
<string>Advance every:</string>
</property>
</widget>
</item>
<item>
- <widget class="KPluralHandlingSpinBox" name="kcfg_SlidesAdvanceTime" >
- <property name="enabled" >
+ <widget class="KPluralHandlingSpinBox" name="kcfg_SlidesAdvanceTime">
+ <property name="enabled">
<bool>false</bool>
</property>
- <property name="value" >
+ <property name="value">
<number>5</number>
</property>
</widget>
@@ -53,8 +81,8 @@
</layout>
</item>
<item>
- <widget class="QCheckBox" name="kcfg_SlidesLoop" >
- <property name="text" >
+ <widget class="QCheckBox" name="kcfg_SlidesLoop">
+ <property name="text">
<string>Loop after last page</string>
</property>
</widget>
@@ -63,63 +91,50 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_2" >
- <property name="title" >
+ <widget class="QGroupBox" name="groupBox_2">
+ <property name="title">
<string>Appearance</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout" >
+ <layout class="QVBoxLayout" name="verticalLayout">
<item>
- <layout class="QGridLayout" name="gridLayout_3" >
- <item row="0" column="0" >
- <widget class="QLabel" name="textLabel3" >
- <property name="text" >
+ <layout class="QGridLayout" name="gridLayout_3">
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel3">
+ <property name="text">
<string>Background color:</string>
</property>
- <property name="alignment" >
+ <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="KColorButton" name="kcfg_SlidesBackgroundColor" />
+ <item row="0" column="1">
+ <widget class="KColorButton" name="kcfg_SlidesBackgroundColor"/>
</item>
- <item row="1" column="0" >
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>Pencil color:</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
- </property>
- </widget>
- </item>
- <item row="1" column="1" >
- <widget class="KColorButton" name="kcfg_SlidesPencilColor" />
- </item>
- <item row="2" column="0" >
- <widget class="QLabel" name="textLabel2" >
- <property name="text" >
+ <item row="1" column="0">
+ <widget class="QLabel" name="textLabel2">
+ <property name="text">
<string>Mouse cursor:</string>
</property>
- <property name="alignment" >
+ <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="2" column="1" >
- <widget class="QComboBox" name="kcfg_SlidesCursor" >
+ <item row="1" column="1">
+ <widget class="QComboBox" name="kcfg_SlidesCursor">
<item>
- <property name="text" >
+ <property name="text">
<string>Hidden After Delay</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Always Visible</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Always Hidden</string>
</property>
</item>
@@ -128,15 +143,15 @@
</layout>
</item>
<item>
- <widget class="QCheckBox" name="kcfg_SlidesShowProgress" >
- <property name="text" >
+ <widget class="QCheckBox" name="kcfg_SlidesShowProgress">
+ <property name="text">
<string>Show &amp;progress indicator</string>
</property>
</widget>
</item>
<item>
- <widget class="QCheckBox" name="kcfg_SlidesShowSummary" >
- <property name="text" >
+ <widget class="QCheckBox" name="kcfg_SlidesShowSummary">
+ <property name="text">
<string>Show s&amp;ummary page</string>
</property>
</widget>
@@ -145,121 +160,121 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="kcfg_SlidesTransitionsEnabled" >
- <property name="title" >
+ <widget class="QGroupBox" name="kcfg_SlidesTransitionsEnabled">
+ <property name="title">
<string>Enable transitions</string>
</property>
- <property name="checkable" >
+ <property name="checkable">
<bool>true</bool>
</property>
- <property name="checked" >
+ <property name="checked">
<bool>true</bool>
</property>
- <layout class="QGridLayout" name="gridLayout" >
- <item row="0" column="0" >
- <widget class="QLabel" name="textLabel1" >
- <property name="text" >
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0">
+ <widget class="QLabel" name="textLabel1">
+ <property name="text">
<string>Default transition:</string>
</property>
- <property name="alignment" >
+ <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QComboBox" name="kcfg_SlidesTransition" >
+ <item row="0" column="1">
+ <widget class="QComboBox" name="kcfg_SlidesTransition">
<item>
- <property name="text" >
+ <property name="text">
<string>Blinds Vertical</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Blinds Horizontal</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Box In</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Box Out</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Dissolve</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Fade</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Glitter Down</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Glitter Right</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Glitter Right-Down</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Random Transition</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Replace</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Split Horizontal In</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Split Horizontal Out</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Split Vertical In</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Split Vertical Out</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Wipe Down</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Wipe Right</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Wipe Left</string>
</property>
</item>
<item>
- <property name="text" >
+ <property name="text">
<string>Wipe Up</string>
</property>
</item>
@@ -269,46 +284,38 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_4" >
- <property name="title" >
+ <widget class="QGroupBox" name="groupBox_4">
+ <property name="title">
<string>Placement</string>
</property>
- <layout class="QGridLayout" name="gridLayout_2" >
- <item row="0" column="0" >
- <widget class="QLabel" name="label_2" >
- <property name="text" >
+ <layout class="QGridLayout" name="gridLayout_2">
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
<string>Screen:</string>
</property>
- <property name="alignment" >
+ <property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
- <item row="0" column="1" >
- <widget class="QComboBox" name="screenCombo" />
+ <item row="0" column="1">
+ <widget class="QComboBox" name="screenCombo"/>
</item>
</layout>
</widget>
</item>
<item>
- <spacer>
- <property name="orientation" >
- <enum>Qt::Vertical</enum>
+ <widget class="QGroupBox" name="annotationToolsGroupBox">
+ <property name="title">
+ <string>Drawing Tool Configuration</string>
</property>
- <property name="sizeType" >
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" stdset="0" >
- <size>
- <width>20</width>
- <height>4</height>
- </size>
- </property>
- </spacer>
+ <layout class="QVBoxLayout" name="verticalLayout_4"/>
+ </widget>
</item>
</layout>
</widget>
- <customwidgets>
+ <customwidgets>
<customwidget>
<class>KColorButton</class>
<extends>QPushButton</extends>
@@ -328,11 +335,11 @@
<receiver>kcfg_SlidesAdvanceTime</receiver>
<slot>setEnabled(bool)</slot>
<hints>
- <hint type="sourcelabel" >
+ <hint type="sourcelabel">
<x>88</x>
<y>43</y>
</hint>
- <hint type="destinationlabel" >
+ <hint type="destinationlabel">
<x>280</x>
<y>49</y>
</hint>
diff --git a/conf/editannottooldialog.cpp b/conf/editannottooldialog.cpp
new file mode 100644
index 0000000..c633baa
--- /dev/null
+++ b/conf/editannottooldialog.cpp
@@ -0,0 +1,491 @@
+
+#include "editannottooldialog.h"
+
+#include <kcolorbutton.h>
+#include <kcombobox.h>
+#include <klocalizedstring.h>
+#include <klineedit.h>
+
+#include <QApplication>
+#include <QHBoxLayout>
+#include <QVBoxLayout>
+#include <QGroupBox>
+#include <QLabel>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QPushButton>
+#include <QStackedWidget>
+#include <QtXml/QDomDocument>
+#include <QtXml/QDomElement>
+#include <KConfigGroup>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+#include "core/annotations.h"
+#include "ui/annotationwidgets.h"
+#include "ui/pageviewannotator.h"
+
+
+EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState )
+ : QDialog( parent ), m_stubann( 0 ), m_annotationWidget( 0 )
+{
+ QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ setLayout(mainLayout);
+ QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
+ okButton->setDefault(true);
+ okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
+ connect(buttonBox, &QDialogButtonBox::accepted, this, &EditAnnotToolDialog::accept);
+ connect(buttonBox, &QDialogButtonBox::rejected, this, &EditAnnotToolDialog::reject);
+ okButton->setDefault(true);
+
+ QLabel * tmplabel;
+ QWidget *widget = new QWidget( this );
+ QGridLayout * widgetLayout = new QGridLayout( widget );
+
+ mainLayout->addWidget(widget);
+ mainLayout->addWidget(buttonBox);
+
+
+ m_name = new KLineEdit( widget );
+ mainLayout->addWidget(m_name);
+ tmplabel = new QLabel( i18n( "&Name:" ), widget );
+ mainLayout->addWidget(tmplabel);
+ tmplabel->setBuddy( m_name );
+ widgetLayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
+ widgetLayout->addWidget( m_name, 0, 1 );
+
+ m_type = new KComboBox( false, widget );
+ 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 );
+ widgetLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
+ widgetLayout->addWidget( m_type, 1, 1 );
+
+ m_toolIcon = new QLabel( widget );
+ mainLayout->addWidget(m_toolIcon);
+ m_toolIcon->setAlignment( Qt::AlignRight | Qt::AlignTop );
+ m_toolIcon->setMinimumSize( 40, 32 );
+ widgetLayout->addWidget( m_toolIcon, 0, 2, 2, 1 );
+
+ m_appearanceBox = new QGroupBox( i18n( "Appearance" ), widget );
+ mainLayout->addWidget(m_appearanceBox);
+ m_appearanceBox->setLayout( new QVBoxLayout( m_appearanceBox ) );
+ widgetLayout->addWidget( m_appearanceBox, 2, 0, 1, 3 );
+
+ // Populate combobox with annotation types
+ m_type->addItem( i18n("Pop-up Note"), qVariantFromValue( ToolNoteLinked ) );
+ m_type->addItem( i18n("Inline Note"), qVariantFromValue( ToolNoteInline ) );
+ m_type->addItem( i18n("Freehand Line"), qVariantFromValue( ToolInk ) );
+ m_type->addItem( i18n("Straight Line"), qVariantFromValue( ToolStraightLine ) );
+ m_type->addItem( i18n("Polygon"), qVariantFromValue( ToolPolygon ) );
+ m_type->addItem( i18n("Text markup"), qVariantFromValue( ToolTextMarkup ) );
+ m_type->addItem( i18n("Geometrical shape"), qVariantFromValue( ToolGeometricalShape ) );
+ m_type->addItem( i18n("Stamp"), qVariantFromValue( ToolStamp ) );
+
+ createStubAnnotation();
+
+ if ( initialState.isNull() )
+ {
+ setWindowTitle( i18n("Create annotation tool") );
+ }
+ else
+ {
+ setWindowTitle( i18n("Edit annotation tool") );
+ loadTool( initialState );
+ }
+
+ rebuildAppearanceBox();
+ updateDefaultNameAndIcon();
+}
+
+EditAnnotToolDialog::~EditAnnotToolDialog()
+{
+ delete m_annotationWidget;
+}
+
+QString EditAnnotToolDialog::name() const
+{
+ return m_name->text();
+}
+
+QDomDocument EditAnnotToolDialog::toolXml() const
+{
+ const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>();
+
+ QDomDocument doc;
+ QDomElement toolElement = doc.createElement( "tool" );
+ QDomElement engineElement = doc.createElement( "engine" );
+ QDomElement annotationElement = doc.createElement( "annotation" );
+ doc.appendChild( toolElement );
+ toolElement.appendChild( engineElement );
+ engineElement.appendChild( annotationElement );
+
+ const QString color = m_stubann->style().color().name();
+ const double opacity = m_stubann->style().opacity();
+ const double width = m_stubann->style().width();
+
+ if ( toolType == ToolNoteLinked )
+ {
+ Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
+ toolElement.setAttribute( "type", "note-linked" );
+ engineElement.setAttribute( "type", "PickPoint" );
+ engineElement.setAttribute( "color", color );
+ engineElement.setAttribute( "hoverIcon", "tool-note" );
+ annotationElement.setAttribute( "type", "Text" );
+ annotationElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "icon", ta->textIcon() );
+ }
+ else if ( toolType == ToolNoteInline )
+ {
+ Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
+ toolElement.setAttribute( "type", "note-inline" );
+ engineElement.setAttribute( "type", "PickPoint" );
+ engineElement.setAttribute( "color", color );
+ engineElement.setAttribute( "hoverIcon", "tool-note-inline" );
+ engineElement.setAttribute( "block", "true" );
+ annotationElement.setAttribute( "type", "FreeText" );
+ annotationElement.setAttribute( "color", color );
+ if ( ta->inplaceAlignment() != 0 )
+ annotationElement.setAttribute( "align", ta->inplaceAlignment() );
+ if ( ta->textFont() != QApplication::font() )
+ annotationElement.setAttribute( "font", ta->textFont().toString() );
+ }
+ else if ( toolType == ToolInk )
+ {
+ toolElement.setAttribute( "type", "ink" );
+ engineElement.setAttribute( "type", "SmoothLine" );
+ engineElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "type", "Ink" );
+ annotationElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "width", width );
+ }
+ else if ( toolType == ToolStraightLine )
+ {
+ Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
+ toolElement.setAttribute( "type", "straight-line" );
+ engineElement.setAttribute( "type", "PolyLine" );
+ engineElement.setAttribute( "color", color );
+ engineElement.setAttribute( "points", "2" );
+ annotationElement.setAttribute( "type", "Line" );
+ annotationElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "width", width );
+ if ( la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0 )
+ {
+ annotationElement.setAttribute( "leadFwd", la->lineLeadingForwardPoint() );
+ annotationElement.setAttribute( "leadBack", la->lineLeadingBackwardPoint() );
+ }
+ }
+ else if ( toolType == ToolPolygon )
+ {
+ Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
+ toolElement.setAttribute( "type", "polygon" );
+ engineElement.setAttribute( "type", "PolyLine" );
+ engineElement.setAttribute( "color", color );
+ engineElement.setAttribute( "points", "-1" );
+ annotationElement.setAttribute( "type", "Line" );
+ annotationElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "width", width );
+ if ( la->lineInnerColor().isValid() )
+ {
+ annotationElement.setAttribute( "innerColor", la->lineInnerColor().name() );
+ }
+ }
+ else if ( toolType == ToolTextMarkup )
+ {
+ Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
+
+ switch ( ha->highlightType() )
+ {
+ case Okular::HighlightAnnotation::Highlight:
+ toolElement.setAttribute( "type", "highlight" );
+ annotationElement.setAttribute( "type", "Highlight" );
+ break;
+ case Okular::HighlightAnnotation::Squiggly:
+ toolElement.setAttribute( "type", "squiggly" );
+ annotationElement.setAttribute( "type", "Squiggly" );
+ break;
+ case Okular::HighlightAnnotation::Underline:
+ toolElement.setAttribute( "type", "underline" );
+ annotationElement.setAttribute( "type", "Underline" );
+ break;
+ case Okular::HighlightAnnotation::StrikeOut:
+ toolElement.setAttribute( "type", "strikeout" );
+ annotationElement.setAttribute( "type", "StrikeOut" );
+ break;
+ }
+
+ engineElement.setAttribute( "type", "TextSelector" );
+ engineElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "color", color );
+ }
+ else if ( toolType == ToolGeometricalShape )
+ {
+ Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
+
+ if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle )
+ {
+ toolElement.setAttribute( "type", "ellipse" );
+ annotationElement.setAttribute( "type", "GeomCircle" );
+ }
+ else
+ {
+ toolElement.setAttribute( "type", "rectangle" );
+ annotationElement.setAttribute( "type", "GeomSquare" );
+ }
+
+ engineElement.setAttribute( "type", "PickPoint" );
+ engineElement.setAttribute( "color", color );
+ engineElement.setAttribute( "block", "true" );
+ annotationElement.setAttribute( "color", color );
+ annotationElement.setAttribute( "width", width );
+
+ if ( ga->geometricalInnerColor().isValid() )
+ annotationElement.setAttribute( "innerColor", ga->geometricalInnerColor().name() );
+ }
+ else if ( toolType == ToolStamp )
+ {
+ Okular::StampAnnotation * sa = static_cast<Okular::StampAnnotation*>( m_stubann );
+ toolElement.setAttribute( "type", "stamp" );
+ engineElement.setAttribute( "type", "PickPoint" );
+ engineElement.setAttribute( "hoverIcon", sa->stampIconName() );
+ engineElement.setAttribute( "size", "64" );
+ engineElement.setAttribute( "block", "true" );
+ annotationElement.setAttribute( "type", "Stamp" );
+ annotationElement.setAttribute( "icon", sa->stampIconName() );
+ }
+
+ if ( opacity != 1 )
+ annotationElement.setAttribute( "opacity", opacity );
+
+ return doc;
+}
+
+void EditAnnotToolDialog::createStubAnnotation()
+{
+ const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>();
+
+ // Delete previous stub annotation, if any
+ delete m_stubann;
+
+ // Create stub annotation
+ if ( toolType == ToolNoteLinked )
+ {
+ Okular::TextAnnotation * ta = new Okular::TextAnnotation();
+ ta->setTextType( Okular::TextAnnotation::Linked );
+ ta->setTextIcon( "Note" );
+ ta->style().setColor( Qt::yellow );
+ m_stubann = ta;
+ }
+ else if ( toolType == ToolNoteInline )
+ {
+ Okular::TextAnnotation * ta = new Okular::TextAnnotation();
+ ta->setTextType( Okular::TextAnnotation::InPlace );
+ ta->style().setColor( Qt::yellow );
+ m_stubann = ta;
+ }
+ else if ( toolType == ToolInk )
+ {
+ m_stubann = new Okular::InkAnnotation();
+ m_stubann->style().setWidth( 2.0 );
+ m_stubann->style().setColor( Qt::green );
+ }
+ else if ( toolType == ToolStraightLine )
+ {
+ Okular::LineAnnotation * la = new Okular::LineAnnotation();
+ la->setLinePoints( QLinkedList<Okular::NormalizedPoint>() <<
+ Okular::NormalizedPoint(0,0) <<
+ Okular::NormalizedPoint(1,0) );
+ la->style().setColor( QColor( 0xff, 0xe0, 0x00 ) );
+ m_stubann = la;
+ }
+ else if ( toolType == ToolPolygon )
+ {
+ Okular::LineAnnotation * la = new Okular::LineAnnotation();
+ la->setLinePoints( QLinkedList<Okular::NormalizedPoint>() <<
+ Okular::NormalizedPoint(0,0) <<
+ Okular::NormalizedPoint(1,0) <<
+ Okular::NormalizedPoint(1,1) );
+ la->setLineClosed( true );
+ la->style().setColor( QColor( 0x00, 0x7e, 0xee ) );
+ m_stubann = la;
+ }
+ else if ( toolType == ToolTextMarkup )
+ {
+ m_stubann = new Okular::HighlightAnnotation();
+ m_stubann->style().setColor( Qt::yellow );
+ }
+ else if ( toolType == ToolGeometricalShape )
+ {
+ Okular::GeomAnnotation * ga = new Okular::GeomAnnotation();
+ ga->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
+ ga->style().setWidth( 5.0 );
+ ga->style().setColor( Qt::cyan );
+ m_stubann = ga;
+ }
+ else if ( toolType == ToolStamp )
+ {
+ Okular::StampAnnotation * sa = new Okular::StampAnnotation();
+ sa->setStampIconName( "okular" );
+ m_stubann = sa;
+ }
+}
+
+void EditAnnotToolDialog::rebuildAppearanceBox()
+{
+ // Remove previous widget (if any)
+ if ( m_annotationWidget )
+ {
+ delete m_annotationWidget->appearanceWidget();
+ delete m_annotationWidget;
+ }
+
+ m_annotationWidget = AnnotationWidgetFactory::widgetFor( m_stubann );
+ m_appearanceBox->layout()->addWidget( m_annotationWidget->appearanceWidget() );
+
+ connect(m_annotationWidget, &AnnotationWidget::dataChanged, this, &EditAnnotToolDialog::slotDataChanged);
+}
+
+void EditAnnotToolDialog::updateDefaultNameAndIcon()
+{
+ QDomDocument doc = toolXml();
+ QDomElement toolElement = doc.documentElement();
+ m_name->setPlaceholderText( PageViewAnnotator::defaultToolName( toolElement ) );
+ m_toolIcon->setPixmap( PageViewAnnotator::makeToolPixmap( toolElement ) );
+}
+
+void EditAnnotToolDialog::setToolType( ToolType newType )
+{
+ int idx = -1;
+
+ for ( int i = 0; idx == -1 && i < m_type->count(); ++i )
+ {
+ if ( m_type->itemData( i ).value<ToolType>() == newType )
+ idx = i;
+ }
+
+ // The following call also results in createStubAnnotation being called
+ m_type->setCurrentIndex( idx );
+}
+
+void EditAnnotToolDialog::loadTool( const QDomElement &toolElement )
+{
+ const QDomElement engineElement = toolElement.elementsByTagName( "engine" ).item( 0 ).toElement();
+ const QDomElement annotationElement = engineElement.elementsByTagName( "annotation" ).item( 0 ).toElement();
+ const QString annotType = toolElement.attribute( "type" );
+
+ if ( annotType == "ellipse" )
+ {
+ setToolType( ToolGeometricalShape );
+ Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
+ ga->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
+ if ( annotationElement.hasAttribute( "innerColor" ) )
+ ga->setGeometricalInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
+ }
+ else if ( annotType == "highlight" )
+ {
+ setToolType( ToolTextMarkup );
+ Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
+ ha->setHighlightType( Okular::HighlightAnnotation::Highlight );
+ }
+ else if ( annotType == "ink" )
+ {
+ setToolType( ToolInk );
+ }
+ else if ( annotType == "note-inline" )
+ {
+ setToolType( ToolNoteInline );
+ Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
+ if ( annotationElement.hasAttribute( "align" ) )
+ ta->setInplaceAlignment( annotationElement.attribute( "align" ).toInt() );
+ if ( annotationElement.hasAttribute( "font" ) )
+ {
+ QFont f;
+ f.fromString( annotationElement.attribute( "font" ) );
+ ta->setTextFont( f );
+ }
+ }
+ else if ( annotType == "note-linked" )
+ {
+ setToolType( ToolNoteLinked );
+ Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
+ ta->setTextIcon( annotationElement.attribute( "icon" ) );
+ }
+ else if ( annotType == "polygon" )
+ {
+ setToolType( ToolPolygon );
+ Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
+ if ( annotationElement.hasAttribute( "innerColor" ) )
+ la->setLineInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
+ }
+ else if ( annotType == "rectangle" )
+ {
+ setToolType( ToolGeometricalShape );
+ Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
+ ga->setGeometricalType( Okular::GeomAnnotation::InscribedSquare );
+ if ( annotationElement.hasAttribute( "innerColor" ) )
+ ga->setGeometricalInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
+ }
+ else if ( annotType == "squiggly" )
+ {
+ setToolType( ToolTextMarkup );
+ Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
+ ha->setHighlightType( Okular::HighlightAnnotation::Squiggly );
+ }
+ else if ( annotType == "stamp" )
+ {
+ setToolType( ToolStamp );
+ Okular::StampAnnotation * sa = static_cast<Okular::StampAnnotation*>( m_stubann );
+ sa->setStampIconName( annotationElement.attribute( "icon" ) );
+ }
+ else if ( annotType == "straight-line" )
+ {
+ setToolType( ToolStraightLine );
+ Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
+ if ( annotationElement.hasAttribute( "leadFwd" ) )
+ la->setLineLeadingForwardPoint( annotationElement.attribute( "leadFwd" ).toDouble() );
+ if ( annotationElement.hasAttribute( "leadBack" ) )
+ la->setLineLeadingBackwardPoint( annotationElement.attribute( "leadBack" ).toDouble() );
+ }
+ else if ( annotType == "strikeout" )
+ {
+ setToolType( ToolTextMarkup );
+ Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
+ ha->setHighlightType( Okular::HighlightAnnotation::StrikeOut );
+ }
+ else if ( annotType == "underline" )
+ {
+ setToolType( ToolTextMarkup );
+ Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
+ ha->setHighlightType( Okular::HighlightAnnotation::Underline );
+ }
+
+ // Common properties
+ if ( annotationElement.hasAttribute( "color" ) )
+ m_stubann->style().setColor( QColor( annotationElement.attribute( "color" ) ) );
+ if ( annotationElement.hasAttribute( "opacity" ) )
+ m_stubann->style().setOpacity( annotationElement.attribute( "opacity" ).toDouble() );
+ if ( annotationElement.hasAttribute( "width" ) )
+ m_stubann->style().setWidth( annotationElement.attribute( "width" ).toDouble() );
+
+ if ( toolElement.hasAttribute( "name" ) )
+ m_name->setText( toolElement.attribute( "name" ) );
+}
+
+void EditAnnotToolDialog::slotTypeChanged()
+{
+ createStubAnnotation();
+ rebuildAppearanceBox();
+ updateDefaultNameAndIcon();
+}
+
+void EditAnnotToolDialog::slotDataChanged()
+{
+ // Mirror changes back in the stub annotation
+ m_annotationWidget->applyChanges();
+
+ updateDefaultNameAndIcon();
+}
diff --git a/conf/editannottooldialog.h b/conf/editannottooldialog.h
new file mode 100644
index 0000000..a5aec2e
--- /dev/null
+++ b/conf/editannottooldialog.h
@@ -0,0 +1,73 @@
+/***************************************************************************
+ * Copyright (C) 2012 by Fabio D'Urso <fabiodurso@hotmail.it> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef EDITANNOTTOOLDIALOG_H
+#define EDITANNOTTOOLDIALOG_H
+
+#include <QDialog>
+#include <QDomElement>
+class KLineEdit;
+class KComboBox;
+class QLabel;
+class QListWidget;
+class QListWidgetItem;
+class QGroupBox;
+class AnnotationWidget;
+
+namespace Okular
+{
+class Annotation;
+}
+
+
+class EditAnnotToolDialog : public QDialog
+{
+ Q_OBJECT
+
+ public:
+ enum ToolType
+ {
+ ToolNoteLinked,
+ ToolNoteInline,
+ ToolInk,
+ ToolStraightLine,
+ ToolPolygon,
+ ToolTextMarkup,
+ ToolGeometricalShape,
+ ToolStamp
+ };
+
+ EditAnnotToolDialog( QWidget *parent = Q_NULLPTR, const QDomElement &initialState = QDomElement() );
+ ~EditAnnotToolDialog();
+ QString name() const;
+ QDomDocument toolXml() const;
+
+ private:
+ void createStubAnnotation();
+ void rebuildAppearanceBox();
+ void updateDefaultNameAndIcon();
+ void setToolType( ToolType newType );
+ void loadTool( const QDomElement &toolElement );
+
+ KLineEdit *m_name;
+ KComboBox *m_type;
+ QLabel *m_toolIcon;
+ QGroupBox *m_appearanceBox;
+
+ Okular::Annotation *m_stubann;
+ AnnotationWidget *m_annotationWidget;
+
+ private slots:
+ void slotTypeChanged();
+ void slotDataChanged();
+};
+
+Q_DECLARE_METATYPE( EditAnnotToolDialog::ToolType )
+
+#endif // EDITANNOTTOOLDIALOG_H
diff --git a/conf/editdrawingtooldialog.cpp b/conf/editdrawingtooldialog.cpp
new file mode 100644
index 0000000..67b522c
--- /dev/null
+++ b/conf/editdrawingtooldialog.cpp
@@ -0,0 +1,122 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#include "editdrawingtooldialog.h"
+
+#include <KColorButton>
+#include <KLocalizedString>
+
+#include <QDialogButtonBox>
+#include <QLabel>
+#include <QPushButton>
+#include <QSpinBox>
+#include <QVBoxLayout>
+
+EditDrawingToolDialog::EditDrawingToolDialog( const QDomElement &initialState, QWidget *parent )
+ : QDialog(parent)
+{
+ QDialogButtonBox *buttonBox = new QDialogButtonBox( QDialogButtonBox::Ok | QDialogButtonBox::Cancel );
+ buttonBox->setObjectName( QStringLiteral("buttonbox") );
+ QVBoxLayout *mainLayout = new QVBoxLayout;
+ setLayout(mainLayout);
+
+ QPushButton *okButton = buttonBox->button( QDialogButtonBox::Ok );
+ okButton->setDefault( true );
+ okButton->setShortcut( Qt::CTRL | Qt::Key_Return );
+ connect( buttonBox, &QDialogButtonBox::accepted, this, &EditDrawingToolDialog::accept );
+ connect( buttonBox, &QDialogButtonBox::rejected, this, &EditDrawingToolDialog::reject );
+ okButton->setDefault( true );
+
+ QWidget *widget = new QWidget( this );
+ QGridLayout * widgetLayout = new QGridLayout( widget );
+
+ mainLayout->addWidget( widget );
+ mainLayout->addWidget( buttonBox );
+
+ QLabel *tmplabel = new QLabel( i18n( "Color:" ), widget );
+ widgetLayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
+
+ m_colorBn = new KColorButton( this );
+ m_colorBn->setObjectName( QStringLiteral("colorbutton") );
+ widgetLayout->addWidget( m_colorBn, 0, 1, Qt::AlignRight );
+
+ tmplabel = new QLabel( i18n( "&Pen Width:" ), widget );
+ widgetLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
+
+ m_penWidth = new QSpinBox( widget );
+ m_penWidth->setObjectName( QStringLiteral("penWidth") );
+ m_penWidth->setRange( 0, 50 );
+ m_penWidth->setSuffix( i18nc( "Suffix for the pen width, eg '10 px'", " px" ) );
+ tmplabel->setBuddy( m_penWidth );
+ widgetLayout->addWidget( m_penWidth, 1, 1 );
+
+ tmplabel = new QLabel( i18n( "&Opacity:" ), widget );
+ widgetLayout->addWidget( tmplabel, 2, 0, Qt::AlignRight );
+
+ m_opacity = new QSpinBox( widget );
+ m_opacity->setObjectName( QStringLiteral("opacity") );
+ m_opacity->setRange( 0, 100 );
+ m_opacity->setSuffix( i18nc( "Suffix for the opacity level, eg '80 %'", " %" ) );
+ tmplabel->setBuddy( m_opacity );
+ widgetLayout->addWidget( m_opacity, 2, 1 );
+
+ if ( initialState.isNull() )
+ {
+ setWindowTitle( i18n("Create drawing tool") );
+ m_colorBn->setColor( Qt::black );
+ m_penWidth->setValue( 2 );
+ m_opacity->setValue( 100 );
+ }
+ else
+ {
+ setWindowTitle( i18n("Edit drawing tool") );
+ loadTool( initialState );
+ }
+}
+
+EditDrawingToolDialog::~EditDrawingToolDialog()
+{
+}
+
+QDomDocument EditDrawingToolDialog::toolXml() const
+{
+ QDomDocument doc;
+ QDomElement toolElement = doc.createElement( QStringLiteral("tool") );
+ QDomElement engineElement = doc.createElement( QStringLiteral("engine") );
+ QDomElement annotationElement = doc.createElement( QStringLiteral("annotation") );
+ doc.appendChild( toolElement );
+ toolElement.appendChild( engineElement );
+ engineElement.appendChild( annotationElement );
+
+ const QString color = m_colorBn->color().name();
+ const double opacity = m_opacity->value() / 100.0;
+
+ engineElement.setAttribute( QStringLiteral("color"), color );
+
+ annotationElement.setAttribute( QStringLiteral("type"), QStringLiteral("Ink") );
+ annotationElement.setAttribute( QStringLiteral("color"), color );
+ annotationElement.setAttribute( QStringLiteral("width"), QString::number( m_penWidth->value() ) );
+
+ if ( opacity != 1.0 )
+ annotationElement.setAttribute( QStringLiteral("opacity"), QString::number( opacity ) );
+
+ return doc;
+}
+
+void EditDrawingToolDialog::loadTool( const QDomElement &toolElement )
+{
+ const QDomElement engineElement = toolElement.elementsByTagName( QStringLiteral("engine") ).item( 0 ).toElement();
+ const QDomElement annotationElement = engineElement.elementsByTagName( QStringLiteral("annotation") ).item( 0 ).toElement();
+
+ if ( annotationElement.hasAttribute( QStringLiteral("color") ) )
+ m_colorBn->setColor( QColor( annotationElement.attribute( QStringLiteral("color") ) ) );
+
+ m_penWidth->setValue( annotationElement.attribute( QStringLiteral("width"), QStringLiteral("2") ).toInt() );
+ m_opacity->setValue( annotationElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble() * 100 );
+}
diff --git a/conf/editdrawingtooldialog.h b/conf/editdrawingtooldialog.h
new file mode 100644
index 0000000..a551020
--- /dev/null
+++ b/conf/editdrawingtooldialog.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef EDITDRAWINGTOOLDIALOG_H
+#define EDITDRAWINGTOOLDIALOG_H
+
+#include <QDialog>
+#include <QDomElement>
+
+class KColorButton;
+
+class QSpinBox;
+
+class EditDrawingToolDialog : public QDialog
+{
+ Q_OBJECT
+public:
+ explicit EditDrawingToolDialog( const QDomElement &initialState = QDomElement(), QWidget *parent = Q_NULLPTR );
+ ~EditDrawingToolDialog();
+
+ QDomDocument toolXml() const;
+
+private:
+ void loadTool( const QDomElement &toolElement );
+
+ KColorButton *m_colorBn;
+ QSpinBox *m_penWidth;
+ QSpinBox *m_opacity;
+};
+
+#endif // EDITDRAWINGTOOLDIALOG_H
diff --git a/conf/okular.kcfg b/conf/okular.kcfg
index 9c03f4f..ec8d569 100644
--- a/conf/okular.kcfg
+++ b/conf/okular.kcfg
@@ -33,6 +33,44 @@
<entry key="ReviewsSearchRegularExpression" type="Bool">
<default>false</default>
</entry>
+ <entry key="DrawingTools" type="StringList">
+ <code>
+ QStringList drawingTools;
+ // load the default tool list from the 'xml tools definition' file
+ QFile infoDrawingFile( QStandardPaths::locate(QStandardPaths::GenericDataLocation, "okular/drawingtools.xml") );
+ if ( infoDrawingFile.exists() &amp;&amp; infoDrawingFile.open( QIODevice::ReadOnly ) )
+ {
+ QDomDocument doc;
+ if ( doc.setContent( &amp;infoDrawingFile ) )
+ {
+ const QDomElement toolsDefinition = doc.elementsByTagName("drawingTools").item( 0 ).toElement();
+ // create the annotationTools list from the XML dom tree
+ QDomNode toolDescription = toolsDefinition.firstChild();
+ while ( toolDescription.isElement() )
+ {
+ const 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
+ drawingTools &lt;&lt; temp.toString(-1);
+ }
+ toolDescription = toolDescription.nextSibling();
+ }
+ }
+ else
+ {
+ qWarning() &lt;&lt; "DrawingTools XML file seems to be damaged";
+ }
+ }
+ else
+ {
+ qWarning() &lt;&lt; "Unable to open DrawingTools XML definition";
+ }
+ </code>
+ <default code="true">drawingTools</default>
+ </entry>
<entry key="AnnotationTools" type="StringList">
<code>
QStringList annotationTools;
@@ -142,9 +180,6 @@
<entry key="SlidesShowSummary" type="Bool" >
<default>false</default>
</entry>
- <entry key="SlidesPencilColor" type="Color" >
- <default code="true" >Qt::red</default>
- </entry>
<entry key="SlidesTransitionsEnabled" type="Bool" >
<default>true</default>
</entry>
diff --git a/conf/widgetannottools.cpp b/conf/widgetannottools.cpp
index 0ee1857..0c2f78b 100644
--- a/conf/widgetannottools.cpp
+++ b/conf/widgetannottools.cpp
@@ -8,23 +8,16 @@
***************************************************************************/
#include "widgetannottools.h"
+#include "editannottooldialog.h"
-#include <kcolorbutton.h>
-#include <kcombobox.h>
-#include <QtCore/QDebug>
#include <QIcon>
#include <klocalizedstring.h>
-#include <klineedit.h>
+
#include <QtWidgets/QApplication>
-#include <QtWidgets/QHBoxLayout>
-#include <QtWidgets/QVBoxLayout>
-#include <QtWidgets/QGroupBox>
-#include <QtWidgets/QLabel>
-#include <QtWidgets/QListWidget>
-#include <QtWidgets/QListWidgetItem>
-#include <QtWidgets/QPushButton>
-#include <QtWidgets/QStackedWidget>
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QListWidgetItem>
#include <QtXml/QDomDocument>
#include <QtXml/QDomElement>
#include <KConfigGroup>
@@ -32,51 +25,15 @@
#include <QPushButton>
#include <QVBoxLayout>
-#include "core/annotations.h"
-#include "ui/annotationwidgets.h"
#include "ui/pageviewannotator.h"
// Used to store tools' XML description in m_list's items
static const int ToolXmlRole = Qt::UserRole;
WidgetAnnotTools::WidgetAnnotTools( QWidget * parent )
- : QWidget( parent )
+ : WidgetConfigurationToolsBase( parent )
{
- QHBoxLayout *hBoxLayout = new QHBoxLayout( this );
- m_list = new QListWidget( this );
- m_list->setIconSize( QSize( 64, 64 ) );
- hBoxLayout->addWidget( m_list );
-
- QVBoxLayout *vBoxLayout = new QVBoxLayout();
- m_btnAdd = new QPushButton( i18n("&Add..."), this );
- m_btnAdd->setIcon( QIcon::fromTheme("list-add") );
- vBoxLayout->addWidget( m_btnAdd );
- m_btnEdit = new QPushButton( i18n("&Edit..."), this );
- m_btnEdit->setIcon( QIcon::fromTheme("edit-rename") );
- m_btnEdit->setEnabled( false );
- vBoxLayout->addWidget( m_btnEdit );
- m_btnRemove = new QPushButton( i18n("&Remove"), this );
- m_btnRemove->setIcon( QIcon::fromTheme("list-remove") );
- m_btnRemove->setEnabled( false );
- vBoxLayout->addWidget( m_btnRemove );
- m_btnMoveUp = new QPushButton( i18n("Move &Up"), this );
- m_btnMoveUp->setIcon( QIcon::fromTheme("arrow-up") );
- m_btnMoveUp->setEnabled( false );
- vBoxLayout->addWidget( m_btnMoveUp );
- m_btnMoveDown = new QPushButton( i18n("Move &Down"), this );
- m_btnMoveDown->setIcon( QIcon::fromTheme("arrow-down") );
- m_btnMoveDown->setEnabled( false );
- vBoxLayout->addWidget( m_btnMoveDown );
- vBoxLayout->addStretch();
- hBoxLayout->addLayout( vBoxLayout );
-
- connect(m_list, &QListWidget::itemDoubleClicked, this, &WidgetAnnotTools::slotEdit);
- connect(m_list, &QListWidget::currentRowChanged, this, &WidgetAnnotTools::updateButtons);
- connect(m_btnAdd, &QPushButton::clicked, this, &WidgetAnnotTools::slotAdd);
- connect(m_btnEdit, &QPushButton::clicked, this, &WidgetAnnotTools::slotEdit);
- connect(m_btnRemove, &QPushButton::clicked, this, &WidgetAnnotTools::slotRemove);
- connect(m_btnMoveUp, &QPushButton::clicked, this, &WidgetAnnotTools::slotMoveUp);
- connect(m_btnMoveDown, &QPushButton::clicked, this, &WidgetAnnotTools::slotMoveDown);
+
}
WidgetAnnotTools::~WidgetAnnotTools()
@@ -104,14 +61,14 @@ QStringList WidgetAnnotTools::tools() const
toolElement.setAttribute( "id", i+1 );
// Remove old shortcut, if any
- QDomNode oldShortcut = toolElement.elementsByTagName( "shortcut" ).item( 0 );
+ QDomNode oldShortcut = toolElement.elementsByTagName( QStringLiteral("shortcut") ).item( 0 );
if ( oldShortcut.isElement() )
toolElement.removeChild( oldShortcut );
// Create new shortcut element (only the first 9 tools are assigned a shortcut key)
if ( i < 9 )
{
- QDomElement newShortcut = doc.createElement( "shortcut" );
+ QDomElement newShortcut = doc.createElement( QStringLiteral("shortcut") );
newShortcut.appendChild( doc.createTextNode(QString::number( i+1 )) );
toolElement.appendChild( newShortcut );
}
@@ -138,10 +95,10 @@ void WidgetAnnotTools::setTools(const QStringList& items)
}
QDomElement toolElement = entryParser.documentElement();
- if ( toolElement.tagName() == "tool" )
+ if ( toolElement.tagName() == QLatin1String("tool") )
{
// Create list item and attach the source XML string as data
- QString itemText = toolElement.attribute( "name" );
+ QString itemText = toolElement.attribute( QStringLiteral("name") );
if ( itemText.isEmpty() )
itemText = PageViewAnnotator::defaultToolName( toolElement );
QListWidgetItem * listEntry = new QListWidgetItem( itemText, m_list );
@@ -153,17 +110,6 @@ void WidgetAnnotTools::setTools(const QStringList& items)
updateButtons();
}
-void WidgetAnnotTools::updateButtons()
-{
- const int row = m_list->currentRow();
- const int last = m_list->count() - 1;
-
- m_btnEdit->setEnabled( row != -1 );
- m_btnRemove->setEnabled( row != -1 );
- m_btnMoveUp->setEnabled( row > 0 );
- m_btnMoveDown->setEnabled( row != -1 && row != last );
-}
-
void WidgetAnnotTools::slotEdit()
{
QListWidgetItem *listEntry = m_list->currentItem();
@@ -184,7 +130,7 @@ void WidgetAnnotTools::slotEdit()
// Store name attribute only if the user specified a customized name
if ( !itemText.isEmpty() )
- toolElement.setAttribute( "name", itemText );
+ toolElement.setAttribute( QStringLiteral("name"), itemText );
else
itemText = PageViewAnnotator::defaultToolName( toolElement );
@@ -214,7 +160,7 @@ void WidgetAnnotTools::slotAdd()
// Store name attribute only if the user specified a customized name
if ( !itemText.isEmpty() )
- toolElement.setAttribute( "name", itemText );
+ toolElement.setAttribute( QStringLiteral("name"), itemText );
else
itemText = PageViewAnnotator::defaultToolName( toolElement );
@@ -229,494 +175,3 @@ void WidgetAnnotTools::slotAdd()
updateButtons();
emit changed();
}
-
-void WidgetAnnotTools::slotRemove()
-{
- const int row = m_list->currentRow();
- delete m_list->takeItem(row);
- updateButtons();
- emit changed();
-}
-
-void WidgetAnnotTools::slotMoveUp()
-{
- const int row = m_list->currentRow();
- m_list->insertItem( row, m_list->takeItem(row-1) );
- m_list->scrollToItem( m_list->currentItem() );
- updateButtons();
- emit changed();
-}
-
-void WidgetAnnotTools::slotMoveDown()
-{
- const int row = m_list->currentRow();
- m_list->insertItem( row, m_list->takeItem(row+1) );
- m_list->scrollToItem( m_list->currentItem() );
- updateButtons();
- emit changed();
-}
-
-EditAnnotToolDialog::EditAnnotToolDialog( QWidget *parent, const QDomElement &initialState )
- : QDialog( parent ), m_stubann( 0 ), m_annotationWidget( 0 )
-{
- QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel);
- QVBoxLayout *mainLayout = new QVBoxLayout;
- setLayout(mainLayout);
- QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok);
- okButton->setDefault(true);
- okButton->setShortcut(Qt::CTRL | Qt::Key_Return);
- connect(buttonBox, &QDialogButtonBox::accepted, this, &EditAnnotToolDialog::accept);
- connect(buttonBox, &QDialogButtonBox::rejected, this, &EditAnnotToolDialog::reject);
- okButton->setDefault(true);
-
- QLabel * tmplabel;
- QWidget *widget = new QWidget( this );
- QGridLayout * widgetLayout = new QGridLayout( widget );
-
- mainLayout->addWidget(widget);
- mainLayout->addWidget(buttonBox);
-
-
- m_name = new KLineEdit( widget );
- mainLayout->addWidget(m_name);
- tmplabel = new QLabel( i18n( "&Name:" ), widget );
- mainLayout->addWidget(tmplabel);
- tmplabel->setBuddy( m_name );
- widgetLayout->addWidget( tmplabel, 0, 0, Qt::AlignRight );
- widgetLayout->addWidget( m_name, 0, 1 );
-
- m_type = new KComboBox( false, widget );
- 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 );
- widgetLayout->addWidget( tmplabel, 1, 0, Qt::AlignRight );
- widgetLayout->addWidget( m_type, 1, 1 );
-
- m_toolIcon = new QLabel( widget );
- mainLayout->addWidget(m_toolIcon);
- m_toolIcon->setAlignment( Qt::AlignRight | Qt::AlignTop );
- m_toolIcon->setMinimumSize( 40, 32 );
- widgetLayout->addWidget( m_toolIcon, 0, 2, 2, 1 );
-
- m_appearanceBox = new QGroupBox( i18n( "Appearance" ), widget );
- mainLayout->addWidget(m_appearanceBox);
- m_appearanceBox->setLayout( new QVBoxLayout( m_appearanceBox ) );
- widgetLayout->addWidget( m_appearanceBox, 2, 0, 1, 3 );
-
- // Populate combobox with annotation types
- m_type->addItem( i18n("Pop-up Note"), qVariantFromValue( ToolNoteLinked ) );
- m_type->addItem( i18n("Inline Note"), qVariantFromValue( ToolNoteInline ) );
- m_type->addItem( i18n("Freehand Line"), qVariantFromValue( ToolInk ) );
- m_type->addItem( i18n("Straight Line"), qVariantFromValue( ToolStraightLine ) );
- m_type->addItem( i18n("Polygon"), qVariantFromValue( ToolPolygon ) );
- m_type->addItem( i18n("Text markup"), qVariantFromValue( ToolTextMarkup ) );
- m_type->addItem( i18n("Geometrical shape"), qVariantFromValue( ToolGeometricalShape ) );
- m_type->addItem( i18n("Stamp"), qVariantFromValue( ToolStamp ) );
-
- createStubAnnotation();
-
- if ( initialState.isNull() )
- {
- setWindowTitle( i18n("Create annotation tool") );
- }
- else
- {
- setWindowTitle( i18n("Edit annotation tool") );
- loadTool( initialState );
- }
-
- rebuildAppearanceBox();
- updateDefaultNameAndIcon();
-}
-
-EditAnnotToolDialog::~EditAnnotToolDialog()
-{
- delete m_annotationWidget;
-}
-
-QString EditAnnotToolDialog::name() const
-{
- return m_name->text();
-}
-
-QDomDocument EditAnnotToolDialog::toolXml() const
-{
- const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>();
-
- QDomDocument doc;
- QDomElement toolElement = doc.createElement( "tool" );
- QDomElement engineElement = doc.createElement( "engine" );
- QDomElement annotationElement = doc.createElement( "annotation" );
- doc.appendChild( toolElement );
- toolElement.appendChild( engineElement );
- engineElement.appendChild( annotationElement );
-
- const QString color = m_stubann->style().color().name();
- const double opacity = m_stubann->style().opacity();
- const double width = m_stubann->style().width();
-
- if ( toolType == ToolNoteLinked )
- {
- Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
- toolElement.setAttribute( "type", "note-linked" );
- engineElement.setAttribute( "type", "PickPoint" );
- engineElement.setAttribute( "color", color );
- engineElement.setAttribute( "hoverIcon", "tool-note" );
- annotationElement.setAttribute( "type", "Text" );
- annotationElement.setAttribute( "color", color );
- annotationElement.setAttribute( "icon", ta->textIcon() );
- }
- else if ( toolType == ToolNoteInline )
- {
- Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
- toolElement.setAttribute( "type", "note-inline" );
- engineElement.setAttribute( "type", "PickPoint" );
- engineElement.setAttribute( "color", color );
- engineElement.setAttribute( "hoverIcon", "tool-note-inline" );
- engineElement.setAttribute( "block", "true" );
- annotationElement.setAttribute( "type", "FreeText" );
- annotationElement.setAttribute( "color", color );
- if ( ta->inplaceAlignment() != 0 )
- annotationElement.setAttribute( "align", ta->inplaceAlignment() );
- if ( ta->textFont() != QApplication::font() )
- annotationElement.setAttribute( "font", ta->textFont().toString() );
- }
- else if ( toolType == ToolInk )
- {
- toolElement.setAttribute( "type", "ink" );
- engineElement.setAttribute( "type", "SmoothLine" );
- engineElement.setAttribute( "color", color );
- annotationElement.setAttribute( "type", "Ink" );
- annotationElement.setAttribute( "color", color );
- annotationElement.setAttribute( "width", width );
- }
- else if ( toolType == ToolStraightLine )
- {
- Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
- toolElement.setAttribute( "type", "straight-line" );
- engineElement.setAttribute( "type", "PolyLine" );
- engineElement.setAttribute( "color", color );
- engineElement.setAttribute( "points", "2" );
- annotationElement.setAttribute( "type", "Line" );
- annotationElement.setAttribute( "color", color );
- annotationElement.setAttribute( "width", width );
- if ( la->lineLeadingForwardPoint() != 0 || la->lineLeadingBackwardPoint() != 0 )
- {
- annotationElement.setAttribute( "leadFwd", la->lineLeadingForwardPoint() );
- annotationElement.setAttribute( "leadBack", la->lineLeadingBackwardPoint() );
- }
- }
- else if ( toolType == ToolPolygon )
- {
- Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
- toolElement.setAttribute( "type", "polygon" );
- engineElement.setAttribute( "type", "PolyLine" );
- engineElement.setAttribute( "color", color );
- engineElement.setAttribute( "points", "-1" );
- annotationElement.setAttribute( "type", "Line" );
- annotationElement.setAttribute( "color", color );
- annotationElement.setAttribute( "width", width );
- if ( la->lineInnerColor().isValid() )
- {
- annotationElement.setAttribute( "innerColor", la->lineInnerColor().name() );
- }
- }
- else if ( toolType == ToolTextMarkup )
- {
- Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
-
- switch ( ha->highlightType() )
- {
- case Okular::HighlightAnnotation::Highlight:
- toolElement.setAttribute( "type", "highlight" );
- annotationElement.setAttribute( "type", "Highlight" );
- break;
- case Okular::HighlightAnnotation::Squiggly:
- toolElement.setAttribute( "type", "squiggly" );
- annotationElement.setAttribute( "type", "Squiggly" );
- break;
- case Okular::HighlightAnnotation::Underline:
- toolElement.setAttribute( "type", "underline" );
- annotationElement.setAttribute( "type", "Underline" );
- break;
- case Okular::HighlightAnnotation::StrikeOut:
- toolElement.setAttribute( "type", "strikeout" );
- annotationElement.setAttribute( "type", "StrikeOut" );
- break;
- }
-
- engineElement.setAttribute( "type", "TextSelector" );
- engineElement.setAttribute( "color", color );
- annotationElement.setAttribute( "color", color );
- }
- else if ( toolType == ToolGeometricalShape )
- {
- Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
-
- if ( ga->geometricalType() == Okular::GeomAnnotation::InscribedCircle )
- {
- toolElement.setAttribute( "type", "ellipse" );
- annotationElement.setAttribute( "type", "GeomCircle" );
- }
- else
- {
- toolElement.setAttribute( "type", "rectangle" );
- annotationElement.setAttribute( "type", "GeomSquare" );
- }
-
- engineElement.setAttribute( "type", "PickPoint" );
- engineElement.setAttribute( "color", color );
- engineElement.setAttribute( "block", "true" );
- annotationElement.setAttribute( "color", color );
- annotationElement.setAttribute( "width", width );
-
- if ( ga->geometricalInnerColor().isValid() )
- annotationElement.setAttribute( "innerColor", ga->geometricalInnerColor().name() );
- }
- else if ( toolType == ToolStamp )
- {
- Okular::StampAnnotation * sa = static_cast<Okular::StampAnnotation*>( m_stubann );
- toolElement.setAttribute( "type", "stamp" );
- engineElement.setAttribute( "type", "PickPoint" );
- engineElement.setAttribute( "hoverIcon", sa->stampIconName() );
- engineElement.setAttribute( "size", "64" );
- engineElement.setAttribute( "block", "true" );
- annotationElement.setAttribute( "type", "Stamp" );
- annotationElement.setAttribute( "icon", sa->stampIconName() );
- }
-
- if ( opacity != 1 )
- annotationElement.setAttribute( "opacity", opacity );
-
- return doc;
-}
-
-void EditAnnotToolDialog::createStubAnnotation()
-{
- const ToolType toolType = m_type->itemData( m_type->currentIndex() ).value<ToolType>();
-
- // Delete previous stub annotation, if any
- delete m_stubann;
-
- // Create stub annotation
- if ( toolType == ToolNoteLinked )
- {
- Okular::TextAnnotation * ta = new Okular::TextAnnotation();
- ta->setTextType( Okular::TextAnnotation::Linked );
- ta->setTextIcon( "Note" );
- ta->style().setColor( Qt::yellow );
- m_stubann = ta;
- }
- else if ( toolType == ToolNoteInline )
- {
- Okular::TextAnnotation * ta = new Okular::TextAnnotation();
- ta->setTextType( Okular::TextAnnotation::InPlace );
- ta->style().setColor( Qt::yellow );
- m_stubann = ta;
- }
- else if ( toolType == ToolInk )
- {
- m_stubann = new Okular::InkAnnotation();
- m_stubann->style().setWidth( 2.0 );
- m_stubann->style().setColor( Qt::green );
- }
- else if ( toolType == ToolStraightLine )
- {
- Okular::LineAnnotation * la = new Okular::LineAnnotation();
- la->setLinePoints( QLinkedList<Okular::NormalizedPoint>() <<
- Okular::NormalizedPoint(0,0) <<
- Okular::NormalizedPoint(1,0) );
- la->style().setColor( QColor( 0xff, 0xe0, 0x00 ) );
- m_stubann = la;
- }
- else if ( toolType == ToolPolygon )
- {
- Okular::LineAnnotation * la = new Okular::LineAnnotation();
- la->setLinePoints( QLinkedList<Okular::NormalizedPoint>() <<
- Okular::NormalizedPoint(0,0) <<
- Okular::NormalizedPoint(1,0) <<
- Okular::NormalizedPoint(1,1) );
- la->setLineClosed( true );
- la->style().setColor( QColor( 0x00, 0x7e, 0xee ) );
- m_stubann = la;
- }
- else if ( toolType == ToolTextMarkup )
- {
- m_stubann = new Okular::HighlightAnnotation();
- m_stubann->style().setColor( Qt::yellow );
- }
- else if ( toolType == ToolGeometricalShape )
- {
- Okular::GeomAnnotation * ga = new Okular::GeomAnnotation();
- ga->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
- ga->style().setWidth( 5.0 );
- ga->style().setColor( Qt::cyan );
- m_stubann = ga;
- }
- else if ( toolType == ToolStamp )
- {
- Okular::StampAnnotation * sa = new Okular::StampAnnotation();
- sa->setStampIconName( "okular" );
- m_stubann = sa;
- }
-}
-
-void EditAnnotToolDialog::rebuildAppearanceBox()
-{
- // Remove previous widget (if any)
- if ( m_annotationWidget )
- {
- delete m_annotationWidget->appearanceWidget();
- delete m_annotationWidget;
- }
-
- m_annotationWidget = AnnotationWidgetFactory::widgetFor( m_stubann );
- m_appearanceBox->layout()->addWidget( m_annotationWidget->appearanceWidget() );
-
- connect(m_annotationWidget, &AnnotationWidget::dataChanged, this, &EditAnnotToolDialog::slotDataChanged);
-}
-
-void EditAnnotToolDialog::updateDefaultNameAndIcon()
-{
- QDomDocument doc = toolXml();
- QDomElement toolElement = doc.documentElement();
- m_name->setPlaceholderText( PageViewAnnotator::defaultToolName( toolElement ) );
- m_toolIcon->setPixmap( PageViewAnnotator::makeToolPixmap( toolElement ) );
-}
-
-void EditAnnotToolDialog::setToolType( ToolType newType )
-{
- int idx = -1;
-
- for ( int i = 0; idx == -1 && i < m_type->count(); ++i )
- {
- if ( m_type->itemData( i ).value<ToolType>() == newType )
- idx = i;
- }
-
- // The following call also results in createStubAnnotation being called
- m_type->setCurrentIndex( idx );
-}
-
-void EditAnnotToolDialog::loadTool( const QDomElement &toolElement )
-{
- const QDomElement engineElement = toolElement.elementsByTagName( "engine" ).item( 0 ).toElement();
- const QDomElement annotationElement = engineElement.elementsByTagName( "annotation" ).item( 0 ).toElement();
- const QString annotType = toolElement.attribute( "type" );
-
- if ( annotType == "ellipse" )
- {
- setToolType( ToolGeometricalShape );
- Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
- ga->setGeometricalType( Okular::GeomAnnotation::InscribedCircle );
- if ( annotationElement.hasAttribute( "innerColor" ) )
- ga->setGeometricalInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
- }
- else if ( annotType == "highlight" )
- {
- setToolType( ToolTextMarkup );
- Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
- ha->setHighlightType( Okular::HighlightAnnotation::Highlight );
- }
- else if ( annotType == "ink" )
- {
- setToolType( ToolInk );
- }
- else if ( annotType == "note-inline" )
- {
- setToolType( ToolNoteInline );
- Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
- if ( annotationElement.hasAttribute( "align" ) )
- ta->setInplaceAlignment( annotationElement.attribute( "align" ).toInt() );
- if ( annotationElement.hasAttribute( "font" ) )
- {
- QFont f;
- f.fromString( annotationElement.attribute( "font" ) );
- ta->setTextFont( f );
- }
- }
- else if ( annotType == "note-linked" )
- {
- setToolType( ToolNoteLinked );
- Okular::TextAnnotation * ta = static_cast<Okular::TextAnnotation*>( m_stubann );
- ta->setTextIcon( annotationElement.attribute( "icon" ) );
- }
- else if ( annotType == "polygon" )
- {
- setToolType( ToolPolygon );
- Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
- if ( annotationElement.hasAttribute( "innerColor" ) )
- la->setLineInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
- }
- else if ( annotType == "rectangle" )
- {
- setToolType( ToolGeometricalShape );
- Okular::GeomAnnotation * ga = static_cast<Okular::GeomAnnotation*>( m_stubann );
- ga->setGeometricalType( Okular::GeomAnnotation::InscribedSquare );
- if ( annotationElement.hasAttribute( "innerColor" ) )
- ga->setGeometricalInnerColor( QColor( annotationElement.attribute( "innerColor" ) ) );
- }
- else if ( annotType == "squiggly" )
- {
- setToolType( ToolTextMarkup );
- Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
- ha->setHighlightType( Okular::HighlightAnnotation::Squiggly );
- }
- else if ( annotType == "stamp" )
- {
- setToolType( ToolStamp );
- Okular::StampAnnotation * sa = static_cast<Okular::StampAnnotation*>( m_stubann );
- sa->setStampIconName( annotationElement.attribute( "icon" ) );
- }
- else if ( annotType == "straight-line" )
- {
- setToolType( ToolStraightLine );
- Okular::LineAnnotation * la = static_cast<Okular::LineAnnotation*>( m_stubann );
- if ( annotationElement.hasAttribute( "leadFwd" ) )
- la->setLineLeadingForwardPoint( annotationElement.attribute( "leadFwd" ).toDouble() );
- if ( annotationElement.hasAttribute( "leadBack" ) )
- la->setLineLeadingBackwardPoint( annotationElement.attribute( "leadBack" ).toDouble() );
- }
- else if ( annotType == "strikeout" )
- {
- setToolType( ToolTextMarkup );
- Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
- ha->setHighlightType( Okular::HighlightAnnotation::StrikeOut );
- }
- else if ( annotType == "underline" )
- {
- setToolType( ToolTextMarkup );
- Okular::HighlightAnnotation * ha = static_cast<Okular::HighlightAnnotation*>( m_stubann );
- ha->setHighlightType( Okular::HighlightAnnotation::Underline );
- }
-
- // Common properties
- if ( annotationElement.hasAttribute( "color" ) )
- m_stubann->style().setColor( QColor( annotationElement.attribute( "color" ) ) );
- if ( annotationElement.hasAttribute( "opacity" ) )
- m_stubann->style().setOpacity( annotationElement.attribute( "opacity" ).toDouble() );
- if ( annotationElement.hasAttribute( "width" ) )
- m_stubann->style().setWidth( annotationElement.attribute( "width" ).toDouble() );
-
- if ( toolElement.hasAttribute( "name" ) )
- m_name->setText( toolElement.attribute( "name" ) );
-}
-
-void EditAnnotToolDialog::slotTypeChanged()
-{
- createStubAnnotation();
- rebuildAppearanceBox();
- updateDefaultNameAndIcon();
-}
-
-void EditAnnotToolDialog::slotDataChanged()
-{
- // Mirror changes back in the stub annotation
- m_annotationWidget->applyChanges();
-
- updateDefaultNameAndIcon();
-}
-
-#include "moc_widgetannottools.cpp"
diff --git a/conf/widgetannottools.h b/conf/widgetannottools.h
index cf6a7be..8fa2331 100644
--- a/conf/widgetannottools.h
+++ b/conf/widgetannottools.h
@@ -10,99 +10,29 @@
#ifndef _WIDGETANNOTTOOLS_H_
#define _WIDGETANNOTTOOLS_H_
-#include <QDialog>
+#include "widgetconfigurationtoolsbase.h"
+
#include <qdom.h>
#include <qwidget.h>
-class KLineEdit;
-class KComboBox;
-class QPushButton;
-class QLabel;
-class QListWidget;
-class QListWidgetItem;
-class QGroupBox;
-class AnnotationWidget;
-
namespace Okular
{
class Annotation;
}
-class WidgetAnnotTools : public QWidget
+class WidgetAnnotTools : public WidgetConfigurationToolsBase
{
Q_OBJECT
-
- Q_PROPERTY( QStringList tools READ tools WRITE setTools NOTIFY changed USER true )
-
public:
explicit WidgetAnnotTools( QWidget * parent = Q_NULLPTR );
~WidgetAnnotTools();
- QStringList tools() const;
- void setTools(const QStringList& items);
-
- Q_SIGNALS:
- void changed();
-
- private:
- QListWidget *m_list;
- QPushButton *m_btnAdd;
- QPushButton *m_btnEdit;
- QPushButton *m_btnRemove;
- QPushButton *m_btnMoveUp;
- QPushButton *m_btnMoveDown;
-
- private slots:
- void updateButtons();
- void slotAdd();
- void slotEdit();
- void slotRemove();
- void slotMoveUp();
- void slotMoveDown();
-};
-
-class EditAnnotToolDialog : public QDialog
-{
- Q_OBJECT
-
- public:
- enum ToolType
- {
- ToolNoteLinked,
- ToolNoteInline,
- ToolInk,
- ToolStraightLine,
- ToolPolygon,
- ToolTextMarkup,
- ToolGeometricalShape,
- ToolStamp
- };
-
- EditAnnotToolDialog( QWidget *parent = Q_NULLPTR, const QDomElement &initialState = QDomElement() );
- ~EditAnnotToolDialog();
- QString name() const;
- QDomDocument toolXml() const;
+ QStringList tools() const Q_DECL_OVERRIDE;
+ void setTools(const QStringList& items) Q_DECL_OVERRIDE;
- private:
- void createStubAnnotation();
- void rebuildAppearanceBox();
- void updateDefaultNameAndIcon();
- void setToolType( ToolType newType );
- void loadTool( const QDomElement &toolElement );
-
- KLineEdit *m_name;
- KComboBox *m_type;
- QLabel *m_toolIcon;
- QGroupBox *m_appearanceBox;
-
- Okular::Annotation *m_stubann;
- AnnotationWidget *m_annotationWidget;
-
- private slots:
- void slotTypeChanged();
- void slotDataChanged();
+ protected slots:
+ void slotAdd() Q_DECL_OVERRIDE;
+ void slotEdit() Q_DECL_OVERRIDE;
};
-Q_DECLARE_METATYPE( EditAnnotToolDialog::ToolType )
-
#endif
diff --git a/conf/widgetconfigurationtoolsbase.cpp b/conf/widgetconfigurationtoolsbase.cpp
new file mode 100644
index 0000000..d30c5e8
--- /dev/null
+++ b/conf/widgetconfigurationtoolsbase.cpp
@@ -0,0 +1,104 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+
+#include "widgetconfigurationtoolsbase.h"
+
+
+#include <QIcon>
+#include <KLocalizedString>
+
+#include <QHBoxLayout>
+#include <QListWidget>
+#include <QListWidgetItem>
+#include <QDialogButtonBox>
+#include <QPushButton>
+#include <QVBoxLayout>
+
+WidgetConfigurationToolsBase::WidgetConfigurationToolsBase( QWidget * parent )
+ : QWidget( parent )
+{
+ QHBoxLayout *hBoxLayout = new QHBoxLayout( this );
+ m_list = new QListWidget( this );
+ m_list->setIconSize( QSize( 64, 64 ) );
+ hBoxLayout->addWidget( m_list );
+
+ QVBoxLayout *vBoxLayout = new QVBoxLayout();
+ m_btnAdd = new QPushButton( i18n("&Add..."), this );
+ m_btnAdd->setIcon( QIcon::fromTheme(QStringLiteral("list-add")) );
+ vBoxLayout->addWidget( m_btnAdd );
+ m_btnEdit = new QPushButton( i18n("&Edit..."), this );
+ m_btnEdit->setIcon( QIcon::fromTheme(QStringLiteral("edit-rename")) );
+ m_btnEdit->setEnabled( false );
+ vBoxLayout->addWidget( m_btnEdit );
+ m_btnRemove = new QPushButton( i18n("&Remove"), this );
+ m_btnRemove->setIcon( QIcon::fromTheme(QStringLiteral("list-remove")) );
+ m_btnRemove->setEnabled( false );
+ vBoxLayout->addWidget( m_btnRemove );
+ m_btnMoveUp = new QPushButton( i18n("Move &Up"), this );
+ m_btnMoveUp->setIcon( QIcon::fromTheme(QStringLiteral("arrow-up")) );
+ m_btnMoveUp->setEnabled( false );
+ vBoxLayout->addWidget( m_btnMoveUp );
+ m_btnMoveDown = new QPushButton( i18n("Move &Down"), this );
+ m_btnMoveDown->setIcon( QIcon::fromTheme(QStringLiteral("arrow-down")) );
+ m_btnMoveDown->setEnabled( false );
+ vBoxLayout->addWidget( m_btnMoveDown );
+ vBoxLayout->addStretch();
+ hBoxLayout->addLayout( vBoxLayout );
+
+ connect(m_list, &QListWidget::itemDoubleClicked, this, &WidgetConfigurationToolsBase::slotEdit);
+ connect(m_list, &QListWidget::currentRowChanged, this, &WidgetConfigurationToolsBase::updateButtons);
+ connect(m_btnAdd, &QPushButton::clicked, this, &WidgetConfigurationToolsBase::slotAdd);
+ connect(m_btnEdit, &QPushButton::clicked, this, &WidgetConfigurationToolsBase::slotEdit);
+ connect(m_btnRemove, &QPushButton::clicked, this, &WidgetConfigurationToolsBase::slotRemove);
+ connect(m_btnMoveUp, &QPushButton::clicked, this, &WidgetConfigurationToolsBase::slotMoveUp);
+ connect(m_btnMoveDown, &QPushButton::clicked, this, &WidgetConfigurationToolsBase::slotMoveDown);
+}
+
+WidgetConfigurationToolsBase::~WidgetConfigurationToolsBase()
+{
+}
+
+void WidgetConfigurationToolsBase::updateButtons()
+{
+ const int row = m_list->currentRow();
+ const int last = m_list->count() - 1;
+
+ m_btnEdit->setEnabled( row != -1 );
+ m_btnRemove->setEnabled( row != -1 );
+ m_btnMoveUp->setEnabled( row > 0 );
+ m_btnMoveDown->setEnabled( row != -1 && row != last );
+}
+
+
+void WidgetConfigurationToolsBase::slotRemove()
+{
+ const int row = m_list->currentRow();
+ delete m_list->takeItem(row);
+ updateButtons();
+ emit changed();
+}
+
+void WidgetConfigurationToolsBase::slotMoveUp()
+{
+ const int row = m_list->currentRow();
+ m_list->insertItem( row, m_list->takeItem(row-1) );
+ m_list->scrollToItem( m_list->currentItem() );
+ updateButtons();
+ emit changed();
+}
+
+void WidgetConfigurationToolsBase::slotMoveDown()
+{
+ const int row = m_list->currentRow();
+ m_list->insertItem( row, m_list->takeItem(row+1) );
+ m_list->scrollToItem( m_list->currentItem() );
+ updateButtons();
+ emit changed();
+}
diff --git a/conf/widgetconfigurationtoolsbase.h b/conf/widgetconfigurationtoolsbase.h
new file mode 100644
index 0000000..8957853
--- /dev/null
+++ b/conf/widgetconfigurationtoolsbase.h
@@ -0,0 +1,51 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#ifndef WIDGETCONFIGURATIONTOOLSBASE_H
+#define WIDGETCONFIGURATIONTOOLSBASE_H
+
+#include <QWidget>
+class QListWidget;
+class QPushButton;
+
+class WidgetConfigurationToolsBase : public QWidget
+{
+ Q_OBJECT
+
+ Q_PROPERTY( QStringList tools READ tools WRITE setTools NOTIFY changed USER true )
+
+ public:
+ explicit WidgetConfigurationToolsBase( QWidget * parent = Q_NULLPTR );
+ ~WidgetConfigurationToolsBase();
+
+ virtual QStringList tools() const = 0;
+ virtual void setTools(const QStringList& items) = 0;
+
+ Q_SIGNALS:
+ void changed();
+
+ protected:
+ QListWidget *m_list;
+ private:
+ QPushButton *m_btnAdd;
+ QPushButton *m_btnEdit;
+ QPushButton *m_btnRemove;
+ QPushButton *m_btnMoveUp;
+ QPushButton *m_btnMoveDown;
+
+ protected slots:
+ virtual void slotAdd() = 0;
+ virtual void slotEdit() = 0;
+ void updateButtons();
+ void slotRemove();
+ void slotMoveUp();
+ void slotMoveDown();
+};
+
+#endif // WIDGETCONFIGURATIONTOOLSBASE_H
diff --git a/conf/widgetdrawingtools.cpp b/conf/widgetdrawingtools.cpp
new file mode 100644
index 0000000..3f6c3db
--- /dev/null
+++ b/conf/widgetdrawingtools.cpp
@@ -0,0 +1,144 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#include "widgetdrawingtools.h"
+
+#include "editdrawingtooldialog.h"
+
+#include <QDebug>
+#include <QDomElement>
+#include <QListWidgetItem>
+#include <QPainter>
+
+// Used to store tools' XML description in m_list's items
+static const int ToolXmlRole = Qt::UserRole;
+
+static QPixmap colorDecorationFromToolDescription( const QString &toolDescription )
+{
+ QDomDocument doc;
+ doc.setContent( toolDescription, true );
+ const QDomElement toolElement = doc.documentElement();
+ const QDomElement engineElement = toolElement.elementsByTagName( QStringLiteral( "engine" ) ).at( 0 ).toElement();
+ const QDomElement annotationElement = engineElement.elementsByTagName( QStringLiteral( "annotation" ) ).at( 0 ).toElement();
+
+ QPixmap pm( 50, 20 );
+ pm.fill( QColor( annotationElement.attribute( QStringLiteral( "color" ) ) ) );
+
+ QPainter p( &pm );
+ p.setPen( Qt::black );
+ p.drawRect( QRect( 0, 0, pm.width() - 1, pm.height() - 1 ) );
+
+ return pm;
+};
+
+WidgetDrawingTools::WidgetDrawingTools( QWidget *parent )
+ : WidgetConfigurationToolsBase( parent )
+{
+}
+
+WidgetDrawingTools::~WidgetDrawingTools()
+{
+
+}
+
+QStringList WidgetDrawingTools::tools() const
+{
+ QStringList res;
+
+ const int count = m_list->count();
+ for ( int i = 0; i < count; ++i )
+ {
+ QListWidgetItem * listEntry = m_list->item( i );
+
+ // Parse associated DOM data
+ QDomDocument doc;
+ doc.setContent( listEntry->data( ToolXmlRole ).value<QString>() );
+
+ // Append to output
+ res << doc.toString( -1 );
+ }
+
+ return res;
+}
+
+void WidgetDrawingTools::setTools( const QStringList &items )
+{
+ m_list->clear();
+
+ // Parse each string and populate the list widget
+ foreach ( const QString &toolXml, items )
+ {
+ QDomDocument entryParser;
+ if ( !entryParser.setContent( toolXml ) )
+ {
+ qWarning() << "Skipping malformed tool XML string";
+ break;
+ }
+
+ const QDomElement toolElement = entryParser.documentElement();
+ if ( toolElement.tagName() == QLatin1String("tool") )
+ {
+ QListWidgetItem * listEntry = new QListWidgetItem( m_list );
+ listEntry->setData( ToolXmlRole, qVariantFromValue( toolXml ) );
+ listEntry->setData( Qt::DecorationRole, colorDecorationFromToolDescription( toolXml ) );
+ }
+ }
+
+ updateButtons();
+}
+
+void WidgetDrawingTools::slotAdd()
+{
+ EditDrawingToolDialog dlg( QDomElement(), this );
+
+ if ( dlg.exec() != QDialog::Accepted )
+ return;
+
+ const QDomDocument rootDoc = dlg.toolXml();
+ const QDomElement toolElement = rootDoc.documentElement();
+
+ // Create list entry and attach XML string as data
+ const QString toolXml = rootDoc.toString( -1 );
+ QListWidgetItem * listEntry = new QListWidgetItem( m_list );
+ listEntry->setData( ToolXmlRole, qVariantFromValue( toolXml ) );
+ listEntry->setData( Qt::DecorationRole, colorDecorationFromToolDescription( toolXml ) );
+
+ // Select and scroll
+ m_list->setCurrentItem( listEntry );
+ m_list->scrollToItem( listEntry );
+ updateButtons();
+ emit changed();
+}
+
+void WidgetDrawingTools::slotEdit()
+{
+ QListWidgetItem *listEntry = m_list->currentItem();
+
+ QDomDocument doc;
+ doc.setContent( listEntry->data( ToolXmlRole ).value<QString>() );
+ const QDomElement toolElement = doc.documentElement();
+
+ EditDrawingToolDialog dlg( toolElement, this );
+
+ if ( dlg.exec() != QDialog::Accepted )
+ return;
+
+ doc = dlg.toolXml();
+
+ // Edit list entry and attach XML string as data
+ const QString toolXml = doc.toString( -1 );
+ listEntry->setData( ToolXmlRole, qVariantFromValue( toolXml ) );
+ listEntry->setData( Qt::DecorationRole, colorDecorationFromToolDescription( toolXml ) );
+
+ // Select and scroll
+ m_list->setCurrentItem( listEntry );
+ m_list->scrollToItem( listEntry );
+ updateButtons();
+ emit changed();
+}
diff --git a/conf/widgetdrawingtools.h b/conf/widgetdrawingtools.h
new file mode 100644
index 0000000..1c43502
--- /dev/null
+++ b/conf/widgetdrawingtools.h
@@ -0,0 +1,31 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+
+#ifndef WIDGETDRAWINGTOOLS_H
+#define WIDGETDRAWINGTOOLS_H
+
+#include "widgetconfigurationtoolsbase.h"
+
+class WidgetDrawingTools : public WidgetConfigurationToolsBase
+{
+ Q_OBJECT
+public:
+ explicit WidgetDrawingTools( QWidget * parent = Q_NULLPTR );
+ ~WidgetDrawingTools();
+
+ QStringList tools() const Q_DECL_OVERRIDE;
+ void setTools( const QStringList& items ) Q_DECL_OVERRIDE;
+
+protected slots:
+ void slotAdd() Q_DECL_OVERRIDE;
+ void slotEdit() Q_DECL_OVERRIDE;
+};
+
+#endif // WIDGETDRAWINGTOOLS_H
diff --git a/part.cpp b/part.cpp
index 11ba9ca..fe29e07 100644
--- a/part.cpp
+++ b/part.cpp
@@ -816,11 +816,6 @@ void Part::setupActions()
blackscreenAction->setIcon( QIcon::fromTheme( "view-presentation" ) );
blackscreenAction->setEnabled( false );
- KToggleAction *drawingAction = new KToggleAction( i18n( "Toggle Drawing Mode" ), ac );
- ac->addAction( "presentation_drawing_mode", drawingAction );
- drawingAction->setIcon( QIcon::fromTheme( "draw-freehand" ) );
- drawingAction->setEnabled( false );
-
QAction *eraseDrawingAction = new QAction( i18n( "Erase Drawings" ), ac );
ac->addAction( "presentation_erase_drawings", eraseDrawingAction );
eraseDrawingAction->setIcon( QIcon::fromTheme( "draw-eraser" ) );
diff --git a/ui/annotationtools.cpp b/ui/annotationtools.cpp
index afc7176..379533e 100644
--- a/ui/annotationtools.cpp
+++ b/ui/annotationtools.cpp
@@ -82,8 +82,8 @@ QCursor AnnotatorEngine::cursor() const
return Qt::CrossCursor;
}
-SmoothPath::SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen )
- : points ( points ), pen ( pen )
+SmoothPath::SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity )
+ : points ( points ), pen ( pen ), opacity( opacity )
{
}
@@ -149,8 +149,11 @@ QRect SmoothPathEngine::event( EventType type, Button button, double nX, double
void SmoothPathEngine::paint( QPainter * painter, double xScale, double yScale, const QRect & /*clipRect*/ )
{
+ const double penWidth = m_annotElement.attribute( QStringLiteral("width"), QStringLiteral("1") ).toInt();
+ const qreal opacity = m_annotElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble();
+
// use engine's color for painting
- const SmoothPath path( points, QPen(m_engineColor, 1) );
+ const SmoothPath path( points, QPen( m_engineColor, penWidth ), opacity );
// draw the path
path.paint( painter, xScale, yScale );
@@ -162,6 +165,7 @@ void SmoothPath::paint( QPainter * painter, double xScale, double yScale ) const
if ( points.count() > 1 )
{
painter->setPen( pen );
+ painter->setOpacity( opacity );
QLinkedList<Okular::NormalizedPoint>::const_iterator pIt = points.begin(), pEnd = points.end();
Okular::NormalizedPoint pA = *pIt;
@@ -221,14 +225,13 @@ SmoothPath SmoothPathEngine::endSmoothPath()
{
m_creationCompleted = false;
- double width = 1;
- if ( m_annotElement.hasAttribute( "width" ) )
- width = m_annotElement.attribute( "width" ).toDouble();
-
QColor color( m_annotElement.hasAttribute( "color" ) ?
m_annotElement.attribute( "color" ) : m_engineColor );
- return SmoothPath( points, QPen(color, width) );
+ const int width = m_annotElement.attribute( QStringLiteral("width"), QStringLiteral("2") ).toInt();
+ const qreal opacity = m_annotElement.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") ).toDouble();
+
+ return SmoothPath( points, QPen(color, width), opacity );
}
/* kate: replace-tabs on; indent-width 4; */
diff --git a/ui/annotationtools.h b/ui/annotationtools.h
index a261154..e72e56d 100644
--- a/ui/annotationtools.h
+++ b/ui/annotationtools.h
@@ -72,12 +72,13 @@ class AnnotatorEngine
class SmoothPath
{
public:
- SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen );
+ SmoothPath( const QLinkedList<Okular::NormalizedPoint> &points, const QPen &pen, qreal opacity = 1.0 );
void paint( QPainter * painter, double xScale, double yScale ) const;
private:
const QLinkedList<Okular::NormalizedPoint> points;
const QPen pen;
+ const qreal opacity;
};
/** @short SmoothPathEngine */
diff --git a/ui/data/CMakeLists.txt b/ui/data/CMakeLists.txt
index dade573..e714c40 100644
--- a/ui/data/CMakeLists.txt
+++ b/ui/data/CMakeLists.txt
@@ -4,6 +4,7 @@ add_subdirectory(icons)
# install annotator xml tools description
install(FILES
tools.xml
+ drawingtools.xml
DESTINATION ${KDE_INSTALL_DATADIR}/okular)
# install annotation tool images
diff --git a/ui/data/drawingtools.xml b/ui/data/drawingtools.xml
new file mode 100644
index 0000000..42c2da2
--- /dev/null
+++ b/ui/data/drawingtools.xml
@@ -0,0 +1,41 @@
+<!DOCTYPE okularDrawingTools>
+<!--
+Engine/DrawingTools Types [specific attributes]:
+ [color]
+ SmoothLine
+ [color]
+ [opacity]
+ Ink [width]
+-->
+<drawingTools>
+ <tool id="1">
+ <engine color="#ff0000">
+ <annotation type="Ink" color="#ff0000" width="2" />
+ </engine>
+ </tool>
+ <tool id="2">
+ <engine color="#00ff00">
+ <annotation type="Ink" color="#00ff00" width="2" />
+ </engine>
+ </tool>
+ <tool id="3">
+ <engine color="#0000ff">
+ <annotation type="Ink" color="#0000ff" width="2" />
+ </engine>
+ </tool>
+ <tool id="4">
+ <engine color="#ffff00">
+ <annotation type="Ink" color="#ffff00" width="2" />
+ </engine>
+ </tool>
+ <tool id="5">
+ <engine color="#000000">
+ <annotation type="Ink" color="#000000" width="2" />
+ </engine>
+ </tool>
+ <tool id="6">
+ <engine color="#ffffff">
+ <annotation type="Ink" color="#ffffff" width="2" />
+ </engine>
+ </tool>
+</drawingTools>
diff --git a/ui/drawingtoolselectaction.cpp b/ui/drawingtoolselectaction.cpp
new file mode 100644
index 0000000..2b01b44
--- /dev/null
+++ b/ui/drawingtoolselectaction.cpp
@@ -0,0 +1,182 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+
+#include "drawingtoolselectaction.h"
+
+#include "debug_ui.h"
+#include "settings.h"
+
+#include <KLocalizedString>
+
+#include <QHBoxLayout>
+#include <QPainter>
+#include <QToolButton>
+
+class ColorButton : public QToolButton
+{
+public:
+ explicit ColorButton( QWidget *parent = Q_NULLPTR )
+ : QToolButton( parent )
+ {
+ }
+
+ void setColor( const QColor &color )
+ {
+ QPixmap pm( 25, 25 );
+ pm.fill( color );
+
+ QIcon icon;
+
+ icon.addPixmap( pm, QIcon::Normal, QIcon::Off );
+
+ QPixmap pmSel( pm );
+ QPainter p( &pmSel );
+ QFont font = p.font();
+ font.setPixelSize( pmSel.height() * 0.9 );
+ p.setFont( font );
+
+ // draw check mark
+ const int lightness = ((color.red() * 299) + (color.green() * 587) + (color.blue() * 114)) / 1000;
+ p.setPen( lightness < 128 ? Qt::white : Qt::black );
+ p.drawText( QRect( QPoint( 0, 0 ), pmSel.size() ), Qt::AlignCenter, "\u2713" );
+
+ icon.addPixmap( pmSel, QIcon::Normal, QIcon::On );
+
+ setIcon( icon );
+ }
+};
+
+DrawingToolSelectAction::DrawingToolSelectAction( QObject *parent )
+ : QWidgetAction( parent )
+{
+ QWidget *mainWidget = new QWidget;
+ m_layout = new QHBoxLayout( mainWidget );
+ m_layout->setContentsMargins( 0, 0, 0, 0 );
+
+ loadTools();
+
+ setDefaultWidget( mainWidget );
+}
+
+
+DrawingToolSelectAction::~DrawingToolSelectAction()
+{
+}
+
+void DrawingToolSelectAction::toolButtonClicked()
+{
+ QAbstractButton *button = qobject_cast<QAbstractButton*>( sender() );
+
+ if ( button ) {
+ if ( button->isChecked() ) {
+ Q_FOREACH ( QAbstractButton *btn, m_buttons )
+ {
+ if ( button != btn ) {
+ btn->setChecked( false );
+ }
+ }
+
+ emit changeEngine( button->property( "__document" ).value<QDomElement>() );
+ } else {
+ emit changeEngine( QDomElement() );
+ }
+ }
+}
+
+void DrawingToolSelectAction::loadTools()
+{
+ const QStringList drawingTools = Okular::Settings::drawingTools();
+
+ QDomDocument doc;
+ QDomElement drawingDefinition = doc.createElement( "drawingTools" );
+ foreach ( const QString &drawingXml, drawingTools )
+ {
+ QDomDocument entryParser;
+ if ( entryParser.setContent( drawingXml ) )
+ drawingDefinition.appendChild( doc.importNode( entryParser.documentElement(), true ) );
+ else
+ qCWarning(OkularUiDebug) << "Skipping malformed quick selection XML in QuickSelectionTools setting";
+ }
+
+ int shortcutCounter = 0;
+
+ // Create the AnnotationToolItems from the XML dom tree
+ QDomNode drawingDescription = drawingDefinition.firstChild();
+ while ( drawingDescription.isElement() )
+ {
+ const QDomElement toolElement = drawingDescription.toElement();
+ if ( toolElement.tagName() == "tool" )
+ {
+ QString width;
+ QString colorStr;
+ QString opacity;
+
+ const QDomNodeList engineNodeList = toolElement.elementsByTagName( "engine" );
+ if ( engineNodeList.size() > 0 )
+ {
+ const QDomElement engineEl = engineNodeList.item( 0 ).toElement();
+ if ( engineEl.hasAttribute( QStringLiteral("color") ) )
+ {
+ colorStr = engineEl.attribute( QStringLiteral("color") );
+ }
+
+ const QDomNodeList annotationList = engineEl.elementsByTagName( "annotation" );
+ if ( annotationList.size() > 0 )
+ {
+ const QDomElement annotationEl = annotationList.item( 0 ).toElement();
+ if ( annotationEl.hasAttribute( QStringLiteral("width") ) )
+ {
+ width = annotationEl.attribute( QStringLiteral("width") );
+ opacity = annotationEl.attribute( QStringLiteral("opacity"), QStringLiteral("1.0") );
+ }
+ }
+ }
+
+ QDomDocument doc( QStringLiteral("engine") );
+ QDomElement root = doc.createElement( QStringLiteral("engine") );
+ root.setAttribute( QStringLiteral("color"), colorStr );
+ doc.appendChild( root );
+ QDomElement annElem = doc.createElement( QStringLiteral("annotation") );
+ root.appendChild( annElem );
+ annElem.setAttribute( QStringLiteral("type"), QStringLiteral("Ink") );
+ annElem.setAttribute( QStringLiteral("color"), colorStr );
+ annElem.setAttribute( QStringLiteral("width"), width );
+ annElem.setAttribute( QStringLiteral("opacity"), opacity );
+
+ const QString description = i18n("Toggle Drawing Tool:\n color: %1\n pen width: %2\n opacity: %3%", colorStr, width, opacity.toDouble() * 100);
+
+ shortcutCounter++;
+ const QString shortcut = (shortcutCounter < 10 ? i18n( "Ctrl+%1", shortcutCounter ) :
+ shortcutCounter == 10 ? i18n( "Ctrl+0" ) :
+ QString());
+
+ createToolButton( description, colorStr, root, shortcut );
+ }
+
+ drawingDescription = drawingDescription.nextSibling();
+ }
+}
+
+void DrawingToolSelectAction::createToolButton( const QString &description, const QString &colorName, const QDomElement &root, const QString &shortcut )
+{
+ ColorButton *button = new ColorButton;
+ button->setToolTip( description );
+ button->setCheckable( true );
+ button->setColor( QColor( colorName ) );
+
+ if ( !shortcut.isEmpty() )
+ button->setShortcut( QKeySequence( shortcut ) );
+
+ button->setProperty( "__document", QVariant::fromValue<QDomElement>( root ) );
+
+ m_buttons.append( button );
+ m_layout->addWidget( button );
+
+ connect( button, SIGNAL(clicked()), SLOT(toolButtonClicked()) );
+}
diff --git a/ui/drawingtoolselectaction.h b/ui/drawingtoolselectaction.h
new file mode 100644
index 0000000..44c8295
--- /dev/null
+++ b/ui/drawingtoolselectaction.h
@@ -0,0 +1,42 @@
+/***************************************************************************
+ * Copyright (C) 2015 by Laurent Montel <montel@kde.org> *
+ * *
+ * 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. *
+ ***************************************************************************/
+#ifndef DRAWINGTOOLSELECTACTION_H
+#define DRAWINGTOOLSELECTACTION_H
+
+#include <QDomDocument>
+#include <QWidgetAction>
+
+class QAbstractButton;
+class QButtonGroup;
+class QHBoxLayout;
+
+class DrawingToolSelectAction : public QWidgetAction
+{
+ Q_OBJECT
+public:
+ explicit DrawingToolSelectAction( QObject *parent = Q_NULLPTR );
+ ~DrawingToolSelectAction();
+
+signals:
+ void changeEngine( const QDomElement &doc );
+
+private slots:
+ void toolButtonClicked();
+
+private:
+ void loadTools();
+ void createToolButton( const QString &description, const QString &colorName, const QDomElement &root, const QString &shortcut = QString() );
+
+ QList<QAbstractButton*> m_buttons;
+ QHBoxLayout *m_layout;
+};
+
+Q_DECLARE_METATYPE( QDomElement )
+
+#endif // DRAWINGTOOLSELECTACTION_H
diff --git a/ui/presentationwidget.cpp b/ui/presentationwidget.cpp
index 76ffe82..3d3a87b 100644
--- a/ui/presentationwidget.cpp
+++ b/ui/presentationwidget.cpp
@@ -8,6 +8,7 @@
***************************************************************************/
#include "presentationwidget.h"
+#include "drawingtoolselectaction.h"
// qt/kde includes
#include <QtCore/qloggingcategory.h>
@@ -184,16 +185,17 @@ PresentationWidget::PresentationWidget( QWidget * parent, Okular::Document * doc
setPlayPauseIcon();
addAction( playPauseAct );
m_topBar->addSeparator();
- QAction *drawingAct = collection->action( "presentation_drawing_mode" );
- connect(drawingAct, &QAction::toggled, this, &PresentationWidget::togglePencilMode);
- drawingAct->setEnabled( true );
- m_topBar->addAction( drawingAct );
- addAction( drawingAct );
QAction *eraseDrawingAct = collection->action( "presentation_erase_drawings" );
eraseDrawingAct->setEnabled( true );
connect(eraseDrawingAct, &QAction::triggered, this, &PresentationWidget::clearDrawings);
m_topBar->addAction( eraseDrawingAct );
addAction( eraseDrawingAct );
+
+ m_drawingToolAction = new DrawingToolSelectAction( this );
+ connect( m_drawingToolAction, &DrawingToolSelectAction::changeEngine, this, &PresentationWidget::slotChangeDrawingToolEngine );
+ m_topBar->addAction( m_drawingToolAction );
+ addAction( m_drawingToolAction );
+
QDesktopWidget *desktop = QApplication::desktop();
if ( desktop->numScreens() > 1 )
{
@@ -278,11 +280,6 @@ PresentationWidget::~PresentationWidget()
// remove this widget from document observer
m_document->removeObserver( this );
- QAction *drawingAct = m_ac->action( "presentation_drawing_mode" );
- disconnect( drawingAct, 0, this, 0 );
- drawingAct->setChecked( false );
- drawingAct->setEnabled( false );
-
QAction *eraseDrawingAct = m_ac->action( "presentation_erase_drawings" );
eraseDrawingAct->setEnabled( false );
@@ -684,9 +681,8 @@ void PresentationWidget::mouseReleaseEvent( QMouseEvent * e )
// manually disable and re-enable the pencil mode, so we can do
// cleaning of the actual drawer and create a new one just after
// that - that gives continuous drawing
- togglePencilMode( false );
- togglePencilMode( true );
-
+ slotChangeDrawingToolEngine( QDomElement() );
+ slotChangeDrawingToolEngine( m_currentDrawingToolElement );
// schedule repaint
update();
}
@@ -1491,33 +1487,24 @@ void PresentationWidget::slotPageChanged()
changePage( p - 1 );
}
-void PresentationWidget::togglePencilMode( bool on )
+void PresentationWidget::slotChangeDrawingToolEngine( const QDomElement &element )
{
- if ( on )
- {
- QString colorstring = Okular::Settings::slidesPencilColor().name();
- // FIXME this should not be recreated every time
- QDomDocument doc( QStringLiteral("engine") );
- QDomElement root = doc.createElement( QStringLiteral("engine") );
- root.setAttribute( QStringLiteral("color"), colorstring );
- doc.appendChild( root );
- QDomElement annElem = doc.createElement( QStringLiteral("annotation") );
- root.appendChild( annElem );
- annElem.setAttribute( QStringLiteral("type"), QStringLiteral("Ink") );
- annElem.setAttribute( QStringLiteral("color"), colorstring );
- annElem.setAttribute( QStringLiteral("width"), QStringLiteral("2") );
- m_drawingEngine = new SmoothPathEngine( root );
- setCursor( QCursor( QPixmap(QStringLiteral("pencil")), Qt::ArrowCursor ) );
- }
- else
+ if ( element.isNull() )
{
delete m_drawingEngine;
m_drawingEngine = 0;
m_drawingRect = QRect();
setCursor( Qt::ArrowCursor );
}
+ else
+ {
+ m_drawingEngine = new SmoothPathEngine( element );
+ setCursor( QCursor( QPixmap( QStringLiteral("pencil") ), Qt::ArrowCursor ) );
+ m_currentDrawingToolElement = element;
+ }
}
+
void PresentationWidget::clearDrawings()
{
if ( m_frameIndex != -1 )
diff --git a/ui/presentationwidget.h b/ui/presentationwidget.h
index ffa4b47..fd3d145 100644
--- a/ui/presentationwidget.h
+++ b/ui/presentationwidget.h
@@ -10,6 +10,7 @@
#ifndef _OKULAR_PRESENTATIONWIDGET_H_
#define _OKULAR_PRESENTATIONWIDGET_H_
+#include <QDomElement>
#include <qlist.h>
#include <qpixmap.h>
#include <qstringlist.h>
@@ -21,6 +22,7 @@
class QLineEdit;
class QToolBar;
class QTimer;
+class DrawingToolSelectAction;
class KActionCollection;
class KSelectAction;
class SmoothPathEngine;
@@ -135,6 +137,8 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
PresentationSearchBar *m_searchBar;
KActionCollection * m_ac;
KSelectAction * m_screenSelect;
+ DrawingToolSelectAction *m_drawingToolAction;
+ QDomElement m_currentDrawingToolElement;
bool m_isSetup;
bool m_blockNotifications;
bool m_inBlackScreenMode;
@@ -150,7 +154,6 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
void slotTransitionStep();
void slotDelayedEvents();
void slotPageChanged();
- void togglePencilMode( bool );
void clearDrawings();
void screenResized( int );
void chooseScreen( QAction * );
@@ -158,6 +161,7 @@ class PresentationWidget : public QWidget, public Okular::DocumentObserver
void slotProcessMovieAction( const Okular::MovieAction *action );
void slotProcessRenditionAction( const Okular::RenditionAction *action );
void slotTogglePlayPause();
+ void slotChangeDrawingToolEngine( const QDomElement &doc );
};
#endif