-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnaivetreedialog.cpp
167 lines (146 loc) · 5.97 KB
/
naivetreedialog.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
#include "naivetreedialog.h"
#include "ui_naivetreedialog.h"
#include "terrain.h"
#include "gardenwidget.h"
#define MIN(a, b) ((a) < (b) ? (a) : (b))
const int RADIUS_MIN = int(MIN(WIDTH / CELL_NUM / 2, LENGTH / CELL_NUM / 2) / 16);
const int RADIUS_MAX = int(MIN(WIDTH / CELL_NUM / 2, LENGTH / CELL_NUM / 2) / 4);
const int LEAF_RADIUS_MIN = int(MIN(WIDTH / CELL_NUM / 2, LENGTH / CELL_NUM / 2));
const int LEAF_RADIUS_MAX = int(MIN(WIDTH / CELL_NUM / 2, LENGTH / CELL_NUM / 2) * 3);
const int HEIGHT_MIN = int(HEIGHT / 32);
const int HEIGHT_MAX = int(HEIGHT / 8);
NaiveTreeDialog::NaiveTreeDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::NaiveTreeDialog)
{
ui->setupUi(this);
tree = nullptr;
connect(ui->base_radius_slider, SIGNAL(valueChanged(int)), ui->radius_label, SLOT(setNum(int)));
ui->base_radius_slider->setMinimum(RADIUS_MIN);
ui->base_radius_slider->setMaximum(RADIUS_MAX);
ui->base_radius_slider->setValue((RADIUS_MIN + RADIUS_MAX) / 2);
connect(ui->base_radius_slider, SIGNAL(valueChanged(int)), SLOT(on_base_radius_slider_valueChanged(int)));
connect(ui->height_slider, SIGNAL(valueChanged(int)), ui->height_label, SLOT(setNum(int)));
ui->height_slider->setMinimum(HEIGHT_MIN);
ui->height_slider->setMaximum(HEIGHT_MAX);
ui->height_slider->setValue((HEIGHT_MIN + HEIGHT_MAX) / 2);
connect(ui->height_slider, SIGNAL(valueChanged(int)), SLOT(on_height_slider_valueChanged(int)));
connect(ui->leaf_size_slider, SIGNAL(valueChanged(int)), ui->leaf_size_label, SLOT(setNum(int)));
ui->leaf_size_slider->setMinimum(LEAF_RADIUS_MIN);
ui->leaf_size_slider->setMaximum(LEAF_RADIUS_MAX);
ui->leaf_size_slider->setValue((LEAF_RADIUS_MIN + LEAF_RADIUS_MAX) / 2);
connect(ui->leaf_size_slider, SIGNAL(valueChanged(int)), SLOT(on_leaf_size_slider_valueChanged(int)));
connect(ui->rootR_slider, SIGNAL(valueChanged(int)), ui->rootR_label, SLOT(setNum(int)));
connect(ui->rootG_slider, SIGNAL(valueChanged(int)), ui->rootG_label, SLOT(setNum(int)));
connect(ui->rootB_slider, SIGNAL(valueChanged(int)), ui->rootB_label, SLOT(setNum(int)));
ui->rootR_slider->setMinimum(0);
ui->rootG_slider->setMinimum(0);
ui->rootB_slider->setMinimum(0);
ui->rootR_slider->setMaximum(255);
ui->rootG_slider->setMaximum(255);
ui->rootB_slider->setMaximum(255);
ui->rootR_slider->setValue(200);
ui->rootG_slider->setValue(150);
ui->rootB_slider->setValue(100);
connect(ui->rootR_slider, SIGNAL(valueChanged(int)), SLOT(on_rootR_slider_valueChanged(int)));
connect(ui->rootG_slider, SIGNAL(valueChanged(int)), SLOT(on_rootG_slider_valueChanged(int)));
connect(ui->rootB_slider, SIGNAL(valueChanged(int)), SLOT(on_rootB_slider_valueChanged(int)));
connect(ui->leafR_slider, SIGNAL(valueChanged(int)), ui->leafR_label, SLOT(setNum(int)));
connect(ui->leafG_slider, SIGNAL(valueChanged(int)), ui->leafG_label, SLOT(setNum(int)));
connect(ui->leafB_slider, SIGNAL(valueChanged(int)), ui->leafB_label, SLOT(setNum(int)));
ui->leafR_slider->setMinimum(0);
ui->leafG_slider->setMinimum(0);
ui->leafB_slider->setMinimum(0);
ui->leafR_slider->setMaximum(255);
ui->leafG_slider->setMaximum(255);
ui->leafB_slider->setMaximum(255);
ui->leafR_slider->setValue(25);
ui->leafG_slider->setValue(175);
ui->leafB_slider->setValue(25);
connect(ui->leafR_slider, SIGNAL(valueChanged(int)), SLOT(on_leafR_slider_valueChanged(int)));
connect(ui->leafG_slider, SIGNAL(valueChanged(int)), SLOT(on_leafG_slider_valueChanged(int)));
connect(ui->leafB_slider, SIGNAL(valueChanged(int)), SLOT(on_leafB_slider_valueChanged(int)));
}
NaiveTreeDialog::~NaiveTreeDialog()
{
delete ui;
}
void NaiveTreeDialog::setTree(NaiveTree *tree, bool exist) {
this->tree = tree;
this->exist = exist;
if (exist) {
info = tree->getInfo();
ui->base_radius_slider->setValue(info.base_radius);
ui->height_slider->setValue(info.height);
ui->leaf_size_slider->setValue(info.leaf_base_radius);
ui->rootR_slider->setValue(int(info.rootR * 255.0));
ui->rootG_slider->setValue(int(info.rootG * 255.0));
ui->rootB_slider->setValue(int(info.rootB * 255.0));
ui->leafR_slider->setValue(int(info.leafR * 255.0));
ui->leafG_slider->setValue(int(info.leafG * 255.0));
ui->leafB_slider->setValue(int(info.leafB * 255.0));
}
else {
ui->base_radius_slider->setValue((RADIUS_MIN + RADIUS_MAX) / 2);
ui->height_slider->setValue((HEIGHT_MIN + HEIGHT_MAX) / 2);
ui->leaf_size_slider->setValue((LEAF_RADIUS_MIN + LEAF_RADIUS_MAX) / 2);
ui->rootR_slider->setValue(200);
ui->rootG_slider->setValue(150);
ui->rootB_slider->setValue(100);
ui->leafR_slider->setValue(25);
ui->leafG_slider->setValue(175);
ui->leafB_slider->setValue(25);
}
}
void NaiveTreeDialog::recover() {
if (tree && exist)
tree->setInfo(info);
}
bool NaiveTreeDialog::isExist() {
return exist;
}
void NaiveTreeDialog::on_rootR_slider_valueChanged(int value)
{
if (tree)
tree->setRootR(value);
}
void NaiveTreeDialog::on_rootG_slider_valueChanged(int value)
{
if (tree)
tree->setRootG(value);
}
void NaiveTreeDialog::on_rootB_slider_valueChanged(int value)
{
if (tree)
tree->setRootB(value);
}
void NaiveTreeDialog::on_leafR_slider_valueChanged(int value)
{
if (tree)
tree->setLeafR(value);
}
void NaiveTreeDialog::on_leafG_slider_valueChanged(int value)
{
if (tree)
tree->setLeafG(value);
}
void NaiveTreeDialog::on_leafB_slider_valueChanged(int value)
{
if (tree)
tree->setLeafB(value);
}
void NaiveTreeDialog::on_base_radius_slider_valueChanged(int value)
{
if (tree)
tree->setBaseRadius(value);
}
void NaiveTreeDialog::on_height_slider_valueChanged(int value)
{
if (tree)
tree->setHeight(value);
}
void NaiveTreeDialog::on_leaf_size_slider_valueChanged(int value)
{
if (tree)
tree->setLeafRadius(value);
}