Fix imageclipboard saveImage().

This commit is contained in:
Black Hat 2019-05-19 22:35:08 +08:00
parent 603cb33042
commit 6bf7e7e0c9
5 changed files with 32 additions and 18 deletions

View File

@ -125,7 +125,7 @@ Item {
background: RippleEffect { background: RippleEffect {
onClicked: { onClicked: {
var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png" var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png"
imageClipboard.saveImage(localPath) if (!imageClipboard.saveImage(localPath)) return
roomPanelInput.attach(localPath) roomPanelInput.attach(localPath)
attachDialog.close() attachDialog.close()
} }

View File

@ -301,7 +301,7 @@ Control {
Keys.onReturnPressed: { Keys.onReturnPressed: {
if (event.modifiers & Qt.ShiftModifier) { if (event.modifiers & Qt.ShiftModifier) {
insert(cursorPosition, "\n") insert(cursorPosition, "\n")
} else if (text) { } else {
postMessage(text) postMessage(text)
text = "" text = ""
closeAll() closeAll()
@ -353,7 +353,6 @@ Control {
} }
function postMessage(text) { function postMessage(text) {
if (text.trim().length === 0) { return }
if(!currentRoom) { return } if(!currentRoom) { return }
if (hasAttachment) { if (hasAttachment) {
@ -362,6 +361,8 @@ Control {
return return
} }
if (text.trim().length === 0) { return }
var PREFIX_ME = '/me ' var PREFIX_ME = '/me '
var PREFIX_NOTICE = '/notice ' var PREFIX_NOTICE = '/notice '
var PREFIX_RAINBOW = '/rainbow ' var PREFIX_RAINBOW = '/rainbow '

View File

@ -42,9 +42,7 @@ HEADERS += \
include/hoedown/escape.h \ include/hoedown/escape.h \
include/hoedown/html.h \ include/hoedown/html.h \
include/hoedown/stack.h \ include/hoedown/stack.h \
include/hoedown/version.h \ include/hoedown/version.h
src/imageclipboard.h \
src/matriximageprovider.h
SOURCES += \ SOURCES += \
include/hoedown/autolink.c \ include/hoedown/autolink.c \
@ -55,9 +53,7 @@ SOURCES += \
include/hoedown/html_blocks.c \ include/hoedown/html_blocks.c \
include/hoedown/html_smartypants.c \ include/hoedown/html_smartypants.c \
include/hoedown/stack.c \ include/hoedown/stack.c \
include/hoedown/version.c \ include/hoedown/version.c
src/imageclipboard.cpp \
src/matriximageprovider.cpp
# The following define makes your compiler emit warnings if you use # The following define makes your compiler emit warnings if you use
# any feature of Qt which as been marked deprecated (the exact warnings # any feature of Qt which as been marked deprecated (the exact warnings
@ -128,7 +124,9 @@ HEADERS += \
src/accountlistmodel.h \ src/accountlistmodel.h \
src/spectraluser.h \ src/spectraluser.h \
src/notifications/manager.h \ src/notifications/manager.h \
src/utils.h src/utils.h \
src/imageclipboard.h \
src/matriximageprovider.h
SOURCES += src/main.cpp \ SOURCES += src/main.cpp \
src/controller.cpp \ src/controller.cpp \
@ -139,7 +137,9 @@ SOURCES += src/main.cpp \
src/userlistmodel.cpp \ src/userlistmodel.cpp \
src/accountlistmodel.cpp \ src/accountlistmodel.cpp \
src/spectraluser.cpp \ src/spectraluser.cpp \
src/utils.cpp src/utils.cpp \
src/imageclipboard.cpp \
src/matriximageprovider.cpp
unix:!mac { unix:!mac {
SOURCES += src/notifications/managerlinux.cpp SOURCES += src/notifications/managerlinux.cpp

View File

@ -1,7 +1,10 @@
#include "imageclipboard.h" #include "imageclipboard.h"
#include <QDir>
#include <QFileInfo>
#include <QGuiApplication> #include <QGuiApplication>
#include <QUrl> #include <QUrl>
#include <QtDebug>
ImageClipboard::ImageClipboard(QObject* parent) ImageClipboard::ImageClipboard(QObject* parent)
: QObject(parent), m_clipboard(QGuiApplication::clipboard()) { : QObject(parent), m_clipboard(QGuiApplication::clipboard()) {
@ -17,10 +20,21 @@ QImage ImageClipboard::image() {
return m_clipboard->image(); return m_clipboard->image();
} }
void ImageClipboard::saveImage(const QUrl& localPath) { bool ImageClipboard::saveImage(const QUrl& localPath) {
auto i = image(); if (!localPath.isLocalFile())
return false;
if (i.isNull()) return; auto i = image();
i.save(localPath.toString()); if (i.isNull())
return false;
QString path = QFileInfo(localPath.toString()).absolutePath();
QDir dir;
if (!dir.exists(path))
dir.mkpath(path);
i.save(localPath.toLocalFile());
return true;
} }

View File

@ -16,14 +16,13 @@ class ImageClipboard : public QObject {
bool hasImage(); bool hasImage();
QImage image(); QImage image();
Q_INVOKABLE bool saveImage(const QUrl& localPath);
private: private:
QClipboard* m_clipboard; QClipboard* m_clipboard;
signals: signals:
void imageChanged(); void imageChanged();
public slots:
void saveImage(const QUrl& localPath);
}; };
#endif // IMAGECLIPBOARD_H #endif // IMAGECLIPBOARD_H