Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtgradienteditor.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
7#include "ui_qtgradienteditor.h"
8
9#include <QtWidgets/qbuttongroup.h>
10
12
13using namespace Qt::StringLiterals;
14
16{
17 Q_OBJECT
18 QtGradientEditor *q_ptr;
20public:
22
23 void setBackgroundCheckered(bool checkered);
24
25 void slotGradientStopsChanged(const QGradientStops &stops);
26 void slotTypeChanged(int type);
27 void slotSpreadChanged(int spread);
28 void slotStartLinearXChanged(double value);
29 void slotStartLinearYChanged(double value);
30 void slotEndLinearXChanged(double value);
31 void slotEndLinearYChanged(double value);
32 void slotCentralRadialXChanged(double value);
33 void slotCentralRadialYChanged(double value);
34 void slotFocalRadialXChanged(double value);
35 void slotFocalRadialYChanged(double value);
36 void slotRadiusRadialChanged(double value);
37 void slotCentralConicalXChanged(double value);
38 void slotCentralConicalYChanged(double value);
39 void slotAngleConicalChanged(double value);
40
41 void slotDetailsChanged(bool details);
42
43 void startLinearChanged(QPointF point);
44 void endLinearChanged(QPointF point);
45 void centralRadialChanged(QPointF point);
46 void focalRadialChanged(QPointF point);
47 void radiusRadialChanged(qreal radius);
48 void centralConicalChanged(const QPointF &point);
49 void angleConicalChanged(qreal angle);
50
51 void setStartLinear(QPointF point);
52 void setEndLinear(QPointF point);
53 void setCentralRadial(QPointF point);
54 void setFocalRadial(QPointF point);
55 void setRadiusRadial(qreal radius);
56 void setCentralConical(QPointF point);
57 void setAngleConical(qreal angle);
58
59 void setType(QGradient::Type type);
60 void showDetails(bool details);
61
62 using DoubleSlotPtr = void (QtGradientEditorPrivate::*)(double);
63 void setupSpinBox(QDoubleSpinBox *spinBox, DoubleSlotPtr slot, double max = 1.0, double step = 0.01, int decimals = 3);
64 void reset();
65 void setLayout(bool details);
66 void layoutDetails(bool details);
67 bool row4Visible() const;
68 bool row5Visible() const;
69 int extensionWidthHint() const;
70
71 void setCombos(bool combos);
72
74 void updateGradient(bool emitSignal);
75
76 Ui::QtGradientEditor m_ui;
78
91
94
96
100 bool m_details = false;
103
105
106 bool m_combos = true;
107};
108
109QtGradientEditorPrivate::QtGradientEditorPrivate(QtGradientEditor *q)
110 : q_ptr(q)
111 , m_gradientStopsController(new QtGradientStopsController(this))
112 , m_gradient(QLinearGradient())
113{
114 m_ui.setupUi(q_ptr);
116 reset();
117 setType(QGradient::LinearGradient);
119
122
123 setStartLinear(QPointF(0, 0));
124 setEndLinear(QPointF(1, 1));
125 setCentralRadial(QPointF(0.5, 0.5));
126 setFocalRadial(QPointF(0.5, 0.5));
127 setRadiusRadial(0.5);
128 setCentralConical(QPointF(0.5, 0.5));
129 setAngleConical(0);
130
131 QIcon icon;
132 icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowRight), QIcon::Normal, QIcon::Off);
133 icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowLeft), QIcon::Normal, QIcon::On);
134 m_ui.detailsButton->setIcon(icon);
135
136 connect(m_ui.detailsButton, &QAbstractButton::clicked,
138 connect(m_gradientStopsController, &QtGradientStopsController::gradientStopsChanged,
139 this, &QtGradientEditorPrivate::slotGradientStopsChanged);
140
141 QIcon iconLinear(":/qt-project.org/qtgradienteditor/images/typelinear.png"_L1);
142 QIcon iconRadial(":/qt-project.org/qtgradienteditor/images/typeradial.png"_L1);
143 QIcon iconConical(":/qt-project.org/qtgradienteditor/images/typeconical.png"_L1);
144
145 m_ui.typeComboBox->addItem(iconLinear, QtGradientEditor::tr("Linear"));
146 m_ui.typeComboBox->addItem(iconRadial, QtGradientEditor::tr("Radial"));
147 m_ui.typeComboBox->addItem(iconConical, QtGradientEditor::tr("Conical"));
148
149 m_ui.linearButton->setIcon(iconLinear);
150 m_ui.radialButton->setIcon(iconRadial);
151 m_ui.conicalButton->setIcon(iconConical);
152
153 m_typeGroup = new QButtonGroup(this);
154 m_typeGroup->addButton(m_ui.linearButton, 0);
155 m_typeGroup->addButton(m_ui.radialButton, 1);
156 m_typeGroup->addButton(m_ui.conicalButton, 2);
157
158 connect(m_typeGroup, &QButtonGroup::idClicked,
160 connect(m_ui.typeComboBox, &QComboBox::activated,
162
163 QIcon iconPad(":/qt-project.org/qtgradienteditor/images/spreadpad.png"_L1);
164 QIcon iconRepeat(":/qt-project.org/qtgradienteditor/images/spreadrepeat.png"_L1);
165 QIcon iconReflect(":/qt-project.org/qtgradienteditor/images/spreadreflect.png"_L1);
166
167 m_ui.spreadComboBox->addItem(iconPad, QtGradientEditor::tr("Pad"));
168 m_ui.spreadComboBox->addItem(iconRepeat, QtGradientEditor::tr("Repeat"));
169 m_ui.spreadComboBox->addItem(iconReflect, QtGradientEditor::tr("Reflect"));
170
171 m_ui.padButton->setIcon(iconPad);
172 m_ui.repeatButton->setIcon(iconRepeat);
173 m_ui.reflectButton->setIcon(iconReflect);
174
175 m_spreadGroup = new QButtonGroup(this);
176 m_spreadGroup->addButton(m_ui.padButton, 0);
177 m_spreadGroup->addButton(m_ui.repeatButton, 1);
178 m_spreadGroup->addButton(m_ui.reflectButton, 2);
179 connect(m_spreadGroup, &QButtonGroup::idClicked,
181 connect(m_ui.spreadComboBox, &QComboBox::activated,
183
184 connect(m_ui.gradientWidget, &QtGradientWidget::startLinearChanged,
185 this, &QtGradientEditorPrivate::startLinearChanged);
186 connect(m_ui.gradientWidget, &QtGradientWidget::endLinearChanged,
187 this, &QtGradientEditorPrivate::endLinearChanged);
188 connect(m_ui.gradientWidget, &QtGradientWidget::centralRadialChanged,
189 this, &QtGradientEditorPrivate::centralRadialChanged);
190 connect(m_ui.gradientWidget, &QtGradientWidget::focalRadialChanged,
191 this, &QtGradientEditorPrivate::focalRadialChanged);
192 connect(m_ui.gradientWidget, &QtGradientWidget::radiusRadialChanged,
193 this, &QtGradientEditorPrivate::radiusRadialChanged);
194 connect(m_ui.gradientWidget, &QtGradientWidget::centralConicalChanged,
195 this, &QtGradientEditorPrivate::centralConicalChanged);
196 connect(m_ui.gradientWidget, &QtGradientWidget::angleConicalChanged,
197 this, &QtGradientEditorPrivate::angleConicalChanged);
198
199 QGradientStops stops = gradient().stops();
200 m_gradientStopsController->setGradientStops(stops);
201 m_ui.gradientWidget->setGradientStops(stops);
202}
203
205{
206 QGradient *gradient = nullptr;
207 switch (m_ui.gradientWidget->gradientType()) {
208 case QGradient::LinearGradient:
209 gradient = new QLinearGradient(m_ui.gradientWidget->startLinear(),
210 m_ui.gradientWidget->endLinear());
211 break;
212 case QGradient::RadialGradient:
213 gradient = new QRadialGradient(m_ui.gradientWidget->centralRadial(),
214 m_ui.gradientWidget->radiusRadial(),
215 m_ui.gradientWidget->focalRadial());
216 break;
217 case QGradient::ConicalGradient:
218 gradient = new QConicalGradient(m_ui.gradientWidget->centralConical(),
219 m_ui.gradientWidget->angleConical());
220 break;
221 default:
222 break;
223 }
224 if (!gradient)
225 return QGradient();
226 gradient->setStops(m_ui.gradientWidget->gradientStops());
227 gradient->setSpread(m_ui.gradientWidget->gradientSpread());
228 gradient->setCoordinateMode(QGradient::StretchToDeviceMode);
229 QGradient gr = *gradient;
230 delete gradient;
231 return gr;
232}
233
235{
236 QGradient grad = gradient();
237 if (m_gradient == grad)
238 return;
239
240 m_gradient = grad;
241 if (emitSignal)
242 emit q_ptr->gradientChanged(m_gradient);
243}
244
246{
247 if (m_combos == combos)
248 return;
249
250 m_combos = combos;
251 m_ui.linearButton->setVisible(!m_combos);
252 m_ui.radialButton->setVisible(!m_combos);
253 m_ui.conicalButton->setVisible(!m_combos);
254 m_ui.padButton->setVisible(!m_combos);
255 m_ui.repeatButton->setVisible(!m_combos);
256 m_ui.reflectButton->setVisible(!m_combos);
257 m_ui.typeComboBox->setVisible(m_combos);
258 m_ui.spreadComboBox->setVisible(m_combos);
259}
260
262{
263 QHBoxLayout *hboxLayout = new QHBoxLayout();
264 hboxLayout->setObjectName(QString::fromUtf8("hboxLayout"));
265 hboxLayout->addWidget(m_ui.typeComboBox);
266 hboxLayout->addWidget(m_ui.spreadComboBox);
267 QHBoxLayout *typeLayout = new QHBoxLayout();
268 typeLayout->setSpacing(0);
269 typeLayout->addWidget(m_ui.linearButton);
270 typeLayout->addWidget(m_ui.radialButton);
271 typeLayout->addWidget(m_ui.conicalButton);
272 hboxLayout->addLayout(typeLayout);
273 QHBoxLayout *spreadLayout = new QHBoxLayout();
274 spreadLayout->setSpacing(0);
275 spreadLayout->addWidget(m_ui.padButton);
276 spreadLayout->addWidget(m_ui.repeatButton);
277 spreadLayout->addWidget(m_ui.reflectButton);
278 hboxLayout->addLayout(spreadLayout);
279 hboxLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
280 hboxLayout->addWidget(m_ui.detailsButton);
281 m_gridLayout->addLayout(hboxLayout, 0, 0, 1, 2);
282 int span = 1;
283 if (details)
284 span = 7;
285 m_gridLayout->addWidget(m_ui.frame, 1, 0, span, 2);
286 int row = 2;
287 if (details) {
288 row = 8;
289 span = 4;
290 }
291 m_gridLayout->addWidget(m_ui.gradientStopsWidget, row, 0, span, 2);
292 QHBoxLayout *hboxLayout1 = new QHBoxLayout();
293 hboxLayout1->setObjectName(QString::fromUtf8("hboxLayout1"));
294 hboxLayout1->addWidget(m_ui.colorLabel);
295 hboxLayout1->addWidget(m_ui.colorButton);
296 hboxLayout1->addWidget(m_ui.hsvRadioButton);
297 hboxLayout1->addWidget(m_ui.rgbRadioButton);
298 hboxLayout1->addItem(new QSpacerItem(16, 23, QSizePolicy::Expanding, QSizePolicy::Minimum));
299 int addRow = 0;
300 if (details)
301 addRow = 9;
302 m_gridLayout->addLayout(hboxLayout1, 3 + addRow, 0, 1, 2);
303 m_gridLayout->addWidget(m_ui.hLabel, 4 + addRow, 0, 1, 1);
304 m_gridLayout->addWidget(m_ui.frame_2, 4 + addRow, 1, 1, 1);
305 m_gridLayout->addWidget(m_ui.sLabel, 5 + addRow, 0, 1, 1);
306 m_gridLayout->addWidget(m_ui.frame_5, 5 + addRow, 1, 1, 1);
307 m_gridLayout->addWidget(m_ui.vLabel, 6 + addRow, 0, 1, 1);
308 m_gridLayout->addWidget(m_ui.frame_3, 6 + addRow, 1, 1, 1);
309 m_gridLayout->addWidget(m_ui.aLabel, 7 + addRow, 0, 1, 1);
310 m_gridLayout->addWidget(m_ui.frame_4, 7 + addRow, 1, 1, 1);
311
312 if (details) {
313 layoutDetails(details);
314 }
315}
316
318{
319 QGridLayout *gridLayout = m_gridLayout;
320 int col = 2;
321 if (!details) {
322 col = 0;
323 if (!m_hiddenWidget) {
324 m_hiddenWidget = new QWidget();
325 m_hiddenLayout = new QGridLayout(m_hiddenWidget);
326 m_hiddenLayout->setContentsMargins(0, 0, 0, 0);
327 m_hiddenLayout->setSizeConstraint(QLayout::SetFixedSize);
328 }
329 gridLayout = m_hiddenLayout;
330 }
331 gridLayout->addWidget(m_ui.label1, 1, col + 0, 1, 1);
332 gridLayout->addWidget(m_ui.spinBox1, 1, col + 1, 1, 1);
333 gridLayout->addWidget(m_ui.label2, 2, col + 0, 1, 1);
334 gridLayout->addWidget(m_ui.spinBox2, 2, col + 1, 1, 1);
335 gridLayout->addWidget(m_ui.label3, 3, col + 0, 1, 1);
336 gridLayout->addWidget(m_ui.spinBox3, 3, col + 1, 1, 1);
337 gridLayout->addWidget(m_ui.label4, 4, col + 0, 1, 1);
338 gridLayout->addWidget(m_ui.spinBox4, 4, col + 1, 1, 1);
339 gridLayout->addWidget(m_ui.label5, 5, col + 0, 1, 1);
340 gridLayout->addWidget(m_ui.spinBox5, 5, col + 1, 1, 1);
341 gridLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 6, col + 0, 1, 1);
342 gridLayout->addWidget(m_ui.line1Widget, 7, col + 0, 1, 2);
343 gridLayout->addWidget(m_ui.zoomLabel, 8, col + 0, 1, 1);
344 gridLayout->addWidget(m_ui.zoomWidget, 8, col + 1, 1, 1);
345 gridLayout->addWidget(m_ui.zoomButtonsWidget, 9, col + 0, 1, 1);
346 gridLayout->addWidget(m_ui.zoomAllButton, 9, col + 1, 1, 1);
347 gridLayout->addItem(new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Preferred), 10, col + 0, 1, 1);
348 gridLayout->addWidget(m_ui.line2Widget, 11, col + 0, 1, 2);
349 gridLayout->addWidget(m_ui.positionLabel, 12, col + 0, 1, 1);
350 gridLayout->addWidget(m_ui.positionWidget, 12, col + 1, 1, 1);
351 gridLayout->addWidget(m_ui.hueLabel, 13, col + 0, 1, 1);
352 gridLayout->addWidget(m_ui.hueWidget, 13, col + 1, 1, 1);
353 gridLayout->addWidget(m_ui.saturationLabel, 14, col + 0, 1, 1);
354 gridLayout->addWidget(m_ui.saturationWidget, 14, col + 1, 1, 1);
355 gridLayout->addWidget(m_ui.valueLabel, 15, col + 0, 1, 1);
356 gridLayout->addWidget(m_ui.valueWidget, 15, col + 1, 1, 1);
357 gridLayout->addWidget(m_ui.alphaLabel, 16, col + 0, 1, 1);
358 gridLayout->addWidget(m_ui.alphaWidget, 16, col + 1, 1, 1);
359
360 if (details) {
361 if (m_hiddenLayout) {
362 delete m_hiddenLayout;
363 m_hiddenLayout = 0;
364 }
365 if (m_hiddenWidget) {
366 delete m_hiddenWidget;
367 m_hiddenWidget = 0;
368 }
369 }
370}
371
373{
374 if (m_details)
375 return q_ptr->size().width() - m_ui.gradientStopsWidget->size().width();
376
377 const int space = m_ui.spinBox1->geometry().left() - m_ui.label1->geometry().right();
378
379 return m_hiddenLayout->minimumSize().width() + space;
380}
381
383{
384 if (m_details == details)
385 return;
386
387 showDetails(details);
388}
389
391{
392 if (m_type == QGradient::ConicalGradient)
393 return false;
394 return true;
395}
396
398{
399 if (m_type == QGradient::RadialGradient)
400 return true;
401 return false;
402}
403
405{
406 bool blocked = m_ui.detailsButton->signalsBlocked();
407 m_ui.detailsButton->blockSignals(true);
408 m_ui.detailsButton->setChecked(details);
409 m_ui.detailsButton->blockSignals(blocked);
410
411 bool updates = q_ptr->updatesEnabled();
412 q_ptr->setUpdatesEnabled(false);
413
414 if (m_gridLayout) {
415 m_gridLayout->setEnabled(false);
416 delete m_gridLayout;
417 m_gridLayout = 0;
418 }
419
420 if (!details) {
421 layoutDetails(details);
422 }
423
424 emit q_ptr->aboutToShowDetails(details, extensionWidthHint());
425 m_details = details;
426
427 m_gridLayout = new QGridLayout(q_ptr);
428 m_gridLayout->setEnabled(false);
429 m_gridLayout->setObjectName(QString::fromUtf8("gridLayout"));
430 m_gridLayout->setContentsMargins(0, 0, 0, 0);
431
432 m_ui.label4->setVisible(row4Visible());
433 m_ui.label5->setVisible(row5Visible());
434 m_ui.spinBox4->setVisible(row4Visible());
435 m_ui.spinBox5->setVisible(row5Visible());
436
437 setLayout(details);
438 m_gridLayout->setEnabled(true);
439
440 q_ptr->setUpdatesEnabled(updates);
441 q_ptr->update();
442}
443
444void QtGradientEditorPrivate::setupSpinBox(QDoubleSpinBox *spinBox, DoubleSlotPtr slot,
445 double max, double step, int decimals)
446{
447 bool blocked = spinBox->signalsBlocked();
448 spinBox->blockSignals(true);
449 spinBox->setDecimals(decimals);
450 spinBox->setMaximum(max);
451 spinBox->setSingleStep(step);
452 spinBox->blockSignals(blocked);
453 QObject::connect(spinBox, &QDoubleSpinBox::valueChanged, this, slot);
454}
455
457{
458 startLinearXSpinBox = 0;
459 startLinearYSpinBox = 0;
460 endLinearXSpinBox = 0;
461 endLinearYSpinBox = 0;
462 centralRadialXSpinBox = 0;
463 centralRadialYSpinBox = 0;
464 focalRadialXSpinBox = 0;
465 focalRadialYSpinBox = 0;
466 radiusRadialSpinBox = 0;
467 centralConicalXSpinBox = 0;
468 centralConicalYSpinBox = 0;
469 angleConicalSpinBox = 0;
470}
471
472void QtGradientEditorPrivate::setType(QGradient::Type type)
473{
474 if (m_type == type)
475 return;
476
477 m_type = type;
478 m_ui.spinBox1->disconnect(this);
479 m_ui.spinBox2->disconnect(this);
480 m_ui.spinBox3->disconnect(this);
481 m_ui.spinBox4->disconnect(this);
482 m_ui.spinBox5->disconnect(this);
483
484 reset();
485
486 bool ena = true;
487
488 if (m_gridLayout) {
489 ena = m_gridLayout->isEnabled();
490 m_gridLayout->setEnabled(false);
491 }
492
493 bool spreadEnabled = true;
494
495 if (type == QGradient::LinearGradient) {
496 startLinearXSpinBox = m_ui.spinBox1;
497 setupSpinBox(startLinearXSpinBox, &QtGradientEditorPrivate::slotStartLinearXChanged);
498 m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Start X"));
499
500 startLinearYSpinBox = m_ui.spinBox2;
501 setupSpinBox(startLinearYSpinBox, &QtGradientEditorPrivate::slotStartLinearYChanged);
502 m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Start Y"));
503
504 endLinearXSpinBox = m_ui.spinBox3;
505 setupSpinBox(endLinearXSpinBox, &QtGradientEditorPrivate::slotEndLinearXChanged);
506 m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Final X"));
507
508 endLinearYSpinBox = m_ui.spinBox4;
509 setupSpinBox(endLinearYSpinBox, &QtGradientEditorPrivate::slotEndLinearYChanged);
510 m_ui.label4->setText(QCoreApplication::translate("QtGradientEditor", "Final Y"));
511
512 setStartLinear(m_ui.gradientWidget->startLinear());
513 setEndLinear(m_ui.gradientWidget->endLinear());
514 } else if (type == QGradient::RadialGradient) {
515 centralRadialXSpinBox = m_ui.spinBox1;
516 setupSpinBox(centralRadialXSpinBox, &QtGradientEditorPrivate::slotCentralRadialXChanged);
517 m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Central X"));
518
519 centralRadialYSpinBox = m_ui.spinBox2;
520 setupSpinBox(centralRadialYSpinBox, &QtGradientEditorPrivate::slotCentralRadialYChanged);
521 m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Central Y"));
522
523 focalRadialXSpinBox = m_ui.spinBox3;
524 setupSpinBox(focalRadialXSpinBox, &QtGradientEditorPrivate::slotFocalRadialXChanged);
525 m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Focal X"));
526
527 focalRadialYSpinBox = m_ui.spinBox4;
528 setupSpinBox(focalRadialYSpinBox, &QtGradientEditorPrivate::slotFocalRadialYChanged);
529 m_ui.label4->setText(QCoreApplication::translate("QtGradientEditor", "Focal Y"));
530
531 radiusRadialSpinBox = m_ui.spinBox5;
532 setupSpinBox(radiusRadialSpinBox, &QtGradientEditorPrivate::slotRadiusRadialChanged, 2.0);
533 m_ui.label5->setText(QCoreApplication::translate("QtGradientEditor", "Radius"));
534
535 setCentralRadial(m_ui.gradientWidget->centralRadial());
536 setFocalRadial(m_ui.gradientWidget->focalRadial());
537 setRadiusRadial(m_ui.gradientWidget->radiusRadial());
538 } else if (type == QGradient::ConicalGradient) {
539 centralConicalXSpinBox = m_ui.spinBox1;
540 setupSpinBox(centralConicalXSpinBox, &QtGradientEditorPrivate::slotCentralConicalXChanged);
541 m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Central X"));
542
543 centralConicalYSpinBox = m_ui.spinBox2;
544 setupSpinBox(centralConicalYSpinBox, &QtGradientEditorPrivate::slotCentralConicalYChanged);
545 m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Central Y"));
546
547 angleConicalSpinBox = m_ui.spinBox3;
548 setupSpinBox(angleConicalSpinBox, &QtGradientEditorPrivate::slotAngleConicalChanged, 360.0, 1.0, 1);
549 m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Angle"));
550
551 setCentralConical(m_ui.gradientWidget->centralConical());
552 setAngleConical(m_ui.gradientWidget->angleConical());
553
554 spreadEnabled = false;
555 }
556 m_ui.spreadComboBox->setEnabled(spreadEnabled);
557 m_ui.padButton->setEnabled(spreadEnabled);
558 m_ui.repeatButton->setEnabled(spreadEnabled);
559 m_ui.reflectButton->setEnabled(spreadEnabled);
560
561 m_ui.label4->setVisible(row4Visible());
562 m_ui.spinBox4->setVisible(row4Visible());
563 m_ui.label5->setVisible(row5Visible());
564 m_ui.spinBox5->setVisible(row5Visible());
565
566 if (m_gridLayout)
567 m_gridLayout->setEnabled(ena);
568}
569
571{
572 m_backgroundCheckered = checkered;
573 m_ui.hueColorLine->setBackgroundCheckered(checkered);
574 m_ui.saturationColorLine->setBackgroundCheckered(checkered);
575 m_ui.valueColorLine->setBackgroundCheckered(checkered);
576 m_ui.alphaColorLine->setBackgroundCheckered(checkered);
577 m_ui.gradientWidget->setBackgroundCheckered(checkered);
578 m_ui.gradientStopsWidget->setBackgroundCheckered(checkered);
579 m_ui.colorButton->setBackgroundCheckered(checkered);
580}
581
582void QtGradientEditorPrivate::slotGradientStopsChanged(const QGradientStops &stops)
583{
584 m_ui.gradientWidget->setGradientStops(stops);
586}
587
589{
590 QGradient::Type type = QGradient::NoGradient;
591 if (idx == 0)
592 type = QGradient::LinearGradient;
593 else if (idx == 1)
594 type = QGradient::RadialGradient;
595 else if (idx == 2)
596 type = QGradient::ConicalGradient;
597 setType(type);
598 m_ui.typeComboBox->setCurrentIndex(idx);
599 m_typeGroup->button(idx)->setChecked(true);
600 m_ui.gradientWidget->setGradientType(type);
602}
603
605{
606 if (spread == 0) {
607 m_ui.gradientWidget->setGradientSpread(QGradient::PadSpread);
608 } else if (spread == 1) {
609 m_ui.gradientWidget->setGradientSpread(QGradient::RepeatSpread);
610 } else if (spread == 2) {
611 m_ui.gradientWidget->setGradientSpread(QGradient::ReflectSpread);
612 }
613 m_ui.spreadComboBox->setCurrentIndex(spread);
615}
616
618{
619 QPointF point = m_ui.gradientWidget->startLinear();
620 point.setX(value);
621 m_ui.gradientWidget->setStartLinear(point);
623}
624
626{
627 QPointF point = m_ui.gradientWidget->startLinear();
628 point.setY(value);
629 m_ui.gradientWidget->setStartLinear(point);
631}
632
634{
635 QPointF point = m_ui.gradientWidget->endLinear();
636 point.setX(value);
637 m_ui.gradientWidget->setEndLinear(point);
639}
640
642{
643 QPointF point = m_ui.gradientWidget->endLinear();
644 point.setY(value);
645 m_ui.gradientWidget->setEndLinear(point);
647}
648
650{
651 QPointF point = m_ui.gradientWidget->centralRadial();
652 point.setX(value);
653 m_ui.gradientWidget->setCentralRadial(point);
655}
656
658{
659 QPointF point = m_ui.gradientWidget->centralRadial();
660 point.setY(value);
661 m_ui.gradientWidget->setCentralRadial(point);
663}
664
666{
667 QPointF point = m_ui.gradientWidget->focalRadial();
668 point.setX(value);
669 m_ui.gradientWidget->setFocalRadial(point);
671}
672
674{
675 QPointF point = m_ui.gradientWidget->focalRadial();
676 point.setY(value);
677 m_ui.gradientWidget->setFocalRadial(point);
679}
680
682{
683 m_ui.gradientWidget->setRadiusRadial(value);
685}
686
688{
689 QPointF point = m_ui.gradientWidget->centralConical();
690 point.setX(value);
691 m_ui.gradientWidget->setCentralConical(point);
693}
694
696{
697 QPointF point = m_ui.gradientWidget->centralConical();
698 point.setY(value);
699 m_ui.gradientWidget->setCentralConical(point);
701}
702
704{
705 m_ui.gradientWidget->setAngleConical(value);
707}
708
710{
711 setStartLinear(point);
713}
714
716{
717 setEndLinear(point);
719}
720
722{
723 setCentralRadial(point);
725}
726
728{
729 setFocalRadial(point);
731}
732
734{
735 setRadiusRadial(radius);
737}
738
740{
741 setCentralConical(point);
743}
744
746{
747 setAngleConical(angle);
749}
750
752{
753 if (startLinearXSpinBox)
754 startLinearXSpinBox->setValue(point.x());
755 if (startLinearYSpinBox)
756 startLinearYSpinBox->setValue(point.y());
757}
758
760{
761 if (endLinearXSpinBox)
762 endLinearXSpinBox->setValue(point.x());
763 if (endLinearYSpinBox)
764 endLinearYSpinBox->setValue(point.y());
765}
766
768{
769 if (centralRadialXSpinBox)
770 centralRadialXSpinBox->setValue(point.x());
771 if (centralRadialYSpinBox)
772 centralRadialYSpinBox->setValue(point.y());
773}
774
776{
777 if (focalRadialXSpinBox)
778 focalRadialXSpinBox->setValue(point.x());
779 if (focalRadialYSpinBox)
780 focalRadialYSpinBox->setValue(point.y());
781}
782
784{
785 if (radiusRadialSpinBox)
786 radiusRadialSpinBox->setValue(radius);
787}
788
790{
791 if (centralConicalXSpinBox)
792 centralConicalXSpinBox->setValue(point.x());
793 if (centralConicalYSpinBox)
794 centralConicalYSpinBox->setValue(point.y());
795}
796
798{
799 if (angleConicalSpinBox)
800 angleConicalSpinBox->setValue(angle);
801}
802
803QtGradientEditor::QtGradientEditor(QWidget *parent)
804 : QWidget(parent), d_ptr(new QtGradientEditorPrivate(this))
805{
806}
807
808QtGradientEditor::~QtGradientEditor()
809{
810 if (d_ptr->m_hiddenWidget)
811 delete d_ptr->m_hiddenWidget;
812}
813
814void QtGradientEditor::setGradient(const QGradient &grad)
815{
816 if (grad == gradient())
817 return;
818
819 QGradient::Type type = grad.type();
820 int idx = 0;
821 switch (type) {
822 case QGradient::LinearGradient: idx = 0; break;
823 case QGradient::RadialGradient: idx = 1; break;
824 case QGradient::ConicalGradient: idx = 2; break;
825 default: return;
826 }
827 d_ptr->setType(type);
828 d_ptr->m_ui.typeComboBox->setCurrentIndex(idx);
829 d_ptr->m_ui.gradientWidget->setGradientType(type);
830 d_ptr->m_typeGroup->button(idx)->setChecked(true);
831
832 QGradient::Spread spread = grad.spread();
833 switch (spread) {
834 case QGradient::PadSpread: idx = 0; break;
835 case QGradient::RepeatSpread: idx = 1; break;
836 case QGradient::ReflectSpread: idx = 2; break;
837 default: idx = 0; break;
838 }
839 d_ptr->m_ui.spreadComboBox->setCurrentIndex(idx);
840 d_ptr->m_ui.gradientWidget->setGradientSpread(spread);
841 d_ptr->m_spreadGroup->button(idx)->setChecked(true);
842
843 if (type == QGradient::LinearGradient) {
844 const QLinearGradient *gr = static_cast<const QLinearGradient *>(&grad);
845 d_ptr->setStartLinear(gr->start());
846 d_ptr->setEndLinear(gr->finalStop());
847 d_ptr->m_ui.gradientWidget->setStartLinear(gr->start());
848 d_ptr->m_ui.gradientWidget->setEndLinear(gr->finalStop());
849 } else if (type == QGradient::RadialGradient) {
850 const QRadialGradient *gr = static_cast<const QRadialGradient *>(&grad);
851 d_ptr->setCentralRadial(gr->center());
852 d_ptr->setFocalRadial(gr->focalPoint());
853 d_ptr->setRadiusRadial(gr->radius());
854 d_ptr->m_ui.gradientWidget->setCentralRadial(gr->center());
855 d_ptr->m_ui.gradientWidget->setFocalRadial(gr->focalPoint());
856 d_ptr->m_ui.gradientWidget->setRadiusRadial(gr->radius());
857 } else if (type == QGradient::ConicalGradient) {
858 const QConicalGradient *gr = static_cast<const QConicalGradient *>(&grad);
859 d_ptr->setCentralConical(gr->center());
860 d_ptr->setAngleConical(gr->angle());
861 d_ptr->m_ui.gradientWidget->setCentralConical(gr->center());
862 d_ptr->m_ui.gradientWidget->setAngleConical(gr->angle());
863 }
864
865 d_ptr->m_gradientStopsController->setGradientStops(grad.stops());
866 d_ptr->m_ui.gradientWidget->setGradientStops(grad.stops());
867 d_ptr->updateGradient(false);
868}
869
870QGradient QtGradientEditor::gradient() const
871{
872 return d_ptr->m_gradient;
873}
874
875bool QtGradientEditor::isBackgroundCheckered() const
876{
877 return d_ptr->m_backgroundCheckered;
878}
879
880void QtGradientEditor::setBackgroundCheckered(bool checkered)
881{
882 if (d_ptr->m_backgroundCheckered == checkered)
883 return;
884
885 d_ptr->setBackgroundCheckered(checkered);
886}
887
888bool QtGradientEditor::detailsVisible() const
889{
890 return d_ptr->m_details;
891}
892
893void QtGradientEditor::setDetailsVisible(bool visible)
894{
895 if (d_ptr->m_details == visible)
896 return;
897
898 d_ptr->showDetails(visible);
899}
900
901bool QtGradientEditor::isDetailsButtonVisible() const
902{
903 return d_ptr->m_detailsButtonVisible;
904}
905
906void QtGradientEditor::setDetailsButtonVisible(bool visible)
907{
908 if (d_ptr->m_detailsButtonVisible == visible)
909 return;
910
911 d_ptr->m_detailsButtonVisible = visible;
912 d_ptr->m_ui.detailsButton->setVisible(visible);
913}
914
915QColor::Spec QtGradientEditor::spec() const
916{
917 return d_ptr->m_gradientStopsController->spec();
918}
919
920void QtGradientEditor::setSpec(QColor::Spec spec)
921{
922 d_ptr->m_gradientStopsController->setSpec(spec);
923}
924
925QT_END_NAMESPACE
926
927#include "qtgradienteditor.moc"
void slotRadiusRadialChanged(double value)
void setCentralConical(QPointF point)
void slotCentralRadialYChanged(double value)
QDoubleSpinBox * startLinearXSpinBox
QDoubleSpinBox * centralRadialYSpinBox
QDoubleSpinBox * radiusRadialSpinBox
void slotStartLinearXChanged(double value)
QDoubleSpinBox * focalRadialXSpinBox
void angleConicalChanged(qreal angle)
void layoutDetails(bool details)
void slotCentralConicalXChanged(double value)
void setBackgroundCheckered(bool checkered)
void setupSpinBox(QDoubleSpinBox *spinBox, DoubleSlotPtr slot, double max=1.0, double step=0.01, int decimals=3)
void slotStartLinearYChanged(double value)
void(QtGradientEditorPrivate::*)(double) DoubleSlotPtr
void setRadiusRadial(qreal radius)
QDoubleSpinBox * startLinearYSpinBox
void endLinearChanged(QPointF point)
QDoubleSpinBox * endLinearYSpinBox
Ui::QtGradientEditor m_ui
void slotDetailsChanged(bool details)
void setCentralRadial(QPointF point)
QDoubleSpinBox * angleConicalSpinBox
void setAngleConical(qreal angle)
void slotFocalRadialXChanged(double value)
void setEndLinear(QPointF point)
void centralRadialChanged(QPointF point)
void showDetails(bool details)
void updateGradient(bool emitSignal)
void slotGradientStopsChanged(const QGradientStops &stops)
void slotCentralConicalYChanged(double value)
QDoubleSpinBox * centralConicalYSpinBox
void slotSpreadChanged(int spread)
void startLinearChanged(QPointF point)
void slotCentralRadialXChanged(double value)
void focalRadialChanged(QPointF point)
void setLayout(bool details)
void setType(QGradient::Type type)
void centralConicalChanged(const QPointF &point)
QDoubleSpinBox * centralConicalXSpinBox
void slotFocalRadialYChanged(double value)
void slotAngleConicalChanged(double value)
void setStartLinear(QPointF point)
QDoubleSpinBox * centralRadialXSpinBox
QDoubleSpinBox * focalRadialYSpinBox
QtGradientStopsController * m_gradientStopsController
QDoubleSpinBox * endLinearXSpinBox
void setFocalRadial(QPointF point)
void radiusRadialChanged(qreal radius)
void slotEndLinearXChanged(double value)
void slotEndLinearYChanged(double value)
void setUi(Ui::QtGradientEditor *editor)
Combined button and popup list for selecting options.