From bbdc16c5c90186a63133c1d8cbb52dfb6dc48494 Mon Sep 17 00:00:00 2001 From: miruka Date: Fri, 12 Jun 2020 14:10:11 -0400 Subject: [PATCH] Merge clipboard.h and clipboard.cpp --- mirage.pro | 6 ++---- src/clipboard.cpp | 44 -------------------------------------------- src/clipboard.h | 40 ++++++++++++++++++++++++++++++++-------- 3 files changed, 34 insertions(+), 56 deletions(-) delete mode 100644 src/clipboard.cpp diff --git a/mirage.pro b/mirage.pro index 37c26fb1..e475b289 100644 --- a/mirage.pro +++ b/mirage.pro @@ -12,10 +12,8 @@ RCC_DIR = $$BUILD_DIR/rcc QRC_FILE = $$BUILD_DIR/resources.qrc RESOURCES += $$QRC_FILE -HEADERS += src/utils.h src/clipboard.h \ - submodules/hsluv-c/src/hsluv.h -SOURCES += src/main.cpp src/clipboard.cpp \ - submodules/hsluv-c/src/hsluv.c +HEADERS += src/utils.h src/clipboard.h submodules/hsluv-c/src/hsluv.h +SOURCES += src/main.cpp submodules/hsluv-c/src/hsluv.c TARGET = mirage diff --git a/src/clipboard.cpp b/src/clipboard.cpp deleted file mode 100644 index 86453c63..00000000 --- a/src/clipboard.cpp +++ /dev/null @@ -1,44 +0,0 @@ -// SPDX-License-Identifier: LGPL-3.0-or-later - -// Function implementations of the Clipboard class, see the clipboard.h file. - -#include -#include "clipboard.h" - - -Clipboard::Clipboard(QObject *parent) - : QObject(parent) { - - connect(m_clipboard, &QClipboard::dataChanged, - this, &Clipboard::textChanged); - - connect(m_clipboard, &QClipboard::selectionChanged, - this, &Clipboard::selectionChanged); -} - - -QString Clipboard::text() const { - return m_clipboard->text(QClipboard::Clipboard); -} - - -void Clipboard::setText(const QString &text) { - m_clipboard->setText(text, QClipboard::Clipboard); -} - - -QString Clipboard::selection() const { - return m_clipboard->text(QClipboard::Selection); -} - - -void Clipboard::setSelection(const QString &text) { - if (m_clipboard->supportsSelection()) { - m_clipboard->setText(text, QClipboard::Selection); - } -} - - -bool Clipboard::supportsSelection() const { - return m_clipboard->supportsSelection(); -} diff --git a/src/clipboard.h b/src/clipboard.h index b552f7da..c608e42d 100644 --- a/src/clipboard.h +++ b/src/clipboard.h @@ -7,6 +7,7 @@ #define CLIPBOARD_H #include +#include #include @@ -20,25 +21,48 @@ class Clipboard : public QObject Q_PROPERTY(bool supportsSelection READ supportsSelection CONSTANT) public: - explicit Clipboard(QObject *parent = 0); + explicit Clipboard(QObject *parent = nullptr) : QObject(parent) { + connect(this->clipboard, &QClipboard::dataChanged, + this, &Clipboard::textChanged); + + connect(this->clipboard, &QClipboard::selectionChanged, + this, &Clipboard::selectionChanged); + } // Normal primary clipboard - QString text() const; - void setText(const QString &text); + + QString text() const { + return this->clipboard->text(QClipboard::Clipboard); + } + + void setText(const QString &text) const { + this->clipboard->setText(text, QClipboard::Clipboard); + } // X11 select-middle-click-paste clipboard - QString selection() const; - void setSelection(const QString &text); - bool supportsSelection() const; + QString selection() const { + return this->clipboard->text(QClipboard::Selection); + } + + void setSelection(const QString &text) const { + if (this->clipboard->supportsSelection()) { + this->clipboard->setText(text, QClipboard::Selection); + } + } + + // Info + + bool supportsSelection() const { + return this->clipboard->supportsSelection(); + } signals: void textChanged(); void selectionChanged(); private: - QClipboard *m_clipboard = QGuiApplication::clipboard(); + QClipboard *clipboard = QGuiApplication::clipboard(); }; - #endif