Merge branch 'master' into feature/platformbackends

This commit is contained in:
ArsenArsen 2017-05-15 13:59:55 +02:00
commit 5b6e9c2e36
10 changed files with 77 additions and 23 deletions

View File

@ -2,22 +2,23 @@
#include "cropscene.hpp" #include "cropscene.hpp"
#include "cropview.hpp" #include "cropview.hpp"
#include <QApplication>
#include <QDebug> #include <QDebug>
#include <QGraphicsPixmapItem> #include <QGraphicsPixmapItem>
#include <QGraphicsView> #include <QGraphicsView>
#include <QScreen>
#include <QTimer> #include <QTimer>
#include <settings.hpp> #include <settings.hpp>
CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) {
scene = new CropScene(parent, image); scene = new CropScene(parent, image);
view = new CropView(scene); view = new CropView(scene);
QPixmap *scaled = new QPixmap(); qreal ratio = QApplication::primaryScreen()->devicePixelRatio();
image->scaled(view->width(), view->height()).swap(*scaled);
pixmapItem = new QGraphicsPixmapItem(*image); pixmapItem = new QGraphicsPixmapItem(*image);
pixmapItem->setZValue(-1); pixmapItem->setZValue(-1);
pixmapItem->setScale(1 / ratio);
scene->addItem(pixmapItem); scene->addItem(pixmapItem);
scene->setSceneRect(image->rect()); scene->setSceneRect(image->rect());
view->setGeometry(0, 0, image->width(), image->height());
view->showFullScreen(); view->showFullScreen();
QTimer::singleShot(0, [&] { view->showFullScreen(); }); QTimer::singleShot(0, [&] { view->showFullScreen(); });

View File

@ -142,7 +142,8 @@ void CropScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *e) {
drawingSelection = drawingSelectionMaker(); drawingSelection = drawingSelectionMaker();
if (drawingSelection) if (drawingSelection)
if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; }); if (!drawingSelection->init(this)) setDrawingSelection("None", [] { return nullptr; });
} } else if (settings::settings().value("quickMode", false).toBool())
done();
prevButtons = Qt::NoButton; prevButtons = Qt::NoButton;
} }

View File

@ -8,14 +8,17 @@ namespace ioutils {
QNetworkAccessManager networkManager; QNetworkAccessManager networkManager;
} }
void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback) { void ioutils::getJson(QUrl target,
QList<QPair<QString, QString>> headers,
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
} }
QNetworkReply *reply = networkManager.get(req); QNetworkReply *reply = networkManager.get(req);
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] { 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(); reply->deleteLater();
}); });
} }
@ -23,14 +26,15 @@ void ioutils::getJson(QUrl target, QList<QPair<QString, QString>> headers, std::
void ioutils::postJson(QUrl target, void ioutils::postJson(QUrl target,
QList<QPair<QString, QString>> headers, QList<QPair<QString, QString>> headers,
QByteArray body, QByteArray body,
std::function<void(QJsonDocument, QNetworkReply *)> callback) { std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback) {
QNetworkRequest req(target); QNetworkRequest req(target);
for (auto header : headers) { for (auto header : headers) {
req.setRawHeader(header.first.toUtf8(), header.second.toUtf8()); req.setRawHeader(header.first.toUtf8(), header.second.toUtf8());
} }
QNetworkReply *reply = networkManager.post(req, body); QNetworkReply *reply = networkManager.post(req, body);
QObject::connect(reply, &QNetworkReply::finished, [reply, callback] { 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; delete reply;
}); });
} }

View File

@ -9,8 +9,11 @@
namespace ioutils { namespace ioutils {
extern QNetworkAccessManager networkManager; extern QNetworkAccessManager networkManager;
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback); void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QJsonDocument, QNetworkReply *)> callback); void postJson(QUrl target,
QList<QPair<QString, QString>> headers,
QByteArray body,
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> callback);
void getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback); void getData(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QByteArray, QNetworkReply *)> callback);
void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback); void postData(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, std::function<void(QByteArray, QNetworkReply *)> callback);
} }

View File

@ -33,16 +33,24 @@ int main(int argc, char *argv[]) {
QApplication a(argc, argv); QApplication a(argc, argv);
a.setApplicationName("KShare"); a.setApplicationName("KShare");
a.setOrganizationName("ArsenArsen"); a.setOrganizationName("ArsenArsen");
a.setApplicationVersion("1.1"); a.setApplicationVersion("3.0");
QCommandLineParser parser; QCommandLineParser parser;
parser.addHelpOption(); parser.addHelpOption();
QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray."); QCommandLineOption h({ "b", "background" }, "Does not show the main window, starts in tray.");
QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs"); QCommandLineOption v({ "v", "verbose" }, "Enables QtDebugMsg outputs");
QCommandLineOption ver({ "ver", "version" }, "Prints KShare version");
parser.addOption(h); parser.addOption(h);
parser.addOption(v); parser.addOption(v);
parser.addOption(ver);
parser.process(a); 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); verbose = parser.isSet(v);
MainWindow w; MainWindow w;

View File

