From 135300b89a96b7a0d711f4dacd6bc4bf6aac2487 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 13:10:49 +0200 Subject: [PATCH 01/11] Ohhhh that's why Retina did not work properly... --- cropeditor/cropeditor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index cedd54b..5f20816 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -13,7 +13,7 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { view = new CropView(scene); QPixmap *scaled = new QPixmap(); image->scaled(view->width(), view->height()).swap(*scaled); - pixmapItem = new QGraphicsPixmapItem(*image); + pixmapItem = new QGraphicsPixmapItem(*scaled); pixmapItem->setZValue(-1); scene->addItem(pixmapItem); scene->setSceneRect(image->rect()); From 5cc16b47d0cafa6861edc178d5ebb3d9f6865a2d Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 15:56:52 +0200 Subject: [PATCH 02/11] How does one retina? --- cropeditor/cropeditor.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index 5f20816..61c3f53 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -2,22 +2,22 @@ #include "cropscene.hpp" #include "cropview.hpp" +#include #include #include #include +#include #include #include CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { scene = new CropScene(parent, image); view = new CropView(scene); - QPixmap *scaled = new QPixmap(); - image->scaled(view->width(), view->height()).swap(*scaled); - pixmapItem = new QGraphicsPixmapItem(*scaled); + qreal ratio = QApplication::primaryScreen()->devicePixelRatio(); + pixmapItem = new QGraphicsPixmapItem(image->scaled(image->width() / ratio, image->height() / ratio)); pixmapItem->setZValue(-1); scene->addItem(pixmapItem); scene->setSceneRect(image->rect()); - view->setGeometry(0, 0, image->width(), image->height()); view->showFullScreen(); QTimer::singleShot(0, [&] { view->showFullScreen(); }); From d17864ea22861522865406660c3854ab85561a47 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 18:32:55 +0200 Subject: [PATCH 03/11] Turns out this was broken for a while now --- uploaders/default/imguruploader.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uploaders/default/imguruploader.cpp b/uploaders/default/imguruploader.cpp index c9c94f7..2312bfa 100644 --- a/uploaders/default/imguruploader.cpp +++ b/uploaders/default/imguruploader.cpp @@ -19,6 +19,6 @@ void ImgurUploader::doUpload(QPixmap *pixmap) { QString result = res.object()["data"].toObject()["link"].toString(); screenshotutil::toClipboard(result); notifications::notify("KShare imgur Uploader ", - result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!"); + result.isEmpty() ? "Failed upload!" : "Uploaded to imgur!"); }); } From d8f5f9b291135974491e8c3b5c8762c1e2ed73fd Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 18:50:54 +0200 Subject: [PATCH 04/11] Make sure `Cancel` does not reset the hotkey. --- mainwindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mainwindow.cpp b/mainwindow.cpp index 37795b2..c83001a 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -152,8 +152,9 @@ void MainWindow::on_hotkeys_doubleClicked(const QModelIndex &) { if (ui->hotkeys->selectedItems().length() == 1) { QListWidgetItem *i = ui->hotkeys->selectedItems().at(0); QString str = i->data(Qt::UserRole + 1).toString(); + bool ok; QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal, - hotkeying::sequence(str)); - if (hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str)); + hotkeying::sequence(str), &ok); + if (ok && hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str)); } } From a4d17949dc0167e190a9211284ab4d8e66082ef2 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 18:54:13 +0200 Subject: [PATCH 05/11] fuck --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index 718d139..a0d4510 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setApplicationName("KShare"); a.setOrganizationName("ArsenArsen"); - a.setApplicationVersion("1.1"); + a.setApplicationVersion("2.1"); QCommandLineParser parser; parser.addHelpOption(); From e47b69a9c57f5afcd0c21bb318010d6ef3b6f9cb Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 19:19:56 +0200 Subject: [PATCH 06/11] Quick mode --- cropeditor/cropscene.cpp | 3 ++- mainwindow.cpp | 12 ++++++++++++ mainwindow.hpp | 4 ++++ mainwindow.ui | 18 ++++++++++++++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index fe87e2d..cad1c59 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -142,7 +142,8 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) { drawingSelection = drawingSelectionMaker(); if (drawingSelection) if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; }); - } + } else if (settings::settings().value("quickMode", false).toBool()) + done(); prevButtons = Qt::NoButton; } diff --git a/mainwindow.cpp b/mainwindow.cpp index c83001a..8aa69a0 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -3,8 +3,10 @@ #include "screenshotutil.hpp" #include "ui_mainwindow.h" #include +#include #include #include +#include #include #include #include @@ -80,6 +82,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi addHotkeyItem("Fullscreen image", "fullscreen", new std::function([] { screenshotter::fullscreen(); })); addHotkeyItem("Area image", "area", new std::function([] { screenshotter::area(); })); + + ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool()); } MainWindow::~MainWindow() { @@ -158,3 +162,11 @@ void MainWindow::on_hotkeys_doubleClicked(const QModelIndex &) { if (ok && hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str)); } } + +void MainWindow::on_settingsButton_clicked() { + QDesktopServices::openUrl(QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + "/KShare")); +} + +void MainWindow::on_quickMode_clicked(bool checked) { + settings::settings().setValue("quickMode", checked); +} diff --git a/mainwindow.hpp b/mainwindow.hpp index 382857a..2395741 100644 --- a/mainwindow.hpp +++ b/mainwindow.hpp @@ -30,6 +30,10 @@ class MainWindow : public QMainWindow { void on_hotkeys_doubleClicked(const QModelIndex &index); + void on_settingsButton_clicked(); + + void on_quickMode_clicked(bool checked); + public: explicit MainWindow(QWidget *parent = 0); ~MainWindow(); diff --git a/mainwindow.ui b/mainwindow.ui index 7997841..c1af1bf 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -7,7 +7,7 @@ 0 0 512 - 304 + 337 @@ -25,7 +25,7 @@ - + <a href="https://github.com/ArsenArsen/KShare">Source code available free for everyone. Forever.</a> @@ -91,6 +91,20 @@ + + + + Quick mode (mouse release screenshots) + + + + + + + Open settings directory + + + From c76eeec89b3d1318b03eb6e123dd52a39f78aa6a Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 19:21:15 +0200 Subject: [PATCH 07/11] This time I didn't forget to up the version number --- main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.cpp b/main.cpp index a0d4510..65f5506 100644 --- a/main.cpp +++ b/main.cpp @@ -33,7 +33,7 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setApplicationName("KShare"); a.setOrganizationName("ArsenArsen"); - a.setApplicationVersion("2.1"); + a.setApplicationVersion("3.0"); QCommandLineParser parser; parser.addHelpOption(); From 9e2c588c9e93ce4938f5b62f7ea90876bc33a2d1 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 19:31:55 +0200 Subject: [PATCH 08/11] Add version option (maybe Ill stop forgetting now) --- main.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/main.cpp b/main.cpp index 65f5506..411791a 100644 --- a/main.cpp +++ b/main.cpp @@ -40,9 +40,17 @@ int main(int argc, char *argv[]) { QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray."); QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs"); + QCommandLineOption ver({ "ver", "version" }, "Prints KShare version"); parser.addOption(h); parser.addOption(v); + parser.addOption(ver); parser.process(a); + + if (parser.isSet(ver)) { + printf("%s %s\n", a.applicationName().toLocal8Bit().constData(), a.applicationVersion().toLocal8Bit().constData()); + return 0; + } + verbose = parser.isSet(v); MainWindow w; From 45b1c6f2dcfa315ed6468a1078d337d9e8c98a84 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 22:39:05 +0200 Subject: [PATCH 09/11] // maybe that works --- io/ioutils.cpp | 12 ++++++++---- io/ioutils.hpp | 7 +++++-- mainwindow.cpp | 4 +++- uploaders/customuploader.cpp | 5 +++-- uploaders/default/imguruploader.cpp | 2 +- 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/io/ioutils.cpp b/io/ioutils.cpp index e1eccb9..e42000b 100644 --- a/io/ioutils.cpp +++ b/io/ioutils.cpp @@ -8,14 +8,17 @@ namespace ioutils { QNetworkAccessManager networkManager; } -void ioutils::getJson(QUrl target, QList> headers, std::function callback) { +void ioutils::getJson(QUrl target, + QList> headers, + std::function callback) { QNetworkRequest req(target); for (auto header : headers) { req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); } QNetworkReply *reply = networkManager.get(req); QObject::connect(reply, &QNetworkReply::finished, [reply, callback] { - callback(QJsonDocument::fromJson(reply->readAll()), reply); + QByteArray data = reply->readAll(); + callback(QJsonDocument::fromJson(data), data, reply); reply->deleteLater(); }); } @@ -23,14 +26,15 @@ void ioutils::getJson(QUrl target, QList> headers, std:: void ioutils::postJson(QUrl target, QList> headers, QByteArray body, - std::function callback) { + std::function callback) { QNetworkRequest req(target); for (auto header : headers) { req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); } QNetworkReply *reply = networkManager.post(req, body); QObject::connect(reply, &QNetworkReply::finished, [reply, callback] { - callback(QJsonDocument::fromJson(reply->readAll()), reply); + QByteArray data = reply->readAll(); + callback(QJsonDocument::fromJson(data), data, reply); delete reply; }); } diff --git a/io/ioutils.hpp b/io/ioutils.hpp index 2b41c1f..c2423a8 100644 --- a/io/ioutils.hpp +++ b/io/ioutils.hpp @@ -9,8 +9,11 @@ namespace ioutils { extern QNetworkAccessManager networkManager; -void getJson(QUrl target, QList> headers, std::function callback); -void postJson(QUrl target, QList> headers, QByteArray body, std::function callback); +void getJson(QUrl target, QList> headers, std::function callback); +void postJson(QUrl target, + QList> headers, + QByteArray body, + std::function callback); void getData(QUrl target, QList> headers, std::function callback); void postData(QUrl target, QList> headers, QByteArray body, std::function callback); } diff --git a/mainwindow.cpp b/mainwindow.cpp index 8aa69a0..b3f186b 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -114,7 +114,9 @@ void MainWindow::quit() { void MainWindow::toggleVisible() { this->setVisible(!this->isVisible()); if (this->isVisible()) { - this->raise(); + this->raise(); // that didn't work + this->setWindowState(Qt::WindowActive); // maybe that works + this->activateWindow(); // maybe that works } } diff --git a/uploaders/customuploader.cpp b/uploaders/customuploader.cpp index d3a2618..66eb8bc 100644 --- a/uploaders/customuploader.cpp +++ b/uploaders/customuploader.cpp @@ -284,8 +284,9 @@ void CustomUploader::doUpload(QPixmap *pixmap) { notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!"); }); } else { - ioutils::postJson(target, h, data, - [&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); }); + ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray, QNetworkReply *) { + parseResult(result, returnPathspec, name()); + }); } break; } diff --git a/uploaders/default/imguruploader.cpp b/uploaders/default/imguruploader.cpp index 2312bfa..f552b36 100644 --- a/uploaders/default/imguruploader.cpp +++ b/uploaders/default/imguruploader.cpp @@ -15,7 +15,7 @@ void ImgurUploader::doUpload(QPixmap *pixmap) { QList>() << QPair("Content-Type", "application/x-www-form-urlencoded") << QPair("Authorization", "Client-ID 8a98f183fc895da"), - byteArray, [](QJsonDocument res, QNetworkReply *) { + byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) { QString result = res.object()["data"].toObject()["link"].toString(); screenshotutil::toClipboard(result); notifications::notify("KShare imgur Uploader ", From 92132ed6fbbba4ba14bb07056bf716466706fa81 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sat, 13 May 2017 22:47:01 +0200 Subject: [PATCH 10/11] Copy request to clipboard upon failure --- uploaders/customuploader.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/uploaders/customuploader.cpp b/uploaders/customuploader.cpp index 66eb8bc..e694fbd 100644 --- a/uploaders/customuploader.cpp +++ b/uploaders/customuploader.cpp @@ -216,7 +216,7 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) { return ""; } -void parseResult(QJsonDocument result, QString returnPathspec, QString name) { +void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name) { if (result.isObject()) { qDebug() << result.object()[".url"]; QString url = parsePathspec(result, returnPathspec); @@ -225,8 +225,11 @@ void parseResult(QJsonDocument result, QString returnPathspec, QString name) { notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!"); } else notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!"); - } else - notifications::notify("KShare Custom Uploader " + name, "Upload done, but result is not JSON Object!"); + } else { + notifications::notify("KShare Custom Uploader " + name, + "Upload done, but result is not JSON Object! Result in clipboard."); + QApplication::clipboard()->setText(data); + } } void CustomUploader::doUpload(QPixmap *pixmap) { @@ -284,8 +287,8 @@ void CustomUploader::doUpload(QPixmap *pixmap) { notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!"); }); } else { - ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray, QNetworkReply *) { - parseResult(result, returnPathspec, name()); + ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) { + parseResult(result, data, returnPathspec, name()); }); } break; From 4e2a82f2bd5b5d88c4ad31fa1a2448cad4281ad0 Mon Sep 17 00:00:00 2001 From: ArsenArsen Date: Sun, 14 May 2017 23:19:13 +0200 Subject: [PATCH 11/11] Attempt at improving quality of images on mac --- QHotkey | 2 +- cropeditor/cropeditor.cpp | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/QHotkey b/QHotkey index 7c4ef6a..9eace8f 160000 --- a/QHotkey +++ b/QHotkey @@ -1 +1 @@ -Subproject commit 7c4ef6a03a219c99932975bab270ea812589e1ad +Subproject commit 9eace8fbbd8dede95db623eea5e25403fd59b490 diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index 61c3f53..b7720aa 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -14,8 +14,9 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { scene = new CropScene(parent, image); view = new CropView(scene); qreal ratio = QApplication::primaryScreen()->devicePixelRatio(); - pixmapItem = new QGraphicsPixmapItem(image->scaled(image->width() / ratio, image->height() / ratio)); + pixmapItem = new QGraphicsPixmapItem(*image); pixmapItem->setZValue(-1); + pixmapItem->setScale(1 / ratio); scene->addItem(pixmapItem); scene->setSceneRect(image->rect()); view->showFullScreen();