summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Feck <cfeck@kde.org>2016-09-01 16:32:47 (GMT)
committerChristoph Feck <cfeck@kde.org>2016-09-01 16:32:47 (GMT)
commitc25c21fa4415ff25db49b674ec3003bdcf4c565e (patch)
treee5337ee317be4f405f0e4e212d24748e54879672
parentb4b8b5a383768fc8dea8914a98ab2b5a1b66e7bc (diff)
Add bookmarks support
REVIEW: 128522 FEATURE: 242333
-rw-r--r--CMakeLists.txt3
-rw-r--r--kcharselectdia.cc68
-rw-r--r--kcharselectdia.h2
-rw-r--r--kcharselectui.rc3
4 files changed, 72 insertions, 4 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6db5c66..8b82736 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ find_package (Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
+ Bookmarks
DocTools
I18n
WidgetsAddons
@@ -31,7 +32,7 @@ set(kcharselect_SRCS kcharselectdia.cc main.cc )
add_executable(kcharselect ${kcharselect_SRCS})
-target_link_libraries(kcharselect KF5::I18n KF5::WidgetsAddons KF5::XmlGui )
+target_link_libraries(kcharselect KF5::Bookmarks KF5::I18n KF5::WidgetsAddons KF5::XmlGui )
install(TARGETS kcharselect ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} )
diff --git a/kcharselectdia.cc b/kcharselectdia.cc
index 28d65f9..a80dfb1 100644
--- a/kcharselectdia.cc
+++ b/kcharselectdia.cc
@@ -19,12 +19,16 @@
#include <QAction>
#include <QApplication>
-#include <QFontDatabase>
-#include <QIcon>
#include <QClipboard>
+#include <QDir>
+#include <QFontDatabase>
#include <QGridLayout>
+#include <QIcon>
+#include <QMenu>
#include <KActionCollection>
+#include <KBookmarkManager>
+#include <KBookmarkMenu>
#include <KConfigGroup>
#include <KLocalizedString>
#include <KStandardAction>
@@ -32,6 +36,51 @@
#include <KSharedConfig>
#include <KToggleAction>
+class KCharSelectBookmarkOwner : public KBookmarkOwner
+{
+public:
+ KCharSelectBookmarkOwner(KCharSelectDia *dia)
+ : d(dia) { }
+ ~KCharSelectBookmarkOwner() { }
+
+ QString currentTitle() const Q_DECL_OVERRIDE
+ {
+ uint ucs4 = d->charSelect->currentCodePoint();
+ if (QChar::isPrint(ucs4)) {
+ return QString::fromUcs4(&ucs4, 1) + QLatin1Char(' ') + formatCodePoint(ucs4);
+ } else {
+ return formatCodePoint(ucs4);
+ }
+ }
+
+ QUrl currentUrl() const Q_DECL_OVERRIDE
+ {
+ return QUrl(formatCodePoint(d->charSelect->currentCodePoint()));
+ }
+
+ void openBookmark(const KBookmark &bm, Qt::MouseButtons, Qt::KeyboardModifiers) Q_DECL_OVERRIDE
+ {
+ QString c = bm.url().toString(QUrl::PreferLocalFile | QUrl::RemoveScheme);
+ if (c.startsWith(QLatin1String("U+"))) {
+ uint uc = c.mid(2).toUInt(Q_NULLPTR, 16);
+ d->charSelect->setCurrentCodePoint(uc);
+ }
+ }
+
+private:
+ static QString formatCodePoint(uint ucs4)
+ {
+ QString c = QString::number(ucs4, 16).toUpper();
+ while (c.length() < 4) {
+ c.prepend(QLatin1Char('0'));
+ }
+ return QStringLiteral("U+") + c;
+ }
+
+private:
+ KCharSelectDia *d;
+};
+
/******************************************************************/
/* class KCharSelectDia */
/******************************************************************/
@@ -124,6 +173,21 @@ KCharSelectDia::KCharSelectDia()
else
lined->setAlignment( Qt::AlignLeft );
+ QString filename = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kcharselect/bookmarks.xml"));
+ if (filename.isEmpty()) {
+ filename = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kcharselect");
+ QDir().mkpath(filename);
+ filename += QStringLiteral("/bookmarks.xml");
+ }
+ KBookmarkManager* manager = KBookmarkManager::managerForFile(filename, QStringLiteral("kcharselect"));
+
+ action = actionCollection()->addAction(QStringLiteral("bookmarks"));
+ action->setText(i18n("Bookmarks"));
+ QMenu *bmmenu = new QMenu(this);
+ action->setMenu(bmmenu);
+ KBookmarkMenu *bm = new KBookmarkMenu(manager, new KCharSelectBookmarkOwner(this), bmmenu, actionCollection());
+ bm->setParent(this);
+
setupGUI(ToolBar|Keys|Save|Create);
}
diff --git a/kcharselectdia.h b/kcharselectdia.h
index 27515a4..c6ec519 100644
--- a/kcharselectdia.h
+++ b/kcharselectdia.h
@@ -35,6 +35,8 @@ class KCharSelectDia : public KXmlGuiWindow
public:
KCharSelectDia();
+ friend class KCharSelectBookmarkOwner;
+
protected:
void closeEvent(QCloseEvent *event);
diff --git a/kcharselectui.rc b/kcharselectui.rc
index d8556ee..ded1c42 100644
--- a/kcharselectui.rc
+++ b/kcharselectui.rc
@@ -1,5 +1,5 @@
<!DOCTYPE kpartgui>
-<kpartgui name="kcharselect" version="2">
+<kpartgui name="kcharselect" version="3">
<MenuBar>
<Menu name="edit"><text>&amp;Edit</text>
<Action name="copy_clip"/>
@@ -11,6 +11,7 @@
<Action name="flip"/>
<Action name="rtl"/>
</Menu>
+ <Action name="bookmarks" />
</MenuBar>
<ToolBar name="mainToolBar" hidden="true">
<text>Main Toolbar</text>