Newer
Older
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
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QColorDialog>
#include <QGridLayout>
#include <QCheckBox>
#include <QDebug>
#include "paint.h"
#include "canvas.h"
/** c'tor */
Paint::Paint(QWidget *parent): QWidget(parent)
{
// instantiate Canvas and button
viewport = new Canvas();
btnClearCanvas = new QPushButton("&Clear Canvas");
cobPrimModes = new QComboBox();
cobPrimModes->addItem(tr("None"), Canvas::NONE);
cobPrimModes->addItem(tr("Line"), Canvas::LINE);
cobPrimModes->addItem(tr("Freehand"), Canvas::FREE_HAND);
cobPrimModes->addItem(tr("Circle"), Canvas::CIRCLE);
cobPrimModes->addItem(tr("Rectangle"), Canvas::RECTANGLE);
cobPrimModes->addItem(tr("Triangle"), Canvas::TRIANGLE);
//cobPrimModes->addItem(tr("Polygon"), Canvas::POLYGON);
lblPrimModes = new QLabel("Primitive Mode");
lblPrimModes->setBuddy(cobPrimModes);
btnDeleteObj = new QPushButton("&Delete Selected");
btnDeleteObj->setDisabled(false);
btnChangeCol = new QPushButton("C&hange Color");
cbOutline = new QCheckBox("Show Only &Outline", this);
BBox = new QCheckBox("Show BBox", this);
//1
groupBox = new QGroupBox("Radio Buttons");
//2
QVBoxLayout* groupBoxLayout = new QVBoxLayout();
groupBox->setLayout(groupBoxLayout);
//3
QRadioButton* creating = new QRadioButton("Create");
creating->setChecked(true);
QRadioButton* deleting = new QRadioButton("Delete Selected");
QRadioButton* coloring = new QRadioButton("Change Color");
QRadioButton* moving = new QRadioButton("Move Selected");
//4
action = new QButtonGroup(this);
//5
action->addButton(creating);
action->addButton(deleting);
action->addButton(coloring);
action->addButton(moving);
//6
action->addButton(creating,Canvas::InteractionMode::CREAT);
action->addButton(deleting,Canvas::InteractionMode::DEL);
action->addButton(coloring,Canvas::InteractionMode::COL);
action->addButton(moving,Canvas::InteractionMode::TRAFO);
//7
groupBoxLayout->addWidget(creating);
groupBoxLayout->addWidget(deleting);
groupBoxLayout->addWidget(coloring);
groupBoxLayout->addWidget(moving);
//8
//connect(action, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked), this, &Paint::groupBoxChanged);
// create layout and add gui elements to it
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(viewport, 0, 0, 1, 4);
mainLayout->addWidget(groupBox, 1, 0 ,3,2);
mainLayout->addWidget(lblPrimModes, 1, 2,Qt::AlignRight);
mainLayout->addWidget(cobPrimModes, 1, 3);
mainLayout->addWidget(btnChangeCol, 2, 3);
mainLayout->addWidget(cbOutline, 2, 2, Qt::AlignRight);
mainLayout->addWidget(btnClearCanvas,3, 3);
mainLayout->addWidget(BBox, 3, 2, Qt::AlignRight);
//mainLayout->addWidget(btnDeleteObj, 2, 0);
// add layout to this widget instance
setLayout(mainLayout);
// connect button click event to clear canvas handler
connect(btnClearCanvas, SIGNAL(clicked()),
this, SLOT(clearBtnPressed()));
// connect button click event to delete selected object handler
connect(btnDeleteObj, SIGNAL(clicked()),
this, SLOT(deleteBtnPressed()));
// connect button click event to color chooser handler
connect(btnChangeCol, SIGNAL(clicked()),
this, SLOT(colorBtnPressed()));
// connect list view to primitive changed event handler
connect(cobPrimModes, SIGNAL(activated(int)),
this, SLOT(primModeChanged()));
// connect checkbox to toggle outline event handler
connect(cbOutline, SIGNAL(toggled(bool)),
this, SLOT(showOutlineOnly(bool)));
// connect checkbox to toggle BBox event handler
connect(BBox, SIGNAL(toggled(bool)),
this, SLOT(BBoxPressed(bool)));
// connect groupButton to toggle action event handler
connect(action, QOverload<QAbstractButton*>::of(&QButtonGroup::buttonClicked),
this, &Paint::groupBoxChanged);
}
/** d'tor */
Paint::~Paint(){
delete groupBox;
delete groupBoxLayout;
delete creating;
delete deleting;
delete coloring;
delete moving;
delete action;
}
/** method for handling button clicked event */
void Paint::clearBtnPressed(){
viewport->clearCanvas();
viewport->update();
}
void Paint::deleteBtnPressed()
{
// if(viewport->getSelectedIndex() != -1){
// viewport->AllShape.erase(viewport->AllShape.begin()+viewport->getSelectedIndex());
// //reset SelectedIndex to -1 for the next Shape
// viewport->setSelectedIndex(-1) ;
// viewport->update();
// }
}
void Paint::colorBtnPressed(){
QColor color = QColorDialog::getColor(Qt::yellow, this );
if (color.isValid()) {
//set color from the GUI
viewport->setColor(color);
}
//qDebug() << "Color Choosen : " << color.name();
}
void Paint::showOutlineOnly(bool outline){
qDebug() << "Only show outline: " << outline;
viewport->setOutline(!viewport->getOutline());
}
void Paint::BBoxPressed(bool bbox)
{
qDebug() << "BBox : " << bbox;
}
void Paint::groupBoxChanged()
{
std::cout<<"action change"<<std::endl;
// you need to cast das here
viewport->setOparation((Canvas::InteractionMode)action->checkedId());
}
void Paint::primModeChanged(){
int mode = cobPrimModes->itemData(cobPrimModes->currentIndex(), Qt::UserRole).toInt();
viewport->setPrimitiveMode(mode);
qDebug() << "Primitive Mode changed to " << mode;
}