Fix imageclipboard saveImage().

square-messages
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 {
onClicked: {
var localPath = StandardPaths.writableLocation(StandardPaths.CacheLocation) + "/screenshots/" + (new Date()).getTime() + ".png"
imageClipboard.saveImage(localPath)
if (!imageClipboard.saveImage(localPath)) return
roomPanelInput.attach(localPath)
attachDialog.close()
}

View File

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

View File

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

View File

@ -1,7 +1,10 @@
#include "imageclipboard.h"
#include <QDir>
#include <QFileInfo>
#include <QGuiApplication>
#include <QUrl>
#include <QtDebug>
ImageClipboard::ImageClipboard(QObject* parent)
: QObject(parent), m_clipboard(QGuiApplication::clipboard()) {
@ -17,10 +20,21 @@ QImage ImageClipboard::image() {
return m_clipboard->image();
}
void ImageClipboard::saveImage(const QUrl& localPath) {
auto i = image();
bool ImageClipboard::saveImage(const QUrl& localPath) {
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();
QImage image();
Q_INVOKABLE bool saveImage(const QUrl& localPath);
private:
QClipboard* m_clipboard;
signals:
void imageChanged();
public slots:
void saveImage(const QUrl& localPath);
};
#endif // IMAGECLIPBOARD_H