PeriDyno 1.0.0
Loading...
Searching...
No Matches
QmValueDialog.cpp
Go to the documentation of this file.
1#include "QmValueDialog.h"
2
3#include "Module.h"
4#include "Node.h"
5#include "Field.h"
6#include "SceneGraphFactory.h"
7
8#include <QVBoxLayout>
9
10#include <memory>
11#include "QmDoubleSpinBox.h"
12
13namespace dyno
14{
15
16 ValueDialog::ValueDialog(QAbstractSpinBox* parent)
17 {
18
19 SBox1 = parent;
20
21 QVBoxLayout* VLayout = new QVBoxLayout;
22
23
24 // double
25 auto doubleSpinBox = TypeInfo::cast<mDoubleSpinBox>(parent);
26 if (doubleSpinBox != nullptr)
27 {
28
29 mDSpinBox = doubleSpinBox;
30 float power = 0.1;
31 for (int i = 0; i < 5; i++)
32 {
33 button[i] = new ValueButton;
34
35 power *= 0.1;
36
37 std::string s = std::to_string(power * 1000);
38 QString text = QString::fromStdString(s);
39
40 button[i]->setText(text);//initial
41 button[i]->setRealText(text);
42 button[i]->setFixedWidth(200);
43 button[i]->setFixedHeight(40);
44 button[i]->adjustSize();
45 //button[i]->setAlignment(Qt::AlignHCenter| Qt::AlignVCenter);
46 button[i]->setStyleSheet("QLabel{color:white;background-color:#346792;border: 1px solid #000000;border-radius:3px; padding: 0px;}");
47 button[i]->StartX = QCursor().pos().x();
48 button[i]->defaultValue = power * 1000;
49 button[i]->SpinBoxData = doubleSpinBox->getRealValue();
50 button[i]->parentDialog = this;
51 button[i]->buttonDSpinBox = doubleSpinBox;
52 VLayout->addWidget(button[i]);
53
54 connect(button[i], SIGNAL(ValueChange(double)), doubleSpinBox, SLOT(ModifyValueAndUpdate(double)));
55 connect(button[i], SIGNAL(Release(double)), this, SLOT(initData(double)));
56 }
57 }
58 // int
59 auto mIntSpinBox = TypeInfo::cast<QSpinBox>(parent);
60 if (mIntSpinBox != nullptr)
61 {
62 mISpinBox = mIntSpinBox;
63
64 int step[5] = {1,5,10,20,50};
65
66 for (int i = 0; i < 5; i++)
67 {
68 button[i] = new ValueButton;
69
70 std::string s = std::to_string(step[i]);
71 QString text = QString::fromStdString(s);
72
73 button[i]->setText(text);//initial
74 button[i]->setRealText(text);
75 button[i]->setFixedWidth(200);
76 button[i]->setFixedHeight(40);
77 button[i]->adjustSize();
78 //button[i]->setAlignment(Qt::AlignHCenter| Qt::AlignVCenter);
79 button[i]->setStyleSheet("QLabel{color:white;background-color:#346792;border: 1px solid #000000;border-radius:3px; padding: 0px;}");
80 button[i]->StartX = QCursor().pos().x();
81 button[i]->intDefaultValue = step[i];
82 button[i]->intBoxData = mISpinBox->value();
83 button[i]->parentDialog = this;
84 button[i]->buttonISpinBox = mIntSpinBox;
85
86 VLayout->addWidget(button[i]);
87
88 connect(button[i], SIGNAL(ValueChange(int)), mIntSpinBox, SLOT(setValue(int)));
89 connect(button[i], SIGNAL(Release(int)), this, SLOT(initData(int)));
90 }
91 }
92
93 VLayout->setSpacing(0);
94
95 this->setLayout(VLayout);
96 this->setWindowFlags(Qt::WindowStaysOnTopHint | Qt::WindowCloseButtonHint | Qt::Popup);
98 this->setMouseTracking(true);
99 this->hasMouseTracking();
100 this->setAttribute(Qt::WA_Hover, true);
101
102 this->setWindowTitle("Property Editor");
103
104 }
105
106
108 {
109 this->move(QCursor().pos().x() - button[1]->rect().width() / 2, QCursor().pos().y() - button[1]->rect().height() * 5 / 2 - 5);
110
111 }
112
113
114 void ValueDialog::mouseReleaseEvent(QMouseEvent* event)
115 {
116
117 }
118
119
120
121 void ValueDialog::keyPressEvent(QKeyEvent* event)
122 {
123 QDialog::keyPressEvent(event);
124 }
125
126 void ValueDialog::keyReleaseEvent(QKeyEvent* event)
127 {
128 QDialog::keyReleaseEvent(event);
129 }
130
132 {
133 if (mDSpinBox != nullptr)
134 {
135 for (int i = 0; i < 5; i++)
136 {
137 button[i]->SpinBoxData = v;
138 button[i]->Data1 = mDSpinBox->getRealValue();
139 }
140 }
141 }
142
144 {
145 if (mISpinBox != nullptr)
146 {
147 for (int i = 0; i < 5; i++)
148 {
149 button[i]->SpinBoxData = v;
150 button[i]->intData1 = mISpinBox->value();
151 }
152 }
153 }
154
155 void ValueDialog::mouseMoveEvent(QMouseEvent* event)
156 {
157
158 }
159
160 void ValueButton::mouseMoveEvent(QMouseEvent* event)
161 {
162 if (!mMousePressed)
163 return;
164
165 EndX = QCursor().pos().x();
166 temp = (EndX - StartX) / 10;
167
168 if(buttonDSpinBox !=nullptr)
169 {
171
173 str = std::to_string(defaultValue) + "\n" + std::to_string(SpinBoxData + sub);
174 else
175 str = std::to_string(sub);
176
177 text = QString::fromStdString(str);
178 this->setText(text);
179
181 }
182 else if (buttonISpinBox != nullptr)
183 {
185
187 str = std::to_string(intDefaultValue) + "\n" + std::to_string(intBoxData + intSub);
188 else
189 str = std::to_string(intSub);
190
191 text = QString::fromStdString(str);
192 this->setText(text);
193
194 emit ValueChange(int(intBoxData + intSub));
195
196 }
197 }
198
199 ValueButton::ValueButton(QWidget* parent) :
200 QPushButton(parent)
201 {
202
203 }
204
205 void ValueButton::mousePressEvent(QMouseEvent* event)
206 {
207 StartX = QCursor().pos().x();
208
209 if (buttonDSpinBox != nullptr)
210 {
211 SpinBoxData = buttonDSpinBox->getRealValue();
212 }
213 else if (buttonISpinBox != nullptr)
214 {
215 intBoxData = buttonISpinBox->value();
216 }
217
218 mMousePressed = true;
219 }
220
221 void ValueButton::mouseReleaseEvent(QMouseEvent* event)
222 {
223 if (buttonDSpinBox != nullptr)
224 {
225 str = std::to_string(defaultValue);
226 text = QString::fromStdString(str);
227 this->setText(text);
229
230 emit Release(SpinBoxData);
231 }
232 else if (buttonISpinBox != nullptr)
233 {
234 str = std::to_string(intDefaultValue);
235 text = QString::fromStdString(str);
236 this->setText(text);
238
239 emit Release(intBoxData);
240 }
241
242 mMousePressed = false;
243 }
244}
245
void mouseReleaseEvent(QMouseEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void Release(double)
void mousePressEvent(QMouseEvent *event) override
void ValueChange(double)
mDoubleSpinBox * buttonDSpinBox
ValueButton(QWidget *parent=nullptr)
QSpinBox * buttonISpinBox
mDoubleSpinBox * mDSpinBox
ValueButton * button[5]
QAbstractSpinBox * SBox1
ValueDialog(QAbstractSpinBox *parent=nullptr)
void mouseReleaseEvent(QMouseEvent *event) override
void initData(double)
QSpinBox * mISpinBox
void keyPressEvent(QKeyEvent *event) override
void mouseMoveEvent(QMouseEvent *event) override
void keyReleaseEvent(QKeyEvent *event) override
TA * cast(TB *b)
Definition Typedef.inl:286
This is an implementation of AdditiveCCD based on peridyno.
Definition Array.h:25