-
Notifications
You must be signed in to change notification settings - Fork 0
/
qttestqtroundedrectitemmodifydialog.cpp
173 lines (155 loc) · 5.04 KB
/
qttestqtroundedrectitemmodifydialog.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
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
//---------------------------------------------------------------------------
/*
TestQtRoundedRectItem, tool to test QtRoundedRectItem
Copyright (C) 2012-2015 Richel Bilderbeek
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 3 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, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTestQtRoundedRectItem.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#include "qttestqtroundedrectitemmodifydialog.h"
#include <boost/make_shared.hpp>
#include <boost/lambda/lambda.hpp>
#include <QKeyEvent>
#include <QTimer>
#include "qtroundedrectitemdialog.h"
#include "qtroundedrectitem.h"
#include "ribi_random.h"
#include "testtimer.h"
#include "trace.h"
#include "ui_qttestqtroundedrectitemmodifydialog.h"
#pragma GCC diagnostic pop
ribi::QtTestQtRoundedRectItemModifyDialog::QtTestQtRoundedRectItemModifyDialog(QWidget *parent) :
QtHideAndShowDialog(parent),
ui(new Ui::QtTestQtRoundedRectItemModifyDialog),
m_dialog_left(new QtRoundedRectItemDialog),
m_dialog_right(new QtRoundedRectItemDialog)
{
ui->setupUi(this);
for (const auto& widget: { ui->widget_left,ui->widget_right })
{
if (!widget->layout())
{
QVBoxLayout * const layout = new QVBoxLayout;
widget->setLayout(layout);
}
}
ui->widget_left->layout()->addWidget(m_dialog_left.get());
ui->widget_right->layout()->addWidget(m_dialog_right.get());
{
QTimer * const timer = new QTimer(this);
QObject::connect(
timer,
SIGNAL(timeout()),
this,
SLOT(DoSomethingRandom())
);
timer->setInterval(100);
timer->start();
}
{
boost::shared_ptr<QtRoundedRectItem> item(new QtRoundedRectItem);
{
const QPen pen(
QBrush(qRgb(0,0,0)),
2.0,
Qt::SolidLine
);
item->SetContourPen(pen);
}
{
const QPen pen(
QBrush(qRgb(0,0,0)),
3.0,
Qt::DashLine
);
item->SetFocusPen(pen);
}
item->SetOuterHeight(32.0);
item->SetCenterPos(0.0,0.0);
item->SetRadiusX(5.0);
item->SetRadiusY(6.0);
item->SetOuterWidth(48.0);
SetItem(item);
}
}
ribi::QtTestQtRoundedRectItemModifyDialog::~QtTestQtRoundedRectItemModifyDialog() noexcept
{
delete ui;
}
void ribi::QtTestQtRoundedRectItemModifyDialog::DoSomethingRandom() noexcept
{
if (!ui->box_change->isChecked()) return;
m_dialog_left->DoSomethingRandom();
m_dialog_right->DoSomethingRandom();
}
void ribi::QtTestQtRoundedRectItemModifyDialog::keyPressEvent(QKeyEvent * event)
{
if (event->key() == Qt::Key_Escape) { close(); return; }
}
boost::shared_ptr<ribi::QtRoundedRectItem> ribi::QtTestQtRoundedRectItemModifyDialog::CreateRandomItem() noexcept
{
boost::shared_ptr<QtRoundedRectItem> item(new QtRoundedRectItem);
{
const QPen pen(
QBrush(qRgb(std::rand() % 256,std::rand() % 256,std::rand() % 256)),
1.0 + (static_cast<double>(std::rand() % 100) / 10.0),
Qt::SolidLine
);
item->SetContourPen(pen);
}
{
const QPen pen(
QBrush(qRgb(std::rand() % 256,std::rand() % 256,std::rand() % 256)),
1.0 + (static_cast<double>(std::rand() % 100) / 10.0),
Qt::DashLine
);
item->SetFocusPen(pen);
}
item->SetInnerHeight(200.0 * Random().GetFraction());
item->SetCenterPos(
-50.0 + (100.0 * Random().GetFraction()),
-50.0 + (100.0 * Random().GetFraction())
);
item->SetRadiusX(100.0 * Random().GetFraction());
item->SetRadiusY(100.0 * Random().GetFraction());
item->SetInnerWidth(200.0 * Random().GetFraction());
return item;
}
void ribi::QtTestQtRoundedRectItemModifyDialog::on_button_set_item_clicked()
{
const auto item = CreateRandomItem();
assert(item);
SetItem(item);
}
void ribi::QtTestQtRoundedRectItemModifyDialog::SetItem(const boost::shared_ptr<QtRoundedRectItem>& item) noexcept
{
m_dialog_left->SetItem(item);
m_dialog_right->SetItem(item);
if (!ui->view_left->scene())
{
assert(!ui->view_left->scene());
assert(!ui->view_right->scene());
QGraphicsScene * const scene = new QGraphicsScene;
ui->view_left->setScene(scene);
ui->view_right->setScene(scene);
}
assert(ui->view_left->scene());
assert(ui->view_right->scene());
assert(ui->view_left->scene() == ui->view_right->scene());
ui->view_left->scene()->clear();
ui->view_left->scene()->addItem(item.get());
}