Merge branch 'master' into feature/platformbackends
This commit is contained in:
commit
5b6e9c2e36
@ -2,22 +2,23 @@
|
||||
|
||||
#include "cropscene.hpp"
|
||||
#include "cropview.hpp"
|
||||
#include <QApplication>
|
||||
#include <QDebug>
|
||||
#include <QGraphicsPixmapItem>
|
||||
#include <QGraphicsView>
|
||||
#include <QScreen>
|
||||
#include <QTimer>
|
||||
#include <settings.hpp>
|
||||
|
||||
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(); });
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -8,14 +8,17 @@ namespace ioutils {
|
||||
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);
|
||||
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<QPair<QString, QString>> headers, std::
|
||||
void ioutils::postJson(QUrl target,
|
||||
QList<QPair<QString, QString>> headers,
|
||||
QByteArray body,
|
||||
std::function<void(QJsonDocument, QNetworkReply *)> callback) {
|
||||
std::function<void(QJsonDocument, QByteArray, QNetworkReply *)> 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;
|
||||
});
|
||||
}
|
||||
|
@ -9,8 +9,11 @@
|
||||
|
||||
namespace ioutils {
|
||||
extern QNetworkAccessManager networkManager;
|
||||
void getJson(QUrl target, QList<QPair<QString, QString>> headers, std::function<void(QJsonDocument, QNetworkReply *)> callback);
|
||||
void postJson(QUrl target, QList<QPair<QString, QString>> headers, QByteArray body, 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, 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);
|
||||
}
|
||||
|
10
main.cpp
10
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;
|
||||
|
@ -3,8 +3,10 @@
|
||||
#include "screenshotutil.hpp"
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QAction>
|
||||
#include <QCheckBox>
|
||||
#include <QCloseEvent>
|
||||
#include <QCoreApplication>
|
||||
#include <QDesktopServices>
|
||||
#include <QDoubleSpinBox>
|
||||
#include <QInputDialog>
|
||||
#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("Area image", "area", new std::function<void()>([] { 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);
|
||||
}
|
||||
|
@ -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();
|
||||
|
@ -7,7 +7,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>512</width>
|
||||
<height>304</height>
|
||||
<height>337</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -25,7 +25,7 @@
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<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">
|
||||
<property name="text">
|
||||
<string><a href="https://github.com/ArsenArsen/KShare">Source code available free for everyone. Forever.</a>
|
||||
@ -91,6 +91,20 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
</widget>
|
||||
<widget class="QMenuBar" name="menuBar">
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -15,10 +15,10 @@ void ImgurUploader::doUpload(QPixmap *pixmap) {
|
||||
QList<QPair<QString, QString>>()
|
||||
<< QPair<QString, QString>("Content-Type", "application/x-www-form-urlencoded")
|
||||
<< QPair<QString, QString>("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!");
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user