This repository has been archived by the owner on Sep 6, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmy_widget.h
199 lines (161 loc) · 5.51 KB
/
my_widget.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
/****************************************/
// COMP2012 2015S PA2 -- Paint
// File: my_widget.h
// Description: the header file
// -- MyMainWindow class definition
/****************************************/
#include <qmainwindow.h>
#include <qapplication.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qpen.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qiconset.h>
#include "my_pendialog.h"
// TODO: include header of other dialogs here
#include "my_linedialog.h"
#include "my_eraserdialog.h"
#include "my_rectdialog.h"
#include "my_filldialog.h"
#include "my_colorpicker_dialog.h"
// generic stack class for undo and redo
#include "stack.h"
// image layers
#include "LayeredPixmap.h"
#include "my_toolbar.h"
#ifndef __DRAW_MODE__
#define __DRAW_MODE__
enum DrawMode
{
DPen,
DLine,
DEraser,
Drect,
DFill,
DColorPicker
};
#endif
#ifndef _MY_WIDGET_H
#define _MY_WIDGET_H
// MyMainWindow: custormized QMainWindow widget
// The QMainWindow class provides a main application window,
// with a menu bar, dock windows (e.g. for toolbars), and a status bar
class MyMainWindow: public QMainWindow {
// All classes that contain signals or slots
// must mention Q_OBJECT in their declaration.
Q_OBJECT
public:
/** maximum support level for undo and redo. It can range from 0 to as much as memory can handle. */
const static int maxUndoLevel = 1000;
const static int imageLayerCount = 6;
/** constructor and destructor */
MyMainWindow(QWidget* parent = 0, const char* name = 0);
~MyMainWindow();
/** mouse event handler */
void mousePressEvent (QMouseEvent *);
void mouseMoveEvent (QMouseEvent *);
void mouseReleaseEvent (QMouseEvent *);
void mouseDoubleClickEvent(QMouseEvent *);
/** paint handler */
void paintEvent(QPaintEvent *);
/** user defined slots */
public slots:
/** Menu bar slots */
void OnNewImage();
void OnLoadImage();
void OnSaveImage();
void OnChooseColor();
void OnChooseBGColor();
void OnExit();
void OnEditUndo();
void OnEditRedo();
void OnEditResize();
void OnEditClearAll();
void OnViewToolBar();
void OnAbout();
void OnDockWindowPositionChanged();
/** Tool bar slots */
void OnChoosePen();
// TODO: add other slots for tool bar here
void OnChooseLine();
void OnChooseEraser();
void OnChooseRect();
void OnChooseFill();
void OnChooseColorPicker();
void OnChooseLayer();
void OnChangeLayerDisplay();
private:
/** Utility functions */
// build the menu
void CreateMenu();
// copy the image to the widget
void paintbmp(bool constructLayers = false);
/** private functions for code reuse and organization*/
void untoggleUnactivatedButtons();
void processChooseColor(QColor windowcolor);
void processChooseBGColor(QColor windowcolor);
void updateUndo();
void updateLayerIcon(int index);
/** Popup menu pointers in the menu bar (pull-down mneu or popup menu) */
QPopupMenu* file;
QPopupMenu* edit;
QPopupMenu* view;
QPopupMenu* help;
/** Image and Painter pointers */
QPixmap* image; // the current image
LayeredPixmap* imageLayers; // image layers
QPainter* paint; // the painter for drawing
/** Undo and Redo. Maximum level of undo and redo is customizable */
// PROVIDED THAT UNDO IS NOT EMPTY, REDO MUST BE EMPTY IN ALL CASES.
Stack<LayeredPixmap>* undoStack; // stack of undo, of customizable size
Stack<LayeredPixmap>* redoStack; // stack of redo
/** Dialog pointers */
MyPenDialog* pendialog; // the pen dialog for the pen tool
// TODO: define the other dialogs for tools including line, eraser and rectangles
MyLineDialog* lineDialog;
MyEraserDialog* eraserDialog;
MyRectDialog* rectDialog;
MyFillDialog* fillDialog;
MyColorPickerDialog* colorPickerDialog;
int mouseevent; // 0 for none, 1 for left button click, or 2 for right button click
/** Tool bar related */
int selectedbutton;
MyToolBar* drawTools;
MyToolBar* layerTools;
QToolButton* newButton;
QToolButton* openButton;
QToolButton* saveButton;
QToolButton* undoButton;
QToolButton* redoButton;
QToolButton* clearallButton;
QToolButton* resizeButton;
QToolButton* penButton;
QToolButton* lineButton;
QToolButton* eraserButton;
QToolButton* rectButton;
QToolButton* colorButton;
QToolButton* bcolorButton;
QToolButton* fillButton;
QToolButton* colorPickerButton;
QToolButton* colorIndicator;
QToolButton* bgColorIndicator;
// array of buttons for image layers and display status.
QToolButton** layerIndicators;
QToolButton** layerDisplayIndicators;
/** Storing the background color setting */
QColor bgcolor;
/** Storing positions of cursors for drawing */
int px, py;
int dx, dy;
/** Storing margin sizes of the windown (with or without tool, menu bars) */
int xPos, yPos;
// xPos: the width between the left edge of painting area and the left edge of the window
// yPos: the height between the top edge of painting area and the top edge of the window
/** flag variable for undo */
//bool undoflag;
};
#endif