diff --git a/KShare.pro b/KShare.pro index 0a57930..9db0ea3 100644 --- a/KShare.pro +++ b/KShare.pro @@ -55,7 +55,8 @@ HEADERS += mainwindow.hpp \ formatter.hpp \ uploaders/customuploader.hpp \ notifications.hpp \ - hotkeying.hpp + hotkeying.hpp \ + cropeditor/drawing/drawitem.hpp FORMS += mainwindow.ui diff --git a/cropeditor/cropeditor.cpp b/cropeditor/cropeditor.cpp index 69b0466..9273280 100644 --- a/cropeditor/cropeditor.cpp +++ b/cropeditor/cropeditor.cpp @@ -8,14 +8,13 @@ CropEditor::CropEditor(QPixmap *image, QObject *parent) : QObject(parent) { - pixmap = image; scene = new CropScene(parent); view = new CropView(scene); - pixmapItem = new QGraphicsPixmapItem(*pixmap); + pixmapItem = new QGraphicsPixmapItem(*image); pixmapItem->setZValue(-1); scene->addItem(pixmapItem); - scene->setSceneRect(pixmap->rect()); + scene->setSceneRect(image->rect()); QTimer::singleShot(0, [&] { view->showFullScreen(); }); @@ -29,8 +28,9 @@ CropEditor::~CropEditor() void CropEditor::crop(QRect rect) { - QPixmap crop = pixmap->copy(rect); + QPixmap map = QPixmap::grabWidget(view, rect); QPixmap *cropp = new QPixmap; - crop.swap(*cropp); + map.swap(*cropp); + delete view; emit cropped(cropp); } diff --git a/cropeditor/cropeditor.hpp b/cropeditor/cropeditor.hpp index cd50e22..104f22b 100644 --- a/cropeditor/cropeditor.hpp +++ b/cropeditor/cropeditor.hpp @@ -19,7 +19,6 @@ class CropEditor : public QObject private: void crop(QRect rect); - QPixmap *pixmap = nullptr; CropScene *scene = nullptr; CropView *view = nullptr; QGraphicsPixmapItem *pixmapItem = nullptr; diff --git a/cropeditor/cropscene.cpp b/cropeditor/cropscene.cpp index a6dc6a6..9f1316a 100644 --- a/cropeditor/cropscene.cpp +++ b/cropeditor/cropscene.cpp @@ -1,7 +1,9 @@ #include "cropscene.hpp" #include #include +#include #include +#include #include CropScene::CropScene(QObject *parent) : QGraphicsScene(parent), prevButtons(Qt::NoButton) @@ -81,6 +83,14 @@ void CropScene::keyReleaseEvent(QKeyEvent *event) if (event->key() == Qt::Key_Return || event->key() == Qt::Key_Enter) done(); } +void CropScene::contextMenuEvent(QGraphicsSceneContextMenuEvent *e) +{ + QMenu menu(e->widget()); + + menu.exec(e->screenPos()); + e->accept(); +} + void CropScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) { done(); @@ -89,6 +99,5 @@ void CropScene::mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) void CropScene::done() { - for (QGraphicsView *v : views()) v->close(); - emit closedWithRect(rect != nullptr ? rect->rect().toRect() : QRect()); + if (rect) emit closedWithRect(rect->rect().toRect()); } diff --git a/cropeditor/cropscene.hpp b/cropeditor/cropscene.hpp index 9be1305..e1060ae 100644 --- a/cropeditor/cropscene.hpp +++ b/cropeditor/cropscene.hpp @@ -3,6 +3,7 @@ #include #include +#include #include #include @@ -18,6 +19,7 @@ class CropScene : public QGraphicsScene void mouseMoveEvent(QGraphicsSceneMouseEvent *e) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *e) override; void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *e) override; + void contextMenuEvent(QGraphicsSceneContextMenuEvent *e) override; void keyReleaseEvent(QKeyEvent *e) override; diff --git a/cropeditor/drawing/drawitem.hpp b/cropeditor/drawing/drawitem.hpp index b3dc745..101d31d 100644 --- a/cropeditor/drawing/drawitem.hpp +++ b/cropeditor/drawing/drawitem.hpp @@ -1,4 +1,16 @@ #ifndef DRAWITEM_HPP #define DRAWITEM_HPP +#include +#include + +class DrawItem +{ + public: + virtual QString name() = 0; + virtual void render(QPixmap *pixmap) = 0; + virtual void makeItem(CropScene *scene) = 0; + virtual void mouseDragEvent(QGraphicsSceneMoveEvent *e, CropScene *scene) = 0; +}; + #endif // DRAWITEM_HPP diff --git a/uploaders/customuploader.cpp b/uploaders/customuploader.cpp index fc28e40..c088d93 100644 --- a/uploaders/customuploader.cpp +++ b/uploaders/customuploader.cpp @@ -262,6 +262,7 @@ void parseResult(QJsonDocument result, QString returnPathspec, QString name) { if (result.isObject()) { + qDebug() << result.object()[".url"]; QString url = parsePathspec(result, returnPathspec); if (!url.isEmpty()) { @@ -271,6 +272,8 @@ void parseResult(QJsonDocument result, QString returnPathspec, QString name) 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!"); } void CustomUploader::doUpload(QPixmap *pixmap)