-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcroppingwidget.h
163 lines (133 loc) · 4.01 KB
/
croppingwidget.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#ifndef CROPPINGWIDGET_H
#define CROPPINGWIDGET_H
#include <QResizeEvent>
#include <QLabel>
#include <QWidget>
#include <QImage>
#include <QMap>
#include <QPainter>
#include <QFile>
#include <QStatusBar>
#include <iostream>
#include "monitor.h"
#include "screenundowrapper.h"
class CroppingWidget : public QWidget
{
Q_OBJECT
public:
explicit CroppingWidget(QWidget *parent = 0);
~CroppingWidget();
/**
* @brief saveCrops Saves crops from the image
* @param path where to save to
*/
void saveCrops(const QFile &path) const;
/**
* @brief removeMonitor
* @param name name of the monitor to be removed
* @return whether the monitor was found
*/
bool removeMonitor(const QString& name);
/**
* @brief addMonitor
* @param name what id to use for the monitor
* @param size what size does the monitor have
* @param pos at what position is the monitor
*/
void addMonitor(const QString& name, const QSize &size, const QPoint &pos);
/**
* @brief selectAllMonitors set selection state for all monitors
* @param select future selection state
*/
void selectAllMonitors(bool select);
/**
* @brief loadImage load the image to be cropped
* @param path where the image is to be found
* @return load operation success
*/
bool loadImage(const QFile &path);
/**
* @brief setStatusbar saves a pointer to the statusbar so that we can update it
* @param s status bar reference
*/
void setStatusbar(QStatusBar *s);
/**
* @brief resetMonitors reset each monitor scale to x=y, maximum fit, and 0x0 position
*/
void resetMonitors();
/**
* @brief onUndo undo the last action
*/
void onUndo();
/**
* @brief onRedo redo the last action
*/
void onRedo();
protected:
void paintEvent(QPaintEvent *event) Q_DECL_OVERRIDE;
void resizeEvent(QResizeEvent* event);
void wheelEvent(QWheelEvent* event);
void mousePressEvent(QMouseEvent*e);
void mouseMoveEvent(QMouseEvent* e);
void mouseReleaseEvent(QMouseEvent*e);
private:
/**
* @brief mMouseMoved has the mouse moved since the last click
*/
bool mMouseMoved = false;
/**
* @brief mMousePressBeginPosition Where did the last mouse click occur
*/
QPoint mMousePressBeginPosition;
/**
* @brief mImageLoaded image currently loaded
*/
bool mImageLoaded = false;
/**
* @brief scaleToWindowSize scales the image to widget size, and the monitors by the factor of difference
*/
void scaleToWindowSize();
/**
* @brief fullQualityCropPossible whether the crop can be done without quality loss
* @return true if the monitors can be cropped without scaling the image > 1
*/
bool fullQualityCropPossible() const;
/**
* @brief getMonitorName Translates from a clicked location to the monitor at that position
* @param clickPosition where the concerned monitor was clicked
* @return name of the clicked monitor
*/
QString getMonitorName(QPoint clickPosition) const;
/**
* @brief moveMonitors Move the monitors
* @param dX x delta
* @param dY y delta
*/
void moveMonitors(int dX, int dY);
/**
* @brief imageScale calculate the scale from the original to the current image
* @return currentSize / oldSize
*/
double imageScale() const ;
/**
* @brief mCurrentImage the original image, but with all transformations applied
*/
QImage mCurrentImage;
/**
* @brief mOriginalImage the original image without any applied transformations
*/
QImage mOriginalImage;
/**
* @brief mStatusBarView Status bar for displaying information
*/
QLabel* mStatusBarView;
/**
* @brief mScreen object handling all things monitor
*/
ScreenUndoWrapper mScreen;
/**
* @brief updateStatusBar refresh the informatino shown on the status bar
*/
void updateStatusBar() const;
};
#endif // CROPPINGWIDGET_H