forked from Harinlen/Robot-Emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
robotaddwidget.cpp
135 lines (121 loc) · 4.59 KB
/
robotaddwidget.cpp
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
/*
* Copyright (C) Kreogist Dev Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include <QBoxLayout>
#include <QPushButton>
#include <QSpinBox>
#include <QLabel>
#include <QSlider>
#include <QRegExpValidator>
#include "robotaddwidget.h"
RobotAddWidget::RobotAddWidget(QWidget *parent) :
QWidget(parent),
m_okay(new QPushButton(this)),
m_cancel(new QPushButton(this)),
m_xData(new QSpinBox(this)),
m_yData(new QSpinBox(this)),
m_angleData(new QSlider(Qt::Horizontal, this))
{
//Intial labels.
for(int i=0; i<3; i++)
{
m_labels[i]=new QLabel(this);
}
//Initial the angle data.
m_angleData->setRange(0, 360);
m_xData->setRange(0, 0);
m_yData->setRange(0, 0);
//Link edit widget.
connect(m_xData, SIGNAL(valueChanged(int)),
this, SLOT(onActionParameterChange()));
connect(m_yData, SIGNAL(valueChanged(int)),
this, SLOT(onActionParameterChange()));
connect(m_angleData, SIGNAL(valueChanged(int)),
this, SLOT(onActionParameterChange()));
//Initial layouts.
QBoxLayout *mainLayout=new QBoxLayout(QBoxLayout::LeftToRight,
this);
mainLayout->setContentsMargins(0,0,0,0);
setLayout(mainLayout);
//Generate the control layout.
QBoxLayout *controlLayout=new QBoxLayout(QBoxLayout::TopToBottom,
mainLayout->widget());
controlLayout->setSpacing(2);
mainLayout->addLayout(controlLayout);
QBoxLayout *positionLayout=new QBoxLayout(QBoxLayout::LeftToRight,
mainLayout->widget());
positionLayout->setSpacing(5);
positionLayout->addWidget(m_labels[0]);
positionLayout->addWidget(m_xData, 1);
positionLayout->addSpacing(10);
positionLayout->addWidget(m_labels[1]);
positionLayout->addWidget(m_yData, 1);
controlLayout->addLayout(positionLayout);
QBoxLayout *angleLayout=new QBoxLayout(QBoxLayout::LeftToRight,
mainLayout->widget());
angleLayout->addWidget(m_labels[2]);
angleLayout->addWidget(m_angleData, 1);
controlLayout->addLayout(angleLayout);
controlLayout->addStretch();
//Generate the button layout.
QBoxLayout *buttonLayout=new QBoxLayout(QBoxLayout::TopToBottom,
mainLayout->widget());
buttonLayout->setSpacing(2);
buttonLayout->addWidget(m_okay);
buttonLayout->addWidget(m_cancel);
buttonLayout->addStretch();
mainLayout->addLayout(buttonLayout);
connect(m_okay,
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]{emit requireAddRobot(QPointF(m_xData->text().toDouble(),
m_yData->text().toDouble()),
m_angleData->value());});
connect(m_cancel,
static_cast<void (QPushButton::*)(bool)>(&QPushButton::clicked),
[=]{emit requireClose();});
retranslate();
}
void RobotAddWidget::updateXAndYRange(const int &minX, const int &minY,
const int &maxX, const int &maxY)
{
m_xData->setRange(minX, maxX);
m_yData->setRange(minY, maxY);
}
void RobotAddWidget::showEvent(QShowEvent *event)
{
QWidget::showEvent(event);
//Reset the data.
m_xData->setValue(m_xData->minimum());
m_yData->setValue(m_yData->minimum());
m_angleData->setValue(0);
//Update the preview.
onActionParameterChange();
}
void RobotAddWidget::retranslate()
{
m_okay->setText(tr("Ok"));
m_cancel->setText(tr("Cancel"));
m_labels[0]->setText(tr("X:"));
m_labels[1]->setText(tr("Y:"));
m_labels[2]->setText(tr("Angle:"));
}
void RobotAddWidget::onActionParameterChange()
{
emit requirePreviewRobot(QPointF(m_xData->text().toDouble(),
m_yData->text().toDouble()),
m_angleData->value());
}