Preparations for drawing

This commit is contained in:
ArsenArsen 2017-04-29 12:08:02 +02:00
parent 13be43186b
commit 3c92607727
7 changed files with 35 additions and 9 deletions

View File

@ -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

View File

@ -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);
}

View File

@ -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;

View File

@ -1,7 +1,9 @@
#include "cropscene.hpp"
#include <QDebug>
#include <QGraphicsPolygonItem>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsView>
#include <QMenu>
#include <QTimer>
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());
}

View File

@ -3,6 +3,7 @@
#include <QGraphicsRectItem>
#include <QGraphicsScene>
#include <QGraphicsSceneContextMenuEvent>
#include <QGraphicsSceneMouseEvent>
#include <QKeyEvent>
@ -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;

View File

@ -1,4 +1,16 @@
#ifndef DRAWITEM_HPP
#define DRAWITEM_HPP
#include <QString>
#include <cropeditor/cropscene.hpp>
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

View File

@ -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)