Transform Clipboard to singleton and add rich text copying feature
This commit is contained in:
@@ -209,7 +209,7 @@ Control {
|
|||||||
icon.name: "mail-attachment"
|
icon.name: "mail-attachment"
|
||||||
|
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (imageClipboard.hasImage) {
|
if (Clipboard.hasImage) {
|
||||||
attachDialog.open()
|
attachDialog.open()
|
||||||
} else {
|
} else {
|
||||||
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
|
var fileDialog = openFileDialog.createObject(ApplicationWindow.overlay)
|
||||||
|
|||||||
@@ -5,13 +5,14 @@ import Qt.labs.qmlmodels 1.0
|
|||||||
import QtQuick.Controls.Material 2.12
|
import QtQuick.Controls.Material 2.12
|
||||||
|
|
||||||
import org.kde.kirigami 2.4 as Kirigami
|
import org.kde.kirigami 2.4 as Kirigami
|
||||||
|
|
||||||
import org.kde.kitemmodels 1.0
|
import org.kde.kitemmodels 1.0
|
||||||
|
import org.kde.neochat 1.0
|
||||||
|
|
||||||
import Spectral.Component 2.0
|
import Spectral.Component 2.0
|
||||||
import Spectral.Component.Timeline 2.0
|
import Spectral.Component.Timeline 2.0
|
||||||
import Spectral.Dialog 2.0
|
import Spectral.Dialog 2.0
|
||||||
import Spectral.Effect 2.0
|
import Spectral.Effect 2.0
|
||||||
|
import Spectral.Menu.Timeline 2.0
|
||||||
import Spectral 0.1
|
import Spectral 0.1
|
||||||
|
|
||||||
Kirigami.ScrollablePage {
|
Kirigami.ScrollablePage {
|
||||||
@@ -27,10 +28,6 @@ Kirigami.ScrollablePage {
|
|||||||
room: currentRoom
|
room: currentRoom
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageClipboard {
|
|
||||||
id: imageClipboard
|
|
||||||
}
|
|
||||||
|
|
||||||
QQC2.Popup {
|
QQC2.Popup {
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
||||||
@@ -74,7 +71,7 @@ Kirigami.ScrollablePage {
|
|||||||
text: i18n("Clipboard image")
|
text: i18n("Clipboard image")
|
||||||
onClicked: {
|
onClicked: {
|
||||||
var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png"
|
var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png"
|
||||||
if (!imageClipboard.saveImage(localPath)) return
|
if (!Clipboard.saveImage(localPath)) return
|
||||||
chatTextInput.attach(localPath)
|
chatTextInput.attach(localPath)
|
||||||
attachDialog.close()
|
attachDialog.close()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ add_executable(neochat
|
|||||||
accountlistmodel.cpp
|
accountlistmodel.cpp
|
||||||
controller.cpp
|
controller.cpp
|
||||||
emojimodel.cpp
|
emojimodel.cpp
|
||||||
imageclipboard.cpp
|
clipboard.cpp
|
||||||
matriximageprovider.cpp
|
matriximageprovider.cpp
|
||||||
messageeventmodel.cpp
|
messageeventmodel.cpp
|
||||||
roomlistmodel.cpp
|
roomlistmodel.cpp
|
||||||
|
|||||||
@@ -3,32 +3,35 @@
|
|||||||
*
|
*
|
||||||
* SPDX-LicenseIdentifier: GPL-3.0-only
|
* SPDX-LicenseIdentifier: GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
#include "imageclipboard.h"
|
#include "clipboard.h"
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QClipboard>
|
||||||
|
#include <QMimeData>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QImage>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
|
||||||
ImageClipboard::ImageClipboard(QObject *parent)
|
Clipboard::Clipboard(QObject *parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, m_clipboard(QGuiApplication::clipboard())
|
, m_clipboard(QGuiApplication::clipboard())
|
||||||
{
|
{
|
||||||
connect(m_clipboard, &QClipboard::changed, this, &ImageClipboard::imageChanged);
|
connect(m_clipboard, &QClipboard::changed, this, &Clipboard::imageChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageClipboard::hasImage() const
|
bool Clipboard::hasImage() const
|
||||||
{
|
{
|
||||||
return !image().isNull();
|
return !image().isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
QImage ImageClipboard::image() const
|
QImage Clipboard::image() const
|
||||||
{
|
{
|
||||||
return m_clipboard->image();
|
return m_clipboard->image();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ImageClipboard::saveImage(const QUrl &localPath)
|
bool Clipboard::saveImage(const QUrl &localPath)
|
||||||
{
|
{
|
||||||
if (!localPath.isLocalFile())
|
if (!localPath.isLocalFile())
|
||||||
return false;
|
return false;
|
||||||
@@ -48,3 +51,12 @@ bool ImageClipboard::saveImage(const QUrl &localPath)
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Clipboard::saveText(QString message)
|
||||||
|
{
|
||||||
|
QRegularExpression re("<[^>]*>");
|
||||||
|
auto *mineData = new QMimeData; // ownership is transfered to clipboard
|
||||||
|
mineData->setHtml(message);
|
||||||
|
mineData->setText(message.replace(re, ""));
|
||||||
|
m_clipboard->setMimeData(mineData);
|
||||||
|
}
|
||||||
@@ -3,32 +3,35 @@
|
|||||||
*
|
*
|
||||||
* SPDX-LicenseIdentifier: GPL-3.0-only
|
* SPDX-LicenseIdentifier: GPL-3.0-only
|
||||||
*/
|
*/
|
||||||
#ifndef IMAGECLIPBOARD_H
|
#pragma once
|
||||||
#define IMAGECLIPBOARD_H
|
|
||||||
|
|
||||||
#include <QClipboard>
|
|
||||||
#include <QImage>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
class ImageClipboard : public QObject
|
class QClipboard;
|
||||||
|
class QImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clipboard proxy
|
||||||
|
*/
|
||||||
|
class Clipboard : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool hasImage READ hasImage NOTIFY imageChanged)
|
Q_PROPERTY(bool hasImage READ hasImage NOTIFY imageChanged)
|
||||||
Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
|
Q_PROPERTY(QImage image READ image NOTIFY imageChanged)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit ImageClipboard(QObject *parent = nullptr);
|
explicit Clipboard(QObject *parent = nullptr);
|
||||||
|
|
||||||
bool hasImage() const;
|
bool hasImage() const;
|
||||||
QImage image() const;
|
QImage image() const;
|
||||||
|
|
||||||
Q_INVOKABLE bool saveImage(const QUrl &localPath);
|
Q_INVOKABLE bool saveImage(const QUrl &localPath);
|
||||||
|
|
||||||
|
Q_INVOKABLE void saveText(QString message);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QClipboard *m_clipboard;
|
QClipboard *m_clipboard;
|
||||||
|
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void imageChanged();
|
void imageChanged();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // IMAGECLIPBOARD_H
|
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
#include "csapi/joining.h"
|
#include "csapi/joining.h"
|
||||||
#include "csapi/leaving.h"
|
#include "csapi/leaving.h"
|
||||||
#include "emojimodel.h"
|
#include "emojimodel.h"
|
||||||
#include "imageclipboard.h"
|
#include "clipboard.h"
|
||||||
#include "matriximageprovider.h"
|
#include "matriximageprovider.h"
|
||||||
#include "messageeventmodel.h"
|
#include "messageeventmodel.h"
|
||||||
#include "notificationsmanager.h"
|
#include "notificationsmanager.h"
|
||||||
@@ -57,7 +57,10 @@ int main(int argc, char *argv[])
|
|||||||
app.setOrganizationName("KDE");
|
app.setOrganizationName("KDE");
|
||||||
app.setWindowIcon(QIcon(":/assets/img/icon.png"));
|
app.setWindowIcon(QIcon(":/assets/img/icon.png"));
|
||||||
|
|
||||||
|
Clipboard clipboard;
|
||||||
|
|
||||||
qmlRegisterSingletonInstance("Spectral", 0, 1, "Controller", &Controller::instance());
|
qmlRegisterSingletonInstance("Spectral", 0, 1, "Controller", &Controller::instance());
|
||||||
|
qmlRegisterSingletonInstance("org.kde.neochat", 1, 0, "Clipboard", &clipboard);
|
||||||
qmlRegisterType<AccountListModel>("Spectral", 0, 1, "AccountListModel");
|
qmlRegisterType<AccountListModel>("Spectral", 0, 1, "AccountListModel");
|
||||||
qmlRegisterType<RoomListModel>("Spectral", 0, 1, "RoomListModel");
|
qmlRegisterType<RoomListModel>("Spectral", 0, 1, "RoomListModel");
|
||||||
qmlRegisterType<UserListModel>("Spectral", 0, 1, "UserListModel");
|
qmlRegisterType<UserListModel>("Spectral", 0, 1, "UserListModel");
|
||||||
@@ -67,7 +70,6 @@ int main(int argc, char *argv[])
|
|||||||
qmlRegisterType<EmojiModel>("Spectral", 0, 1, "EmojiModel");
|
qmlRegisterType<EmojiModel>("Spectral", 0, 1, "EmojiModel");
|
||||||
qmlRegisterType<NotificationsManager>("Spectral", 0, 1, "NotificationsManager");
|
qmlRegisterType<NotificationsManager>("Spectral", 0, 1, "NotificationsManager");
|
||||||
qmlRegisterType<TrayIcon>("Spectral", 0, 1, "TrayIcon");
|
qmlRegisterType<TrayIcon>("Spectral", 0, 1, "TrayIcon");
|
||||||
qmlRegisterType<ImageClipboard>("Spectral", 0, 1, "ImageClipboard");
|
|
||||||
qmlRegisterUncreatableType<RoomMessageEvent>("Spectral", 0, 1, "RoomMessageEvent", "ENUM");
|
qmlRegisterUncreatableType<RoomMessageEvent>("Spectral", 0, 1, "RoomMessageEvent", "ENUM");
|
||||||
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
|
qmlRegisterUncreatableType<RoomType>("Spectral", 0, 1, "RoomType", "ENUM");
|
||||||
qmlRegisterUncreatableType<UserType>("Spectral", 0, 1, "UserType", "ENUM");
|
qmlRegisterUncreatableType<UserType>("Spectral", 0, 1, "UserType", "ENUM");
|
||||||
|
|||||||
Reference in New Issue
Block a user