From 74c4d63c16a56d374b990dbea895bda1487da614 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 16 Jul 2020 13:54:17 -0400 Subject: [PATCH] Add C++ clipboard image provider Will be used to show a preview before uploading image from clipboard. Transforming the clipboard image to PNG (or any other real format) is slow and freezes the GUI, with the provider we can display it directly. --- TODO.md | 26 +++++++++++++---------- src/clipboard.h | 2 ++ src/clipboard_image_provider.h | 38 ++++++++++++++++++++++++++++++++++ src/main.cpp | 6 ++++++ 4 files changed, 61 insertions(+), 11 deletions(-) create mode 100644 src/clipboard_image_provider.h diff --git a/TODO.md b/TODO.md index d1f41422..4d4f97fd 100644 --- a/TODO.md +++ b/TODO.md @@ -1,24 +1,28 @@ # TODO -- power control focus +- global presence control +- power level control keyboard focus - idlemanager: what if setPresence call fails due to network? -- block power level change when offline +- disable member power level change control when offline - fix power level control button layout when apply button is loading -- joining new DM, not loading past events the first time? +- joining new DM → not loading past events the first time? - fix HLabeledItem disabled opacity + (visible for the topic area in room settings) -- save and restore status in accounts.json +- ~~save and restore status message in accounts.json~~ - mark accounts as offline when closing mirage -- document new x11 dependnecy (auto-idle) -- auto-idle for Windows and OSX -- open context menus centered on touch screens -- retrieve last seen time for offline members on hover/in profile -- status based on process detection -- retry if media not found +- document new libXScreenSaver-devel dependency (for auto-idle) +- retrieve last seen time for offline members on hover/in profile/automatically +- retry if media retrieval request ends up with a 404 - fix members not synced bug - fix local unread counters order -- warn about no E2E room shared if no devices +- member profile: if no devices show up, warn about no E2E rooms shared or + no E2E-aware devices for that member + +- open context menus centered on touch screens +- auto-idle for Windows and OSX +- status based on process detection ## Refactoring diff --git a/src/clipboard.h b/src/clipboard.h index fcb2fe14..f1183543 100644 --- a/src/clipboard.h +++ b/src/clipboard.h @@ -82,6 +82,7 @@ public: } signals: + void contentChanged(); void textChanged(); void imageChanged(); void hasImageChanged(); @@ -91,6 +92,7 @@ private: QClipboard *clipboard = QGuiApplication::clipboard(); void mainClipboardChanged() { + contentChanged(); this->hasImage() ? this->imageChanged() : this->textChanged(); this->hasImageChanged(); }; diff --git a/src/clipboard_image_provider.h b/src/clipboard_image_provider.h new file mode 100644 index 00000000..a1153b74 --- /dev/null +++ b/src/clipboard_image_provider.h @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: LGPL-3.0-or-later + +#ifndef CLIPBOARD_IMAGE_PROVIDER_H +#define CLIPBOARD_IMAGE_PROVIDER_H + +#include +#include +#include + + +class ClipboardImageProvider : public QQuickImageProvider { + +public: + explicit ClipboardImageProvider() + : QQuickImageProvider(QQuickImageProvider::Image) {} + + QImage requestImage( + const QString &id, QSize *size, const QSize &requestSize + ) { + Q_UNUSED(id); + + QImage image = this->clipboard->image(); + + if (size) *size = image.size(); + + if (requestSize.width() > 0 && requestSize.height() > 0) + image = image.scaled( + requestSize.width(), requestSize.height(), Qt::KeepAspectRatio + ); + + return image; + } + +private: + QClipboard *clipboard = QGuiApplication::clipboard(); +}; + +#endif diff --git a/src/main.cpp b/src/main.cpp index 7612edf3..f495a987 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,6 +19,7 @@ #include "utils.h" #include "clipboard.h" +#include "clipboard_image_provider.h" void loggingHandler( @@ -125,6 +126,11 @@ int main(int argc, char *argv[]) { objectContext->setContextProperty("debugMode", false); #endif + // Register out custom image providers. + // QML will be able to request an image from them by setting an + // `Image`'s `source` to `image:///` + engine.addImageProvider("clipboard", new ClipboardImageProvider); + // Register our custom non-visual QObject singletons, // that will be importable anywhere in QML. Example: // import Clipboard 0.1