-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
174 lines (148 loc) · 4.62 KB
/
Copy pathmainwindow.cpp
File metadata and controls
174 lines (148 loc) · 4.62 KB
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
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "dlgconfig.h"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionE_xit, SIGNAL(triggered()), this, SLOT(close()));
connect(ui->actionGrid_Lines, SIGNAL(triggered()), this, SLOT(toggleGrid()));
connect(ui->action_Options, SIGNAL(triggered()), this, SLOT(showOptions()));
connect(ui->gB_Gear1, SIGNAL(toggled(bool)), this, SLOT(hideGear()));
connect(ui->gB_Gear2, SIGNAL(toggled(bool)), this, SLOT(hideGear()));
timer = new QTimer(this);
connect(timer, SIGNAL(timeout()), this, SLOT(timer_update()));
mainScene = new QGraphicsScene();
ui->graphicsView->setScene(mainScene);
gridGroupV = NULL;
gridGroupH = NULL;
gridGroupD = NULL;
gear1 = NULL;
gear2 = NULL;
drawGear(8,8);
timer->start(100);
gear1->setPos(100,100);
gear2->setPos(300,100);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::timer_update()
{
gear1->setRotation(gear1->rotation() + 10);
gear2->setRotation(gear2->rotation() + 10);
}
void MainWindow::showOptions()
{
qDebug() << "Show Options Dialog.";
dlgConfig *newOptions = new dlgConfig(this);
connect(newOptions, SIGNAL(recvGridOptions()), this, SLOT(drawGrid()));
newOptions->exec();
}
//1px = 0.264583333 mm
//1px = 0.026458333 cm
//1px = 0.010416667 in
void MainWindow::drawGear(int teeth, int adendum)
{
gear1 = new gearObj();
gear2 = new gearObj();
mainScene->addItem(gear1);
mainScene->addItem(gear2);
}
void MainWindow::hideGear()
{
QGroupBox *senderObj = qobject_cast<QGroupBox *>(sender());
if (senderObj->objectName() == "gB_Gear1" && senderObj->isChecked())
gear1->setVisible(true);
else gear1->setVisible(true);
if (senderObj->objectName() == "gB_Gear2" && senderObj->isChecked())
gear2->setVisible(false);
else gear2->setVisible(false);
}
void MainWindow::toggleGrid()
{
if (ui->actionGrid_Lines->isChecked())
showGrid();
if (!ui->actionGrid_Lines->isChecked())
hideGrid();
}
void MainWindow::showGrid()
{
if (gridGroupV != NULL)
gridGroupV->show();
if (gridGroupH != NULL)
gridGroupH->show();
if (gridGroupD != NULL)
gridGroupD->show();
}
void MainWindow::hideGrid()
{
if (gridGroupV != NULL)
gridGroupV->hide();
if (gridGroupH != NULL)
gridGroupH->hide();
if (gridGroupD != NULL)
gridGroupD->hide();
}
void MainWindow::deleteGrid()
{
//must delete object... currently only removing from scene...
if (gridGroupV != NULL)
mainScene->removeItem(gridGroupV);
if (gridGroupH != NULL)
mainScene->removeItem(gridGroupH);
if (gridGroupH != NULL)
mainScene->removeItem(gridGroupD);
}
void MainWindow::drawGrid()
{
deleteGrid();
// X Axis = Horizontal.
if (mainOptions->grid.getXvisible())
{
QList<QGraphicsItem*> gXLines;
for (int x=0; x<=ui->graphicsView->width(); x+=mainOptions->grid.getXspacing())
if(x >= mainOptions->grid.getXorigin())
{
QGraphicsLineItem *newLineX = new QGraphicsLineItem(x,0,x,ui->graphicsView->height()-1);
newLineX->setPen(QPen(mainOptions->grid.getXcolor(), 1));
gXLines.append(newLineX);
}
gridGroupV = mainScene->createItemGroup(gXLines);
gridGroupV->setZValue(-1);
}
// Y Axis = Vertical.
if (mainOptions->grid.getYvisible())
{
QList<QGraphicsItem*> gYLines;
for (int y=0; y<=ui->graphicsView->height(); y+=mainOptions->grid.getYspacing())
if(y >= mainOptions->grid.getYorigin())
{
QGraphicsLineItem *newLineY = new QGraphicsLineItem(0,y,ui->graphicsView->width()-1,y);
newLineY->setPen(QPen(mainOptions->grid.getYcolor(), 1));
gYLines.append(newLineY);
}
gridGroupH = mainScene->createItemGroup(gYLines);
gridGroupH->setZValue(-1);
}
//TODO: still working on this.
// Diagonal Grid Lines.
if (mainOptions->grid.getDvisible())
{
QList<QGraphicsItem*> gDLines;
for (int d=0; d<=ui->graphicsView->width(); d+=mainOptions->grid.getXspacing())
{
QGraphicsLineItem *newLineD = new QGraphicsLineItem(0,d,d,0);
newLineD->setPen(QPen(mainOptions->grid.getXcolor(), 1));
gDLines.append(newLineD);
}
gridGroupD = mainScene->createItemGroup(gDLines);
gridGroupD->setZValue(-1);
}
}
void MainWindow::testslot()
{
qDebug() << "test slot";
}