-
Notifications
You must be signed in to change notification settings - Fork 3
/
customscene.h
101 lines (93 loc) · 2.62 KB
/
customscene.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef CUSTOMSCENE_H
#define CUSTOMSCENE_H
#include <QGraphicsScene>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsLineItem>
#include <QAction>
#include <QGraphicsView>
#include <QKeyEvent>
#include "boxitem.h"
#include <QFileInfo>
#include <QFile>
#include <QImageReader>
#include <QUndoStack>
#include "commands.h"
#include "FreeImage.h"
#include "boxitemmimedata.h"
#include <QClipboard>
class CustomScene : public QGraphicsScene
{
Q_OBJECT
public:
CustomScene(QObject* parent = 0);
~CustomScene()
{
clearAll();
}
void loadImage(QString path);
void saveToFile(const QString& path);
void clearAll();
void setTypeNameList (const QStringList &list)
{
_typeNameList = list;
}
void setTypeName (const QString &name)
{
_typeName = name;
}
QUndoStack *undoStack() const
{
return _undoStack;
}
void selectBoxItems(QList<BoxItem *> *boxList, bool op);
void selectBoxItems(BoxItem *box, bool op);
void selectBoxItems(bool op);
void registerItem(BoxItem *b);
void drawBoxItem(bool op);
void panImage(bool op);
public slots:
void changeBoxTypeName(QString name);
void selectedBoxItemInfo(QRect rect, QString typeName)
{
_typeName = typeName;
}
void copy();
void cut();
void paste();
void clipboardDataChanged();
private slots:
void moveBox(QRectF newRect, QRectF oldRect);
signals:
void imageLoaded(QSize imageSize);
void cursorMoved(QPointF cursorPos);
void boxSelected(QRect boxRect, QString typeName);
protected:
void mousePressEvent(QGraphicsSceneMouseEvent *event);
void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
void keyPressEvent(QKeyEvent *keyEvent);
void keyReleaseEvent(QKeyEvent *keyEvent);
void deleteBoxItems();
private:
QImage *_image;
QGraphicsPixmapItem *_pixmapItem = nullptr;
BoxItem* _boxItem = nullptr;//, *_selectedBoxItem;
QString _typeName;
QStringList _typeNameList;
double _zoomFactor = 1;
QPointF _dragStart, _dragEnd;
bool _isPanning = false;
bool _isDrawing = false;
bool _isMoving = false;
bool _isMouseMoved = false;
QPointF _leftTopPoint;
QPointF _rightBottomPoint;
QString _boxItemFileName;
QUndoStack *_undoStack;
BoxItemMimeData *_boxItemMimeData = nullptr;
QList<QPointF> _pastePos;
QPointF _clickedPos;
void loadBoxItemsFromFile();
void saveBoxItemsToFile();
};
#endif // CUSTOMSCENE_H