diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index cedd54b..b7720aa 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -2,22 +2,23 @@ #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); + qreal ratio = QApplication::primaryScreen()->devicePixelRatio(); pixmapItem = new QGraphicsPixmapItem(*image); pixmapItem->setZValue(-1); + pixmapItem->setScale(1 / ratio); scene->addItem(pixmapItem); scene->setSceneRect(image->rect()); - view->setGeometry(0, 0, image->width(), image->height()); view->showFullScreen(); QTimer::singleShot(0, [&] { view->showFullScreen(); }); 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/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/main.cpp b/main.cpp index cb36d38..38d571e 100644 --- a/main.cpp +++ b/main.cpp @@ -33,16 +33,24 @@ int main(int argc, char *argv[]) { QApplication a(argc, argv); a.setApplicationName("KShare"); a.setOrganizationName("ArsenArsen"); - a.setApplicationVersion("1.1"); + a.setApplicationVersion("3.0"); QCommandLineParser parser; parser.addHelpOption(); 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; diff --git a/mainwindow.cpp b/mainwindow.cpp index 37795b2..b3f186b 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() { @@ -110,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 } } @@ -152,8 +158,17 @@ 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)); } } + +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 + + + diff --git a/uploaders/customuploader.cpp b/uploaders/customuploader.cpp index d3a2618..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,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 data, QNetworkReply *) { + parseResult(result, data, returnPathspec, name()); + }); } break; } diff --git a/uploaders/default/imguruploader.cpp b/uploaders/default/imguruploader.cpp index c9c94f7..f552b36 100644 --- a/uploaders/default/imguruploader.cpp +++ b/uploaders/default/imguruploader.cpp @@ -15,10 +15,10 @@ 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 ", - result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!"); + result.isEmpty() ? "Failed upload!" : "Uploaded to imgur!"); }); }