110 , m_gradientStopsController(
new QtGradientStopsController(
this))
111 , m_gradient(QLinearGradient())
114 m_gradientStopsController->setUi(&m_ui);
116 setType(QGradient::LinearGradient);
122 setStartLinear(QPointF(0, 0));
123 setEndLinear(QPointF(1, 1));
124 setCentralRadial(QPointF(0.5, 0.5));
125 setFocalRadial(QPointF(0.5, 0.5));
126 setRadiusRadial(0.5);
127 setCentralConical(QPointF(0.5, 0.5));
131 icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowRight), QIcon::Normal, QIcon::Off);
132 icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowLeft), QIcon::Normal, QIcon::On);
133 m_ui.detailsButton->setIcon(icon);
135 connect(m_ui.detailsButton, &QAbstractButton::clicked,
136 this, &QtGradientEditorPrivate::slotDetailsChanged);
137 connect(m_gradientStopsController, &QtGradientStopsController::gradientStopsChanged,
138 this, &QtGradientEditorPrivate::slotGradientStopsChanged);
140 QIcon iconLinear(
":/qt-project.org/qtgradienteditor/images/typelinear.png"_L1);
141 QIcon iconRadial(
":/qt-project.org/qtgradienteditor/images/typeradial.png"_L1);
142 QIcon iconConical(
":/qt-project.org/qtgradienteditor/images/typeconical.png"_L1);
144 m_ui.typeComboBox->addItem(iconLinear, QtGradientEditor::tr(
"Linear"));
145 m_ui.typeComboBox->addItem(iconRadial, QtGradientEditor::tr(
"Radial"));
146 m_ui.typeComboBox->addItem(iconConical, QtGradientEditor::tr(
"Conical"));
148 m_ui.linearButton->setIcon(iconLinear);
149 m_ui.radialButton->setIcon(iconRadial);
150 m_ui.conicalButton->setIcon(iconConical);
152 m_typeGroup =
new QButtonGroup(
this);
153 m_typeGroup->addButton(m_ui.linearButton, 0);
154 m_typeGroup->addButton(m_ui.radialButton, 1);
155 m_typeGroup->addButton(m_ui.conicalButton, 2);
157 connect(m_typeGroup, &QButtonGroup::idClicked,
158 this, &QtGradientEditorPrivate::slotTypeChanged);
159 connect(m_ui.typeComboBox, &QComboBox::activated,
160 this, &QtGradientEditorPrivate::slotTypeChanged);
162 QIcon iconPad(
":/qt-project.org/qtgradienteditor/images/spreadpad.png"_L1);
163 QIcon iconRepeat(
":/qt-project.org/qtgradienteditor/images/spreadrepeat.png"_L1);
164 QIcon iconReflect(
":/qt-project.org/qtgradienteditor/images/spreadreflect.png"_L1);
166 m_ui.spreadComboBox->addItem(iconPad, QtGradientEditor::tr(
"Pad"));
167 m_ui.spreadComboBox->addItem(iconRepeat, QtGradientEditor::tr(
"Repeat"));
168 m_ui.spreadComboBox->addItem(iconReflect, QtGradientEditor::tr(
"Reflect"));
170 m_ui.padButton->setIcon(iconPad);
171 m_ui.repeatButton->setIcon(iconRepeat);
172 m_ui.reflectButton->setIcon(iconReflect);
174 m_spreadGroup =
new QButtonGroup(
this);
175 m_spreadGroup->addButton(m_ui.padButton, 0);
176 m_spreadGroup->addButton(m_ui.repeatButton, 1);
177 m_spreadGroup->addButton(m_ui.reflectButton, 2);
178 connect(m_spreadGroup, &QButtonGroup::idClicked,
179 this, &QtGradientEditorPrivate::slotSpreadChanged);
180 connect(m_ui.spreadComboBox, &QComboBox::activated,
181 this, &QtGradientEditorPrivate::slotSpreadChanged);
183 connect(m_ui.gradientWidget, &QtGradientWidget::startLinearChanged,
184 this, &QtGradientEditorPrivate::startLinearChanged);
185 connect(m_ui.gradientWidget, &QtGradientWidget::endLinearChanged,
186 this, &QtGradientEditorPrivate::endLinearChanged);
187 connect(m_ui.gradientWidget, &QtGradientWidget::centralRadialChanged,
188 this, &QtGradientEditorPrivate::centralRadialChanged);
189 connect(m_ui.gradientWidget, &QtGradientWidget::focalRadialChanged,
190 this, &QtGradientEditorPrivate::focalRadialChanged);
191 connect(m_ui.gradientWidget, &QtGradientWidget::radiusRadialChanged,
192 this, &QtGradientEditorPrivate::radiusRadialChanged);
193 connect(m_ui.gradientWidget, &QtGradientWidget::centralConicalChanged,
194 this, &QtGradientEditorPrivate::centralConicalChanged);
195 connect(m_ui.gradientWidget, &QtGradientWidget::angleConicalChanged,
196 this, &QtGradientEditorPrivate::angleConicalChanged);
198 QGradientStops stops = gradient().stops();
200 m_ui.gradientWidget->setGradientStops(stops);
205 QGradient *gradient =
nullptr;
206 switch (m_ui.gradientWidget->gradientType()) {
207 case QGradient::LinearGradient:
208 gradient =
new QLinearGradient(m_ui.gradientWidget->startLinear(),
209 m_ui.gradientWidget->endLinear());
211 case QGradient::RadialGradient:
212 gradient =
new QRadialGradient(m_ui.gradientWidget->centralRadial(),
213 m_ui.gradientWidget->radiusRadial(),
214 m_ui.gradientWidget->focalRadial());
216 case QGradient::ConicalGradient:
217 gradient =
new QConicalGradient(m_ui.gradientWidget->centralConical(),
218 m_ui.gradientWidget->angleConical());
225 gradient->setStops(m_ui.gradientWidget->gradientStops());
226 gradient->setSpread(m_ui.gradientWidget->gradientSpread());
227 gradient->setCoordinateMode(QGradient::StretchToDeviceMode);
228 QGradient gr = *gradient;
262 QHBoxLayout *hboxLayout =
new QHBoxLayout();
263 hboxLayout->setObjectName(QString::fromUtf8(
"hboxLayout"));
264 hboxLayout->addWidget(m_ui.typeComboBox);
265 hboxLayout->addWidget(m_ui.spreadComboBox);
266 QHBoxLayout *typeLayout =
new QHBoxLayout();
267 typeLayout->setSpacing(0);
268 typeLayout->addWidget(m_ui.linearButton);
269 typeLayout->addWidget(m_ui.radialButton);
270 typeLayout->addWidget(m_ui.conicalButton);
271 hboxLayout->addLayout(typeLayout);
272 QHBoxLayout *spreadLayout =
new QHBoxLayout();
273 spreadLayout->setSpacing(0);
274 spreadLayout->addWidget(m_ui.padButton);
275 spreadLayout->addWidget(m_ui.repeatButton);
276 spreadLayout->addWidget(m_ui.reflectButton);
277 hboxLayout->addLayout(spreadLayout);
278 hboxLayout->addItem(
new QSpacerItem(0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum));
279 hboxLayout->addWidget(m_ui.detailsButton);
280 m_gridLayout->addLayout(hboxLayout, 0, 0, 1, 2);
284 m_gridLayout->addWidget(m_ui.frame, 1, 0, span, 2);
290 m_gridLayout->addWidget(m_ui.gradientStopsWidget, row, 0, span, 2);
291 QHBoxLayout *hboxLayout1 =
new QHBoxLayout();
292 hboxLayout1->setObjectName(QString::fromUtf8(
"hboxLayout1"));
293 hboxLayout1->addWidget(m_ui.colorLabel);
294 hboxLayout1->addWidget(m_ui.colorButton);
295 hboxLayout1->addWidget(m_ui.hsvRadioButton);
296 hboxLayout1->addWidget(m_ui.rgbRadioButton);
297 hboxLayout1->addItem(
new QSpacerItem(16, 23, QSizePolicy::Expanding, QSizePolicy::Minimum));
301 m_gridLayout->addLayout(hboxLayout1, 3 + addRow, 0, 1, 2);
302 m_gridLayout->addWidget(m_ui.hLabel, 4 + addRow, 0, 1, 1);
303 m_gridLayout->addWidget(m_ui.frame_2, 4 + addRow, 1, 1, 1);
304 m_gridLayout->addWidget(m_ui.sLabel, 5 + addRow, 0, 1, 1);
305 m_gridLayout->addWidget(m_ui.frame_5, 5 + addRow, 1, 1, 1);
306 m_gridLayout->addWidget(m_ui.vLabel, 6 + addRow, 0, 1, 1);
307 m_gridLayout->addWidget(m_ui.frame_3, 6 + addRow, 1, 1, 1);
308 m_gridLayout->addWidget(m_ui.aLabel, 7 + addRow, 0, 1, 1);
309 m_gridLayout->addWidget(m_ui.frame_4, 7 + addRow, 1, 1, 1);
318 QGridLayout *gridLayout = m_gridLayout;
322 if (!m_hiddenWidget) {
323 m_hiddenWidget =
new QWidget();
324 m_hiddenLayout =
new QGridLayout(m_hiddenWidget);
325 m_hiddenLayout->setContentsMargins(0, 0, 0, 0);
326 m_hiddenLayout->setSizeConstraint(QLayout::SetFixedSize);
328 gridLayout = m_hiddenLayout;
330 gridLayout->addWidget(m_ui.label1, 1, col + 0, 1, 1);
331 gridLayout->addWidget(m_ui.spinBox1, 1, col + 1, 1, 1);
332 gridLayout->addWidget(m_ui.label2, 2, col + 0, 1, 1);
333 gridLayout->addWidget(m_ui.spinBox2, 2, col + 1, 1, 1);
334 gridLayout->addWidget(m_ui.label3, 3, col + 0, 1, 1);
335 gridLayout->addWidget(m_ui.spinBox3, 3, col + 1, 1, 1);
336 gridLayout->addWidget(m_ui.label4, 4, col + 0, 1, 1);
337 gridLayout->addWidget(m_ui.spinBox4, 4, col + 1, 1, 1);
338 gridLayout->addWidget(m_ui.label5, 5, col + 0, 1, 1);
339 gridLayout->addWidget(m_ui.spinBox5, 5, col + 1, 1, 1);
340 gridLayout->addItem(
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Expanding), 6, col + 0, 1, 1);
341 gridLayout->addWidget(m_ui.line1Widget, 7, col + 0, 1, 2);
342 gridLayout->addWidget(m_ui.zoomLabel, 8, col + 0, 1, 1);
343 gridLayout->addWidget(m_ui.zoomWidget, 8, col + 1, 1, 1);
344 gridLayout->addWidget(m_ui.zoomButtonsWidget, 9, col + 0, 1, 1);
345 gridLayout->addWidget(m_ui.zoomAllButton, 9, col + 1, 1, 1);
346 gridLayout->addItem(
new QSpacerItem(0, 0, QSizePolicy::Minimum, QSizePolicy::Preferred), 10, col + 0, 1, 1);
347 gridLayout->addWidget(m_ui.line2Widget, 11, col + 0, 1, 2);
348 gridLayout->addWidget(m_ui.positionLabel, 12, col + 0, 1, 1);
349 gridLayout->addWidget(m_ui.positionWidget, 12, col + 1, 1, 1);
350 gridLayout->addWidget(m_ui.hueLabel, 13, col + 0, 1, 1);
351 gridLayout->addWidget(m_ui.hueWidget, 13, col + 1, 1, 1);
352 gridLayout->addWidget(m_ui.saturationLabel, 14, col + 0, 1, 1);
353 gridLayout->addWidget(m_ui.saturationWidget, 14, col + 1, 1, 1);
354 gridLayout->addWidget(m_ui.valueLabel, 15, col + 0, 1, 1);
355 gridLayout->addWidget(m_ui.valueWidget, 15, col + 1, 1, 1);
356 gridLayout->addWidget(m_ui.alphaLabel, 16, col + 0, 1, 1);
357 gridLayout->addWidget(m_ui.alphaWidget, 16, col + 1, 1, 1);
360 if (m_hiddenLayout) {
361 delete m_hiddenLayout;
364 if (m_hiddenWidget) {
365 delete m_hiddenWidget;
405 bool blocked = m_ui.detailsButton->signalsBlocked();
406 m_ui.detailsButton->blockSignals(
true);
407 m_ui.detailsButton->setChecked(details);
408 m_ui.detailsButton->blockSignals(blocked);
410 bool updates = q_ptr->updatesEnabled();
411 q_ptr->setUpdatesEnabled(
false);
414 m_gridLayout->setEnabled(
false);
423 emit q_ptr->aboutToShowDetails(details, extensionWidthHint());
426 m_gridLayout =
new QGridLayout(q_ptr);
427 m_gridLayout->setEnabled(
false);
428 m_gridLayout->setObjectName(QString::fromUtf8(
"gridLayout"));
429 m_gridLayout->setContentsMargins(0, 0, 0, 0);
431 m_ui.label4->setVisible(row4Visible());
432 m_ui.label5->setVisible(row5Visible());
433 m_ui.spinBox4->setVisible(row4Visible());
434 m_ui.spinBox5->setVisible(row5Visible());
437 m_gridLayout->setEnabled(
true);
439 q_ptr->setUpdatesEnabled(updates);
477 m_ui.spinBox1->disconnect(
this);
478 m_ui.spinBox2->disconnect(
this);
479 m_ui.spinBox3->disconnect(
this);
480 m_ui.spinBox4->disconnect(
this);
481 m_ui.spinBox5->disconnect(
this);
488 ena = m_gridLayout->isEnabled();
489 m_gridLayout->setEnabled(
false);
492 bool spreadEnabled =
true;
494 if (type == QGradient::LinearGradient) {
495 startLinearXSpinBox = m_ui.spinBox1;
496 setupSpinBox(startLinearXSpinBox, &QtGradientEditorPrivate::slotStartLinearXChanged);
497 m_ui.label1->setText(QCoreApplication::translate(
"QtGradientEditor",
"Start X"));
499 startLinearYSpinBox = m_ui.spinBox2;
500 setupSpinBox(startLinearYSpinBox, &QtGradientEditorPrivate::slotStartLinearYChanged);
501 m_ui.label2->setText(QCoreApplication::translate(
"QtGradientEditor",
"Start Y"));
503 endLinearXSpinBox = m_ui.spinBox3;
504 setupSpinBox(endLinearXSpinBox, &QtGradientEditorPrivate::slotEndLinearXChanged);
505 m_ui.label3->setText(QCoreApplication::translate(
"QtGradientEditor",
"Final X"));
507 endLinearYSpinBox = m_ui.spinBox4;
508 setupSpinBox(endLinearYSpinBox, &QtGradientEditorPrivate::slotEndLinearYChanged);
509 m_ui.label4->setText(QCoreApplication::translate(
"QtGradientEditor",
"Final Y"));
511 setStartLinear(m_ui.gradientWidget->startLinear());
512 setEndLinear(m_ui.gradientWidget->endLinear());
513 }
else if (type == QGradient::RadialGradient) {
514 centralRadialXSpinBox = m_ui.spinBox1;
515 setupSpinBox(centralRadialXSpinBox, &QtGradientEditorPrivate::slotCentralRadialXChanged);
516 m_ui.label1->setText(QCoreApplication::translate(
"QtGradientEditor",
"Central X"));
518 centralRadialYSpinBox = m_ui.spinBox2;
519 setupSpinBox(centralRadialYSpinBox, &QtGradientEditorPrivate::slotCentralRadialYChanged);
520 m_ui.label2->setText(QCoreApplication::translate(
"QtGradientEditor",
"Central Y"));
522 focalRadialXSpinBox = m_ui.spinBox3;
523 setupSpinBox(focalRadialXSpinBox, &QtGradientEditorPrivate::slotFocalRadialXChanged);
524 m_ui.label3->setText(QCoreApplication::translate(
"QtGradientEditor",
"Focal X"));
526 focalRadialYSpinBox = m_ui.spinBox4;
527 setupSpinBox(focalRadialYSpinBox, &QtGradientEditorPrivate::slotFocalRadialYChanged);
528 m_ui.label4->setText(QCoreApplication::translate(
"QtGradientEditor",
"Focal Y"));
530 radiusRadialSpinBox = m_ui.spinBox5;
531 setupSpinBox(radiusRadialSpinBox, &QtGradientEditorPrivate::slotRadiusRadialChanged, 2.0);
532 m_ui.label5->setText(QCoreApplication::translate(
"QtGradientEditor",
"Radius"));
534 setCentralRadial(m_ui.gradientWidget->centralRadial());
535 setFocalRadial(m_ui.gradientWidget->focalRadial());
536 setRadiusRadial(m_ui.gradientWidget->radiusRadial());
537 }
else if (type == QGradient::ConicalGradient) {
538 centralConicalXSpinBox = m_ui.spinBox1;
539 setupSpinBox(centralConicalXSpinBox, &QtGradientEditorPrivate::slotCentralConicalXChanged);
540 m_ui.label1->setText(QCoreApplication::translate(
"QtGradientEditor",
"Central X"));
542 centralConicalYSpinBox = m_ui.spinBox2;
543 setupSpinBox(centralConicalYSpinBox, &QtGradientEditorPrivate::slotCentralConicalYChanged);
544 m_ui.label2->setText(QCoreApplication::translate(
"QtGradientEditor",
"Central Y"));
546 angleConicalSpinBox = m_ui.spinBox3;
547 setupSpinBox(angleConicalSpinBox, &QtGradientEditorPrivate::slotAngleConicalChanged, 360.0, 1.0, 1);
548 m_ui.label3->setText(QCoreApplication::translate(
"QtGradientEditor",
"Angle"));
550 setCentralConical(m_ui.gradientWidget->centralConical());
551 setAngleConical(m_ui.gradientWidget->angleConical());
553 spreadEnabled =
false;
555 m_ui.spreadComboBox->setEnabled(spreadEnabled);
556 m_ui.padButton->setEnabled(spreadEnabled);
557 m_ui.repeatButton->setEnabled(spreadEnabled);
558 m_ui.reflectButton->setEnabled(spreadEnabled);
560 m_ui.label4->setVisible(row4Visible());
561 m_ui.spinBox4->setVisible(row4Visible());
562 m_ui.label5->setVisible(row5Visible());
563 m_ui.spinBox5->setVisible(row5Visible());
566 m_gridLayout->setEnabled(ena);
813void QtGradientEditor::setGradient(
const QGradient &grad)
815 if (grad == gradient())
818 QGradient::Type type = grad.type();
821 case QGradient::LinearGradient: idx = 0;
break;
822 case QGradient::RadialGradient: idx = 1;
break;
823 case QGradient::ConicalGradient: idx = 2;
break;
826 d_ptr->setType(type);
827 d_ptr->m_ui.typeComboBox->setCurrentIndex(idx);
828 d_ptr->m_ui.gradientWidget->setGradientType(type);
829 d_ptr->m_typeGroup->button(idx)->setChecked(
true);
831 QGradient::Spread spread = grad.spread();
833 case QGradient::PadSpread: idx = 0;
break;
834 case QGradient::RepeatSpread: idx = 1;
break;
835 case QGradient::ReflectSpread: idx = 2;
break;
836 default: idx = 0;
break;
838 d_ptr->m_ui.spreadComboBox->setCurrentIndex(idx);
839 d_ptr->m_ui.gradientWidget->setGradientSpread(spread);
840 d_ptr->m_spreadGroup->button(idx)->setChecked(
true);
842 if (type == QGradient::LinearGradient) {
843 const QLinearGradient *gr =
static_cast<
const QLinearGradient *>(&grad);
844 d_ptr->setStartLinear(gr->start());
845 d_ptr->setEndLinear(gr->finalStop());
846 d_ptr->m_ui.gradientWidget->setStartLinear(gr->start());
847 d_ptr->m_ui.gradientWidget->setEndLinear(gr->finalStop());
848 }
else if (type == QGradient::RadialGradient) {
849 const QRadialGradient *gr =
static_cast<
const QRadialGradient *>(&grad);
850 d_ptr->setCentralRadial(gr->center());
851 d_ptr->setFocalRadial(gr->focalPoint());
852 d_ptr->setRadiusRadial(gr->radius());
853 d_ptr->m_ui.gradientWidget->setCentralRadial(gr->center());
854 d_ptr->m_ui.gradientWidget->setFocalRadial(gr->focalPoint());
855 d_ptr->m_ui.gradientWidget->setRadiusRadial(gr->radius());
856 }
else if (type == QGradient::ConicalGradient) {
857 const QConicalGradient *gr =
static_cast<
const QConicalGradient *>(&grad);
858 d_ptr->setCentralConical(gr->center());
859 d_ptr->setAngleConical(gr->angle());
860 d_ptr->m_ui.gradientWidget->setCentralConical(gr->center());
861 d_ptr->m_ui.gradientWidget->setAngleConical(gr->angle());
864 d_ptr->m_gradientStopsController->setGradientStops(grad.stops());
865 d_ptr->m_ui.gradientWidget->setGradientStops(grad.stops());
866 d_ptr->updateGradient(
false);