summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKai Uwe Broulik <kde@privat.broulik.de>2016-09-27 12:49:40 (GMT)
committerKai Uwe Broulik <kde@privat.broulik.de>2016-09-27 12:49:40 (GMT)
commit8328a1295a7bded16549998411af2446d774dc79 (patch)
treee755a5c445dc04ad011f207bb4ce14f57fe9fd12
parent6a4906090db93923b203dfba6bd2a9f681e03e49 (diff)
[Quick Chat] Add context menu for copying text and links
This allows to copy links by right clicking them and copying individual text snippets to the clipboard. REVIEW: 128089
-rw-r--r--chat/org.kde.ktp-chat/contents/ui/ChatWidget.qml43
-rw-r--r--chat/org.kde.ktp-chat/contents/ui/TextDelegate.qml7
-rw-r--r--chat/qmlplugin/CMakeLists.txt2
-rw-r--r--chat/qmlplugin/htmlhelper.cpp36
-rw-r--r--chat/qmlplugin/htmlhelper.h33
-rw-r--r--chat/qmlplugin/qmlplugin.cpp7
6 files changed, 125 insertions, 3 deletions
diff --git a/chat/org.kde.ktp-chat/contents/ui/ChatWidget.qml b/chat/org.kde.ktp-chat/contents/ui/ChatWidget.qml
index 7e41910..5ce61e2 100644
--- a/chat/org.kde.ktp-chat/contents/ui/ChatWidget.qml
+++ b/chat/org.kde.ktp-chat/contents/ui/ChatWidget.qml
@@ -23,6 +23,8 @@ import QtQuick.Layouts 1.1
import org.kde.telepathy 0.1
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.plasma.components 2.0 as PlasmaComponents
+import org.kde.kquickcontrolsaddons 2.0 as KQC
+import org.kde.ktpchat 0.1 as KTpChat
FocusScope {
id: chatWidget
@@ -125,6 +127,14 @@ FocusScope {
source = "TextDelegate.qml";
}
}
+
+ Connections {
+ target: item
+ ignoreUnknownSignals: true
+ onContextMenuRequested: {
+ contextMenu.show(item, x, y, item.linkAt(x, y))
+ }
+ }
}
model: conv.messages
@@ -137,6 +147,39 @@ FocusScope {
}
}
+ KQC.Clipboard {
+ id: clipboard
+ }
+
+ PlasmaComponents.ContextMenu {
+ id: contextMenu
+ property url link
+
+ function show(item, x, y, link) {
+ contextMenu.link = link || ""
+ visualParent = item
+ open(x, y)
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Copy Link")
+ visible: contextMenu.link != ""
+ onClicked: clipboard.content = contextMenu.link
+ }
+
+ PlasmaComponents.MenuItem {
+ separator: true
+ visible: contextMenu.link != ""
+ }
+
+ PlasmaComponents.MenuItem {
+ text: i18n("Copy Text")
+ icon: "edit-copy"
+ enabled: contextMenu.visualParent && contextMenu.visualParent.text !== ""
+ onClicked: clipboard.content = KTpChat.HtmlHelper.decode(contextMenu.visualParent.text)
+ }
+ }
+
PlasmaComponents.Label {
id: disconnectedLabel
visible: !conv.valid
diff --git a/chat/org.kde.ktp-chat/contents/ui/TextDelegate.qml b/chat/org.kde.ktp-chat/contents/ui/TextDelegate.qml
index fc2ead1..ea205df 100644
--- a/chat/org.kde.ktp-chat/contents/ui/TextDelegate.qml
+++ b/chat/org.kde.ktp-chat/contents/ui/TextDelegate.qml
@@ -22,6 +22,9 @@ import org.kde.plasma.components 2.0 as PlasmaComponents
PlasmaComponents.Label {
id: body
+
+ signal contextMenuRequested(int x, int y)
+
wrapMode: Text.Wrap
width: view.width
@@ -56,7 +59,7 @@ PlasmaComponents.Label {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
- //we just want to know if the mouse is there, otherwise prevents links from being clicked
- acceptedButtons: Qt.NoButton
+ acceptedButtons: Qt.NoButton | Qt.RightButton
+ onClicked: body.contextMenuRequested(mouse.x, mouse.y)
}
}
diff --git a/chat/qmlplugin/CMakeLists.txt b/chat/qmlplugin/CMakeLists.txt
index 52e79a0..145e164 100644
--- a/chat/qmlplugin/CMakeLists.txt
+++ b/chat/qmlplugin/CMakeLists.txt
@@ -1,4 +1,4 @@
-add_library (ktpchatplugin SHARED hide-window-component.cpp qmlplugin.cpp)
+add_library (ktpchatplugin SHARED hide-window-component.cpp htmlhelper.cpp qmlplugin.cpp)
target_link_libraries (ktpchatplugin
Qt5::Qml
diff --git a/chat/qmlplugin/htmlhelper.cpp b/chat/qmlplugin/htmlhelper.cpp
new file mode 100644
index 0000000..ec0e396
--- /dev/null
+++ b/chat/qmlplugin/htmlhelper.cpp
@@ -0,0 +1,36 @@
+/*
+ Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#include "htmlhelper.h"
+
+#include <QTextDocument>
+#include <QDebug>
+
+HtmlHelper::HtmlHelper(QObject *parent) : QObject(parent)
+{
+
+}
+
+HtmlHelper::~HtmlHelper() = default;
+
+QString HtmlHelper::decode(const QString &text) const
+{
+ QTextDocument doc;
+ doc.setHtml(text);
+ return doc.toPlainText();
+}
diff --git a/chat/qmlplugin/htmlhelper.h b/chat/qmlplugin/htmlhelper.h
new file mode 100644
index 0000000..76082ae
--- /dev/null
+++ b/chat/qmlplugin/htmlhelper.h
@@ -0,0 +1,33 @@
+/*
+ Copyright (C) 2016 Kai Uwe Broulik <kde@privat.broulik.de>
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+*/
+
+#pragma once
+
+#include <QObject>
+
+class HtmlHelper : public QObject
+{
+ Q_OBJECT
+
+ public:
+ explicit HtmlHelper(QObject *parent = nullptr);
+ ~HtmlHelper() override;
+
+ Q_INVOKABLE QString decode(const QString &text) const;
+
+};
diff --git a/chat/qmlplugin/qmlplugin.cpp b/chat/qmlplugin/qmlplugin.cpp
index 71a6495..eb1fce6 100644
--- a/chat/qmlplugin/qmlplugin.cpp
+++ b/chat/qmlplugin/qmlplugin.cpp
@@ -19,6 +19,12 @@
#include <QQmlExtensionPlugin>
#include <qqml.h>
#include "hide-window-component.h"
+#include "htmlhelper.h"
+
+static QObject *htmlHelper_singleton_provider(QQmlEngine *, QJSEngine *)
+{
+ return new HtmlHelper();
+}
class QmlPlugins : public QQmlExtensionPlugin
{
@@ -29,6 +35,7 @@ class QmlPlugins : public QQmlExtensionPlugin
virtual void initializeEngine(QQmlEngine */*engine*/, const char */*uri*/) {}
virtual void registerTypes(const char *uri) {
qmlRegisterType<HideWindowComponent>(uri, 0, 1, "HideWindowComponent");
+ qmlRegisterSingletonType<HtmlHelper>(uri, 0, 1, "HtmlHelper", htmlHelper_singleton_provider);
}
};