Browse Source

Preparations for drawing

tags/v5.0.0
ArsenArsen 5 years ago
parent
commit
3c92607727
  1. 3
      KShare.pro
  2. 10
      cropeditor/cropeditor.cpp
  3. 1
      cropeditor/cropeditor.hpp
  4. 13
      cropeditor/cropscene.cpp
  5. 2
      cropeditor/cropscene.hpp
  6. 12
      cropeditor/drawing/drawitem.hpp
  7. 3
      uploaders/customuploader.cpp

3
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

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

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

13
cropeditor/cropscene.cpp

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

2
cropeditor/cropscene.hpp

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

12
cropeditor/drawing/drawitem.hpp

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

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

Loading…
Cancel
Save