@ -3,8 +3,10 @@
#include "screenshotutil.hpp" #include "screenshotutil.hpp"
#include "ui_mainwindow.h" #include "ui_mainwindow.h"
#include <QAction> #include <QAction>
#include <QCheckBox>
#include <QCloseEvent> #include <QCloseEvent>
#include <QCoreApplication> #include <QCoreApplication>
#include <QDesktopServices>
#include <QDoubleSpinBox> #include <QDoubleSpinBox>
#include <QInputDialog> #include <QInputDialog>
#include <QListWidgetItem> #include <QListWidgetItem>
@ -80,6 +82,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); })); addHotkeyItem("Fullscreen image", "fullscreen", new std::function<void()>([] { screenshotter::fullscreen(); }));
addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); })); addHotkeyItem("Area image", "area", new std::function<void()>([] { screenshotter::area(); }));
ui->quickMode->setChecked(settings::settings().value("quickMode", false).toBool());
} }
MainWindow::~MainWindow() { MainWindow::~MainWindow() {
@ -110,7 +114,9 @@ void MainWindow::quit() {
void MainWindow::toggleVisible() { void MainWindow::toggleVisible() {
this->setVisible(!this->isVisible()); this->setVisible(!this->isVisible());
if (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) { if (ui->hotkeys->selectedItems().length() == 1) {
QListWidgetItem *i = ui->hotkeys->selectedItems().at(0); QListWidgetItem *i = ui->hotkeys->selectedItems().at(0);
QString str = i->data(Qt::UserRole + 1).toString(); QString str = i->data(Qt::UserRole + 1).toString();
bool ok;
QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal, QString seq = QInputDialog::getText(ui->centralWidget, "Hotkey Input", "Insert hotkey:", QLineEdit::Normal,
hotkeying::sequence(str)); hotkeying::sequence(str), &ok);
if (hotkeying::valid(seq)) hotkeying::hotkey(str, QKeySequence(seq), *fncs.value(str)); 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);
}

View File

@ -30,6 +30,10 @@ class MainWindow : public QMainWindow {
void on_hotkeys_doubleClicked(const QModelIndex &index); void on_hotkeys_doubleClicked(const QModelIndex &index);
void on_settingsButton_clicked();
void on_quickMode_clicked(bool checked);
public: public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
~MainWindow(); ~MainWindow();

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>512</width> <width>512</width>
<height>304</height> <height>337</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -25,7 +25,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
<item row="6" column="0" colspan="2"> <item row="7" column="0" colspan="2">
<widget class="QLabel" name="label_6"> <widget class="QLabel" name="label_6">
<property name="text"> <property name="text">
<string>&lt;a href=&quot;https://github.com/ArsenArsen/KShare&quot;&gt;Source code available free for everyone. Forever.&lt;/a&gt; <string>&lt;a href=&quot;https://github.com/ArsenArsen/KShare&quot;&gt;Source code available free for everyone. Forever.&lt;/a&gt;
@ -91,6 +91,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="6" column="0">
<widget class="QCheckBox" name="quickMode">
<property name="text">
<string>Quick mode (mouse release screenshots)</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QPushButton" name="settingsButton">
<property name="text">
<string>Open settings directory</string>
</property>
</widget>
</item>
</layout> </layout>
</widget> </widget>
<widget class="QMenuBar" name="menuBar"> <widget class="QMenuBar" name="menuBar">

View File

@ -216,7 +216,7 @@ QString parsePathspec(QJsonDocument &response, QString &pathspec) {
return ""; return "";
} }
void parseResult(QJsonDocument result, QString returnPathspec, QString name) { void parseResult(QJsonDocument result, QByteArray data, QString returnPathspec, QString name) {
if (result.isObject()) { if (result.isObject()) {
qDebug() << result.object()[".url"]; qDebug() << result.object()[".url"];
QString url = parsePathspec(result, returnPathspec); 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!"); notifications::notify("KShare Custom Uploader " + name, "Copied upload link to clipboard!");
} else } else
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!"); notifications::notify("KShare Custom Uploader " + name, "Upload done, but result empty!");
} else } else {
notifications::notify("KShare Custom Uploader " + name, "Upload done, but result is not JSON Object!"); 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) { 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!"); notifications::notify("KShare Custom Uploader " + name(), "Copied upload result to clipboard!");
}); });
} else { } else {
ioutils::postJson(target, h, data, ioutils::postJson(target, h, data, [&](QJsonDocument result, QByteArray data, QNetworkReply *) {
[&](QJsonDocument result, QNetworkReply *) { parseResult(result, returnPathspec, name()); }); parseResult(result, data, returnPathspec, name());
});
} }
break; break;
} }

View File

@ -15,10 +15,10 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
QList<QPair<QString, QString>>() QList<QPair<QString, QString>>()
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded") << QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
<< QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"), << QPair<QString, QString>("Authorization", "Client-ID 8a98f183fc895da"),
byteArray, [](QJsonDocument res, QNetworkReply *) { byteArray, [](QJsonDocument res, QByteArray, QNetworkReply *) {
QString result = res.object()["data"].toObject()["link"].toString(); QString result = res.object()["data"].toObject()["link"].toString();
screenshotutil::toClipboard(result); screenshotutil::toClipboard(result);
notifications::notify("KShare imgur Uploader ", notifications::notify("KShare imgur Uploader ",
result.isEmpty() ? "Failed upload!" : "Upload done, but result empty!"); result.isEmpty() ? "Failed upload!" : "Uploaded to imgur!");
}); });
} }