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
#include <QPushButton>
#include <QComboBox>
#include <QLabel>
#include <QColorDialog>
#include <QGridLayout>
#include <QCheckBox>
#include <QDebug>
#include "paint.h"
#include "canvas.h"
#include <iostream>
/** c'tor */
Paint::Paint(QWidget *parent)
: QWidget(parent) {
// instantiate Canvas and button
viewport = new Canvas();
btnClearCanvas = new QPushButton("&Clear Canvas");
btnScene1 = new QPushButton("&Scene 1");
btnScene2 = new QPushButton("&Scene 2");
btnScene3 = new QPushButton("&Scene 3");
cobPrimModes = new QComboBox();
cobPrimModes->addItem(tr("None"), NONE);
cobPrimModes->addItem(tr("Line"), LINE);
cobPrimModes->addItem(tr("Freehand"), FREE_HAND);
cobPrimModes->addItem(tr("Circle"), CIRCLE);
cobPrimModes->addItem(tr("Rectangle"), RECTANGLE);
//cobPrimModes->addItem(tr("Triangle"), TRIANGLE);
//cobPrimModes->addItem(tr("Polygon"), POLYGON);
cobTrafoModes = new QComboBox();
cobTrafoModes->addItem(tr("Create"), CREATE);
cobTrafoModes->addItem(tr("Paint"), PAINT);
cobTrafoModes->addItem(tr("Move"), MOVE);
//cobTrafoModes->addItem(tr("Scale"), SCALE);
//cobTrafoModes->addItem(tr("Rotate"), ROTATE);
cobTrafoModes->addItem(tr("Delete"), DELETE);
lblPrimModes = new QLabel("Primitive Mode");
lblPrimModes->setBuddy(cobPrimModes);
btnDeleteObj = new QPushButton("&Delete Selected");
btnDeleteObj->setDisabled(true);
btnChangeCol = new QPushButton("C&hange Color");
cbOutline = new QCheckBox("Show Only &Outline", this);
// create layout and add gui elements to it
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(viewport, 0, 0, 1, 4);
mainLayout->addWidget(btnChangeCol, 1, 0);
mainLayout->addWidget(cbOutline, 1, 1, Qt::AlignLeft);
mainLayout->addWidget(lblPrimModes, 1, 2, Qt::AlignRight);
mainLayout->addWidget(cobPrimModes, 1, 3);
mainLayout->addWidget(cobTrafoModes, 2, 0);
mainLayout->addWidget(btnScene1, 2, 1);
mainLayout->addWidget(btnScene2, 2, 2);
mainLayout->addWidget(btnClearCanvas, 2, 3);
// 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(cobTrafoModes, SIGNAL(activated(int)),
this, SLOT(trafoModeChanged()));
// connect checkbox to toggle outline event handler
connect(cbOutline, SIGNAL(toggled(bool)),
this, SLOT(showOutlineOnly(bool)));
connect(btnScene1, SIGNAL(clicked()), this, SLOT(scene1Pressed()));
connect(btnScene2, SIGNAL(clicked()), this, SLOT(scene2Pressed()));
}
/** d'tor */
Paint::~Paint() {
}
/** method for handling button clicked event */
void Paint::clearBtnPressed() {
viewport->clearCanvas();
// force redraw
update();
qDebug() << "Clear image called";
}
void Paint::deleteBtnPressed() {
// Implementation requires inside test for all objects for selection
qDebug() << "Next action: delete selected item (NYI)";
}
void Paint::colorBtnPressed() {
QColor color = QColorDialog::getColor(Qt::yellow, this);
if (color.isValid()) {
qDebug() << "Color Choosen : " << color.name();
viewport->s->setColour(color);
}
}
void Paint::changeScene(int index) {
viewport->s->changeCD(index);
update();
}
void Paint::scene1Pressed() {
changeScene(1);
std::cout << "Changed Scene to Scene1.\n";
}
void Paint::scene2Pressed() {
changeScene(2);
std::cout << "Changed Scene to Scene2.\n";
}
void Paint::showOutlineOnly(bool outline) {
qDebug() << "Only show outline: " << outline;
viewport->s->setOutline(outline);
}
void Paint::primModeChanged() {
int mode = cobPrimModes->itemData(
cobPrimModes->currentIndex(), Qt::UserRole).toInt();
viewport->s->setMode(mode);
qDebug() << "Primitive Mode changed to " << mode;
}
void Paint::trafoModeChanged() {
int mode = cobTrafoModes->itemData(
cobTrafoModes->currentIndex(), Qt::UserRole).toInt();
viewport->s->setDefaultTrafo(mode);
qDebug() << "Trafo Mode changed to " << mode;
}