37 double IntRatioToFactor(
int intRatio)
45 double ratio = intRatio / 100.0;
46 return (ratio >= 0 ? (ratio + 1) : 1 / (1 - ratio));
49 int FactorToIntRatio(
double factor)
52 double ratio = factor >= 1.0 ? factor - 1 : 1 - 1 / factor;
53 return std::round(ratio * 100);
59 :
QWidget(parent), m_rotation(0), m_scaling_x(1.0), m_scaling_y(1.0), m_aspect_ratio_maintained(true), m_translation_x(0.0), m_translation_y(0.0), m_updating(false)
61 SetupGui(maxScaleRatio, maxTranslationX, maxTranslationY);
68 void TransformationWidget::UpdateRotation(
int degrees)
75 void TransformationWidget::UpdateScalingX(
double factor)
80 m_scaling_x_slider->setValue(FactorToIntRatio(factor));
81 if (m_aspect_ratio_maintained) {
82 m_scaling_y_spin_box->setValue(factor);
83 m_scaling_y_slider->setValue(m_scaling_x_slider->value());
91 void TransformationWidget::UpdateScalingX(
int value)
95 m_scaling_x_spin_box->setValue(IntRatioToFactor(value));
96 if (m_aspect_ratio_maintained) {
97 m_scaling_y_spin_box->setValue(m_scaling_x_spin_box->value());
98 m_scaling_y_slider->setValue(value);
106 void TransformationWidget::UpdateScalingY(
double factor)
108 m_scaling_y = factor;
111 m_scaling_y_slider->setValue(FactorToIntRatio(factor));
118 void TransformationWidget::UpdateScalingY(
int value)
122 m_scaling_y_spin_box->setValue(IntRatioToFactor(value));
129 void TransformationWidget::UpdateAspectRatioMaintained(
bool checked)
131 m_aspect_ratio_maintained = checked;
132 m_scaling_y_spin_box->setEnabled(!checked);
133 m_scaling_y_slider->setEnabled(!checked);
138 void TransformationWidget::UpdateTranslationX(
double position)
140 m_translation_x = position;
143 m_translation_x_slider->setValue(std::round(position * 100));
150 void TransformationWidget::UpdateTranslationX(
int position)
154 m_translation_x_spin_box->setValue(position / 100.0);
161 void TransformationWidget::UpdateTranslationY(
double position)
163 m_translation_y = position;
166 m_translation_y_slider->setValue(std::round(position * 100));
173 void TransformationWidget::UpdateTranslationY(
int position)
177 m_translation_y_spin_box->setValue(position / 100.0);
185 void TransformationWidget::SetupGui(
int maxScaleRatio,
double maxTranslationX,
double maxTranslationY)
188 QVBoxLayout *layout =
new QVBoxLayout();
191 QHBoxLayout *rotationLayout =
new QHBoxLayout();
192 rotationLayout->addWidget(
new QLabel(
"rotation"));
193 rotationLayout->addStretch();
195 QSpinBox *rotationSpinBox =
new QSpinBox();
196 rotationSpinBox->setRange(-180, 180);
197 rotationSpinBox->setValue(0);
198 rotationSpinBox->setSuffix(QString::fromUtf8(
"��"));
199 rotationLayout->addWidget(rotationSpinBox);
200 layout->addLayout(rotationLayout);
202 QDial *rotationDial =
new QDial();
203 rotationDial->setRange(-180, 180);
204 rotationDial->setWrapping(
true);
205 rotationDial->setValue(0);
206 layout->addWidget(rotationDial);
208 connect(rotationSpinBox, SIGNAL(valueChanged(
int)), rotationDial, SLOT(setValue(
int)));
209 connect(rotationDial, SIGNAL(valueChanged(
int)), rotationSpinBox, SLOT(setValue(
int)));
210 connect(rotationDial, SIGNAL(valueChanged(
int)),
this, SLOT(UpdateRotation(
int)));
213 QFrame *line =
new QFrame();
214 line->setFrameShape(QFrame::HLine);
215 line->setFrameShadow(QFrame::Sunken);
216 layout->addWidget(line);
219 QHBoxLayout *scalingXLayout =
new QHBoxLayout();
220 scalingXLayout->addWidget(
new QLabel(
"x scale"));
221 scalingXLayout->addStretch();
223 m_scaling_x_spin_box =
new QDoubleSpinBox();
224 m_scaling_x_spin_box->setRange(1.0 / maxScaleRatio, maxScaleRatio);
225 m_scaling_x_spin_box->setValue(m_scaling_x);
226 m_scaling_x_spin_box->setDecimals(2);
227 m_scaling_x_spin_box->setSingleStep(0.1);
228 scalingXLayout->addWidget(m_scaling_x_spin_box);
229 layout->addLayout(scalingXLayout);
231 m_scaling_x_slider =
new QSlider(Qt::Horizontal);
232 m_scaling_x_slider->setRange((1 - maxScaleRatio) * 100, (maxScaleRatio - 1) * 100);
233 m_scaling_x_slider->setValue(0);
234 layout->addWidget(m_scaling_x_slider);
236 connect(m_scaling_x_spin_box, SIGNAL(valueChanged(
double)),
this, SLOT(UpdateScalingX(
double)));
237 connect(m_scaling_x_slider, SIGNAL(valueChanged(
int)),
this, SLOT(UpdateScalingX(
int)));
239 QHBoxLayout *scalingYLayout =
new QHBoxLayout();
240 scalingYLayout->addWidget(
new QLabel(
"y scale"));
241 scalingYLayout->addStretch();
243 m_scaling_y_spin_box =
new QDoubleSpinBox();
244 m_scaling_y_spin_box->setRange(1.0 / maxScaleRatio, maxScaleRatio);
245 m_scaling_y_spin_box->setValue(m_scaling_y);
246 m_scaling_y_spin_box->setDecimals(2);
247 m_scaling_y_spin_box->setSingleStep(0.1);
248 scalingYLayout->addWidget(m_scaling_y_spin_box);
249 layout->addLayout(scalingYLayout);
251 m_scaling_y_slider =
new QSlider(Qt::Horizontal);
252 m_scaling_y_slider->setRange((1 - maxScaleRatio) * 100, (maxScaleRatio - 1) * 100);
253 m_scaling_y_slider->setValue(0);
254 layout->addWidget(m_scaling_y_slider);
256 connect(m_scaling_y_spin_box, SIGNAL(valueChanged(
double)),
this, SLOT(UpdateScalingY(
double)));
257 connect(m_scaling_y_slider, SIGNAL(valueChanged(
int)),
this, SLOT(UpdateScalingY(
int)));
259 QCheckBox *aspectRatio =
new QCheckBox(
"Maintain aspect ratio");
260 aspectRatio->setChecked(m_aspect_ratio_maintained);
261 UpdateAspectRatioMaintained(m_aspect_ratio_maintained);
262 connect(aspectRatio, SIGNAL(toggled(
bool)),
this, SLOT(UpdateAspectRatioMaintained(
bool)));
264 layout->addWidget(aspectRatio);
268 line->setFrameShape(QFrame::HLine);
269 line->setFrameShadow(QFrame::Sunken);
270 layout->addWidget(line);
273 QHBoxLayout *translationXLayout =
new QHBoxLayout();
274 translationXLayout->addWidget(
new QLabel(
"x offset"));
275 translationXLayout->addStretch();
277 m_translation_x_spin_box =
new QDoubleSpinBox();
278 m_translation_x_spin_box->setRange(-maxTranslationX, maxTranslationX);
279 m_translation_x_spin_box->setValue(m_translation_x);
280 m_translation_x_spin_box->setDecimals(2);
281 translationXLayout->addWidget(m_translation_x_spin_box);
282 layout->addLayout(translationXLayout);
284 m_translation_x_slider =
new QSlider(Qt::Horizontal);
285 m_translation_x_slider->setRange(-std::nearbyint(maxTranslationX * 100), std::nearbyint(maxTranslationX * 100));
286 m_translation_x_slider->setValue(0);
287 layout->addWidget(m_translation_x_slider);
289 connect(m_translation_x_spin_box, SIGNAL(valueChanged(
double)),
this, SLOT(UpdateTranslationX(
double)));
290 connect(m_translation_x_slider, SIGNAL(valueChanged(
int)),
this, SLOT(UpdateTranslationX(
int)));
292 QHBoxLayout *translationYLayout =
new QHBoxLayout();
293 translationYLayout->addWidget(
new QLabel(
"y offset"));
294 translationYLayout->addStretch();
296 m_translation_y_spin_box =
new QDoubleSpinBox();
297 m_translation_y_spin_box->setRange(-maxTranslationY, maxTranslationY);
298 m_translation_y_spin_box->setValue(m_translation_y);
299 m_translation_y_spin_box->setDecimals(2);
300 translationYLayout->addWidget(m_translation_y_spin_box);
301 layout->addLayout(translationYLayout);
303 m_translation_y_slider =
new QSlider(Qt::Horizontal);
304 m_translation_y_slider->setRange(-std::nearbyint(maxTranslationY * 100), std::nearbyint(maxTranslationY * 100));
305 m_translation_y_slider->setValue(0);
306 layout->addWidget(m_translation_y_slider);
308 connect(m_translation_y_spin_box, SIGNAL(valueChanged(
double)),
this, SLOT(UpdateTranslationY(
double)));
309 connect(m_translation_y_slider, SIGNAL(valueChanged(
int)),
this, SLOT(UpdateTranslationY(
int)));
void TransformationChanged()
Emitted when the transformation is changed by the user.
Namespace for SimPT tissue editor package.
Interface for TransformationWidget.
TransformationWidget(int maxScaleRatio, double maxTranslationX, double maxTranslationY, QWidget *parent=nullptr)
Constructor.
virtual ~TransformationWidget()
Destructor.
see the online Qt documentation