From 27de6e52e5104d97a214bfa2ea8982f23d182fe4 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Thu, 4 Nov 2021 16:34:18 +0100 Subject: Gradient editor: replace string-based connections with typed connections This fixes some already broken connection due to removal of some signals in Qt 6. Change-Id: I7dbe44c3d9307539530cd74c1f1658e2a58954c7 Reviewed-by: Friedemann Kleint (cherry picked from commit 6ab73adf460794c6b218da4bfd67e342fe83df8b) Reviewed-by: Qt Cherry-pick Bot --- src/shared/qtgradienteditor/qtcolorbutton.cpp | 7 +- src/shared/qtgradienteditor/qtcolorbutton.h | 4 +- src/shared/qtgradienteditor/qtcolorline.h | 4 - src/shared/qtgradienteditor/qtgradientdialog.cpp | 10 +- src/shared/qtgradienteditor/qtgradientdialog.h | 1 - src/shared/qtgradienteditor/qtgradienteditor.cpp | 332 +++++++++++---------- src/shared/qtgradienteditor/qtgradienteditor.h | 24 -- .../qtgradienteditor/qtgradientstopscontroller.cpp | 184 ++++++------ .../qtgradienteditor/qtgradientstopscontroller.h | 27 -- .../qtgradienteditor/qtgradientstopswidget.cpp | 126 ++++---- .../qtgradienteditor/qtgradientstopswidget.h | 15 - src/shared/qtgradienteditor/qtgradientutils.h | 1 - src/shared/qtgradienteditor/qtgradientview.cpp | 48 +-- src/shared/qtgradienteditor/qtgradientview.h | 2 +- .../qtgradienteditor/qtgradientviewdialog.cpp | 8 +- src/shared/qtgradienteditor/qtgradientwidget.h | 1 + 16 files changed, 373 insertions(+), 421 deletions(-) diff --git a/src/shared/qtgradienteditor/qtcolorbutton.cpp b/src/shared/qtgradienteditor/qtcolorbutton.cpp index 33b084781..0b758fab7 100644 --- a/src/shared/qtgradienteditor/qtcolorbutton.cpp +++ b/src/shared/qtgradienteditor/qtcolorbutton.cpp @@ -47,8 +47,9 @@ QT_BEGIN_NAMESPACE -class QtColorButtonPrivate +class QtColorButtonPrivate : public QObject { + Q_OBJECT QtColorButton *q_ptr; Q_DECLARE_PUBLIC(QtColorButton) public: @@ -124,7 +125,7 @@ QtColorButton::QtColorButton(QWidget *parent) setAcceptDrops(true); - connect(this, SIGNAL(clicked()), this, SLOT(slotEditColor())); + connect(this, &QToolButton::clicked, d_ptr.data(), &QtColorButtonPrivate::slotEditColor); setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred)); } @@ -268,4 +269,4 @@ void QtColorButton::dropEvent(QDropEvent *event) QT_END_NAMESPACE -#include "moc_qtcolorbutton.cpp" +#include "qtcolorbutton.moc" diff --git a/src/shared/qtgradienteditor/qtcolorbutton.h b/src/shared/qtgradienteditor/qtcolorbutton.h index 892b7d465..ae7095bef 100644 --- a/src/shared/qtgradienteditor/qtcolorbutton.h +++ b/src/shared/qtgradienteditor/qtcolorbutton.h @@ -58,11 +58,11 @@ public: QColor color() const; public slots: - void setColor(const QColor &color); signals: void colorChanged(const QColor &color); + protected: void paintEvent(QPaintEvent *event) override; void mousePressEvent(QMouseEvent *event) override; @@ -72,11 +72,11 @@ protected: void dragLeaveEvent(QDragLeaveEvent *event) override; void dropEvent(QDropEvent *event) override; #endif + private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorButton) Q_DISABLE_COPY_MOVE(QtColorButton) - Q_PRIVATE_SLOT(d_func(), void slotEditColor()) }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtcolorline.h b/src/shared/qtgradienteditor/qtcolorline.h index a9d0d191c..0cf1f240d 100644 --- a/src/shared/qtgradienteditor/qtcolorline.h +++ b/src/shared/qtgradienteditor/qtcolorline.h @@ -94,15 +94,12 @@ public: ColorComponent colorComponent() const; public slots: - void setColor(const QColor &color); signals: - void colorChanged(const QColor &color); protected: - void resizeEvent(QResizeEvent *event) override; void paintEvent(QPaintEvent *event) override; void mousePressEvent(QMouseEvent *event) override; @@ -111,7 +108,6 @@ protected: void mouseDoubleClickEvent(QMouseEvent *event) override; private: - QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtColorLine) Q_DISABLE_COPY_MOVE(QtColorLine) diff --git a/src/shared/qtgradienteditor/qtgradientdialog.cpp b/src/shared/qtgradienteditor/qtgradientdialog.cpp index c47a374b4..020295721 100644 --- a/src/shared/qtgradienteditor/qtgradientdialog.cpp +++ b/src/shared/qtgradienteditor/qtgradientdialog.cpp @@ -43,12 +43,12 @@ QT_BEGIN_NAMESPACE -class QtGradientDialogPrivate +class QtGradientDialogPrivate : public QObject { + Q_OBJECT QtGradientDialog *q_ptr; Q_DECLARE_PUBLIC(QtGradientDialog) public: - void slotAboutToShowDetails(bool details, int extensionWidthHint); Ui::QtGradientDialog m_ui; @@ -205,8 +205,8 @@ QtGradientDialog::QtGradientDialog(QWidget *parent) button = d_ptr->m_ui.buttonBox->button(QDialogButtonBox::Cancel); if (button) button->setAutoDefault(false); - connect(d_ptr->m_ui.gradientEditor, SIGNAL(aboutToShowDetails(bool,int)), - this, SLOT(slotAboutToShowDetails(bool,int))); + connect(d_ptr->m_ui.gradientEditor, &QtGradientEditor::aboutToShowDetails, + d_ptr.data(), &QtGradientDialogPrivate::slotAboutToShowDetails); } /*! @@ -348,4 +348,4 @@ QGradient QtGradientDialog::getGradient(bool *ok, QWidget *parent, const QString QT_END_NAMESPACE -#include "moc_qtgradientdialog.cpp" +#include "qtgradientdialog.moc" diff --git a/src/shared/qtgradienteditor/qtgradientdialog.h b/src/shared/qtgradienteditor/qtgradientdialog.h index 852c3a143..fdcfe9044 100644 --- a/src/shared/qtgradienteditor/qtgradientdialog.h +++ b/src/shared/qtgradienteditor/qtgradientdialog.h @@ -77,7 +77,6 @@ private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientDialog) Q_DISABLE_COPY_MOVE(QtGradientDialog) - Q_PRIVATE_SLOT(d_func(), void slotAboutToShowDetails(bool details, int extensionWidthHint)) }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtgradienteditor.cpp b/src/shared/qtgradienteditor/qtgradienteditor.cpp index 57d35b83a..24c432abe 100644 --- a/src/shared/qtgradienteditor/qtgradienteditor.cpp +++ b/src/shared/qtgradienteditor/qtgradienteditor.cpp @@ -45,12 +45,15 @@ QT_BEGIN_NAMESPACE -class QtGradientEditorPrivate +class QtGradientEditorPrivate : public QObject { + Q_OBJECT QtGradientEditor *q_ptr; Q_DECLARE_PUBLIC(QtGradientEditor) public: - QtGradientEditorPrivate() : m_gradient(QLinearGradient()) {} + QtGradientEditorPrivate(QtGradientEditor *q); + + void setBackgroundCheckered(bool checkered); void slotGradientStopsChanged(const QGradientStops &stops); void slotTypeChanged(int type); @@ -89,7 +92,8 @@ public: void setType(QGradient::Type type); void showDetails(bool details); - void setSpinBox(QDoubleSpinBox *spinBox, const char *slot, double max = 1.0, double step = 0.01, int decimals = 3); + using DoubleSlotPtr = void (QtGradientEditorPrivate::*)(double); + void setupSpinBox(QDoubleSpinBox *spinBox, DoubleSlotPtr slot, double max = 1.0, double step = 0.01, int decimals = 3); void reset(); void setLayout(bool details); void layoutDetails(bool details); @@ -105,36 +109,131 @@ public: Ui::QtGradientEditor m_ui; QtGradientStopsController *m_gradientStopsController; - QDoubleSpinBox *startLinearXSpinBox; - QDoubleSpinBox *startLinearYSpinBox; - QDoubleSpinBox *endLinearXSpinBox; - QDoubleSpinBox *endLinearYSpinBox; - QDoubleSpinBox *centralRadialXSpinBox; - QDoubleSpinBox *centralRadialYSpinBox; - QDoubleSpinBox *focalRadialXSpinBox; - QDoubleSpinBox *focalRadialYSpinBox; - QDoubleSpinBox *radiusRadialSpinBox; - QDoubleSpinBox *centralConicalXSpinBox; - QDoubleSpinBox *centralConicalYSpinBox; - QDoubleSpinBox *angleConicalSpinBox; - - QButtonGroup *m_typeGroup; - QButtonGroup *m_spreadGroup; - - QGradient::Type m_type; - - QGridLayout *m_gridLayout; - QWidget *m_hiddenWidget; - QGridLayout *m_hiddenLayout; - bool m_details; - bool m_detailsButtonVisible; - bool m_backgroundCheckered; + QDoubleSpinBox *startLinearXSpinBox = nullptr; + QDoubleSpinBox *startLinearYSpinBox = nullptr; + QDoubleSpinBox *endLinearXSpinBox = nullptr; + QDoubleSpinBox *endLinearYSpinBox = nullptr; + QDoubleSpinBox *centralRadialXSpinBox = nullptr; + QDoubleSpinBox *centralRadialYSpinBox = nullptr; + QDoubleSpinBox *focalRadialXSpinBox = nullptr; + QDoubleSpinBox *focalRadialYSpinBox = nullptr; + QDoubleSpinBox *radiusRadialSpinBox = nullptr; + QDoubleSpinBox *centralConicalXSpinBox = nullptr; + QDoubleSpinBox *centralConicalYSpinBox = nullptr; + QDoubleSpinBox *angleConicalSpinBox = nullptr; + + QButtonGroup *m_typeGroup = nullptr; + QButtonGroup *m_spreadGroup = nullptr; + + QGradient::Type m_type = QGradient::RadialGradient; + + QGridLayout *m_gridLayout = nullptr; + QWidget *m_hiddenWidget = nullptr; + QGridLayout *m_hiddenLayout = nullptr; + bool m_details = false; + bool m_detailsButtonVisible = true; + bool m_backgroundCheckered = true; QGradient m_gradient; - bool m_combos; + bool m_combos = true; }; +QtGradientEditorPrivate::QtGradientEditorPrivate(QtGradientEditor *q) + : q_ptr(q) + , m_gradientStopsController(new QtGradientStopsController(this)) + , m_gradient(QLinearGradient()) +{ + m_ui.setupUi(q_ptr); + m_gradientStopsController->setUi(&m_ui); + reset(); + setType(QGradient::LinearGradient); + setCombos(!m_combos); + + showDetails(m_details); + setBackgroundCheckered(m_backgroundCheckered); + + setStartLinear(QPointF(0, 0)); + setEndLinear(QPointF(1, 1)); + setCentralRadial(QPointF(0.5, 0.5)); + setFocalRadial(QPointF(0.5, 0.5)); + setRadiusRadial(0.5); + setCentralConical(QPointF(0.5, 0.5)); + setAngleConical(0); + + QIcon icon; + icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowRight), QIcon::Normal, QIcon::Off); + icon.addPixmap(q_ptr->style()->standardPixmap(QStyle::SP_ArrowLeft), QIcon::Normal, QIcon::On); + m_ui.detailsButton->setIcon(icon); + + connect(m_ui.detailsButton, &QAbstractButton::clicked, + this, &QtGradientEditorPrivate::slotDetailsChanged); + connect(m_gradientStopsController, &QtGradientStopsController::gradientStopsChanged, + this, &QtGradientEditorPrivate::slotGradientStopsChanged); + + QIcon iconLinear(QLatin1String(":/qt-project.org/qtgradienteditor/images/typelinear.png")); + QIcon iconRadial(QLatin1String(":/qt-project.org/qtgradienteditor/images/typeradial.png")); + QIcon iconConical(QLatin1String(":/qt-project.org/qtgradienteditor/images/typeconical.png")); + + m_ui.typeComboBox->addItem(iconLinear, QtGradientEditor::tr("Linear")); + m_ui.typeComboBox->addItem(iconRadial, QtGradientEditor::tr("Radial")); + m_ui.typeComboBox->addItem(iconConical, QtGradientEditor::tr("Conical")); + + m_ui.linearButton->setIcon(iconLinear); + m_ui.radialButton->setIcon(iconRadial); + m_ui.conicalButton->setIcon(iconConical); + + m_typeGroup = new QButtonGroup(this); + m_typeGroup->addButton(m_ui.linearButton, 0); + m_typeGroup->addButton(m_ui.radialButton, 1); + m_typeGroup->addButton(m_ui.conicalButton, 2); + + connect(m_typeGroup, &QButtonGroup::idClicked, + this, &QtGradientEditorPrivate::slotTypeChanged); + connect(m_ui.typeComboBox, &QComboBox::activated, + this, &QtGradientEditorPrivate::slotTypeChanged); + + QIcon iconPad(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadpad.png")); + QIcon iconRepeat(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadrepeat.png")); + QIcon iconReflect(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadreflect.png")); + + m_ui.spreadComboBox->addItem(iconPad, QtGradientEditor::tr("Pad")); + m_ui.spreadComboBox->addItem(iconRepeat, QtGradientEditor::tr("Repeat")); + m_ui.spreadComboBox->addItem(iconReflect, QtGradientEditor::tr("Reflect")); + + m_ui.padButton->setIcon(iconPad); + m_ui.repeatButton->setIcon(iconRepeat); + m_ui.reflectButton->setIcon(iconReflect); + + m_spreadGroup = new QButtonGroup(this); + m_spreadGroup->addButton(m_ui.padButton, 0); + m_spreadGroup->addButton(m_ui.repeatButton, 1); + m_spreadGroup->addButton(m_ui.reflectButton, 2); + connect(m_spreadGroup, &QButtonGroup::idClicked, + this, &QtGradientEditorPrivate::slotSpreadChanged); + connect(m_ui.spreadComboBox, &QComboBox::activated, + this, &QtGradientEditorPrivate::slotSpreadChanged); + + connect(m_ui.gradientWidget, &QtGradientWidget::startLinearChanged, + this, &QtGradientEditorPrivate::startLinearChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::endLinearChanged, + this, &QtGradientEditorPrivate::endLinearChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::centralRadialChanged, + this, &QtGradientEditorPrivate::centralRadialChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::focalRadialChanged, + this, &QtGradientEditorPrivate::focalRadialChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::radiusRadialChanged, + this, &QtGradientEditorPrivate::radiusRadialChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::centralConicalChanged, + this, &QtGradientEditorPrivate::centralConicalChanged); + connect(m_ui.gradientWidget, &QtGradientWidget::angleConicalChanged, + this, &QtGradientEditorPrivate::angleConicalChanged); + + QGradientStops stops = gradient().stops(); + m_gradientStopsController->setGradientStops(stops); + m_ui.gradientWidget->setGradientStops(stops); +} + QGradient QtGradientEditorPrivate::gradient() const { QGradient *gradient = 0; @@ -315,6 +414,9 @@ int QtGradientEditorPrivate::extensionWidthHint() const void QtGradientEditorPrivate::slotDetailsChanged(bool details) { + if (m_details == details) + return; + showDetails(details); } @@ -334,9 +436,6 @@ bool QtGradientEditorPrivate::row5Visible() const void QtGradientEditorPrivate::showDetails(bool details) { - if (m_details == details) - return; - bool blocked = m_ui.detailsButton->signalsBlocked(); m_ui.detailsButton->blockSignals(true); m_ui.detailsButton->setChecked(details); @@ -375,7 +474,8 @@ void QtGradientEditorPrivate::showDetails(bool details) q_ptr->update(); } -void QtGradientEditorPrivate::setSpinBox(QDoubleSpinBox *spinBox, const char *slot, double max, double step, int decimals) +void QtGradientEditorPrivate::setupSpinBox(QDoubleSpinBox *spinBox, DoubleSlotPtr slot, + double max, double step, int decimals) { bool blocked = spinBox->signalsBlocked(); spinBox->blockSignals(true); @@ -383,7 +483,7 @@ void QtGradientEditorPrivate::setSpinBox(QDoubleSpinBox *spinBox, const char *sl spinBox->setMaximum(max); spinBox->setSingleStep(step); spinBox->blockSignals(blocked); - QObject::connect(spinBox, SIGNAL(valueChanged(double)), q_ptr, slot); + QObject::connect(spinBox, &QDoubleSpinBox::valueChanged, this, slot); } void QtGradientEditorPrivate::reset() @@ -408,11 +508,11 @@ void QtGradientEditorPrivate::setType(QGradient::Type type) return; m_type = type; - m_ui.spinBox1->disconnect(SIGNAL(valueChanged(double))); - m_ui.spinBox2->disconnect(SIGNAL(valueChanged(double))); - m_ui.spinBox3->disconnect(SIGNAL(valueChanged(double))); - m_ui.spinBox4->disconnect(SIGNAL(valueChanged(double))); - m_ui.spinBox5->disconnect(SIGNAL(valueChanged(double))); + m_ui.spinBox1->disconnect(this); + m_ui.spinBox2->disconnect(this); + m_ui.spinBox3->disconnect(this); + m_ui.spinBox4->disconnect(this); + m_ui.spinBox5->disconnect(this); reset(); @@ -427,42 +527,42 @@ void QtGradientEditorPrivate::setType(QGradient::Type type) if (type == QGradient::LinearGradient) { startLinearXSpinBox = m_ui.spinBox1; - setSpinBox(startLinearXSpinBox, SLOT(slotStartLinearXChanged(double))); + setupSpinBox(startLinearXSpinBox, &QtGradientEditorPrivate::slotStartLinearXChanged); m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Start X")); startLinearYSpinBox = m_ui.spinBox2; - setSpinBox(startLinearYSpinBox, SLOT(slotStartLinearYChanged(double))); + setupSpinBox(startLinearYSpinBox, &QtGradientEditorPrivate::slotStartLinearYChanged); m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Start Y")); endLinearXSpinBox = m_ui.spinBox3; - setSpinBox(endLinearXSpinBox, SLOT(slotEndLinearXChanged(double))); + setupSpinBox(endLinearXSpinBox, &QtGradientEditorPrivate::slotEndLinearXChanged); m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Final X")); endLinearYSpinBox = m_ui.spinBox4; - setSpinBox(endLinearYSpinBox, SLOT(slotEndLinearYChanged(double))); + setupSpinBox(endLinearYSpinBox, &QtGradientEditorPrivate::slotEndLinearYChanged); m_ui.label4->setText(QCoreApplication::translate("QtGradientEditor", "Final Y")); setStartLinear(m_ui.gradientWidget->startLinear()); setEndLinear(m_ui.gradientWidget->endLinear()); } else if (type == QGradient::RadialGradient) { centralRadialXSpinBox = m_ui.spinBox1; - setSpinBox(centralRadialXSpinBox, SLOT(slotCentralRadialXChanged(double))); + setupSpinBox(centralRadialXSpinBox, &QtGradientEditorPrivate::slotCentralRadialXChanged); m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Central X")); centralRadialYSpinBox = m_ui.spinBox2; - setSpinBox(centralRadialYSpinBox, SLOT(slotCentralRadialYChanged(double))); + setupSpinBox(centralRadialYSpinBox, &QtGradientEditorPrivate::slotCentralRadialYChanged); m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Central Y")); focalRadialXSpinBox = m_ui.spinBox3; - setSpinBox(focalRadialXSpinBox, SLOT(slotFocalRadialXChanged(double))); + setupSpinBox(focalRadialXSpinBox, &QtGradientEditorPrivate::slotFocalRadialXChanged); m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Focal X")); focalRadialYSpinBox = m_ui.spinBox4; - setSpinBox(focalRadialYSpinBox, SLOT(slotFocalRadialYChanged(double))); + setupSpinBox(focalRadialYSpinBox, &QtGradientEditorPrivate::slotFocalRadialYChanged); m_ui.label4->setText(QCoreApplication::translate("QtGradientEditor", "Focal Y")); radiusRadialSpinBox = m_ui.spinBox5; - setSpinBox(radiusRadialSpinBox, SLOT(slotRadiusRadialChanged(double)), 2.0); + setupSpinBox(radiusRadialSpinBox, &QtGradientEditorPrivate::slotRadiusRadialChanged, 2.0); m_ui.label5->setText(QCoreApplication::translate("QtGradientEditor", "Radius")); setCentralRadial(m_ui.gradientWidget->centralRadial()); @@ -470,15 +570,15 @@ void QtGradientEditorPrivate::setType(QGradient::Type type) setRadiusRadial(m_ui.gradientWidget->radiusRadial()); } else if (type == QGradient::ConicalGradient) { centralConicalXSpinBox = m_ui.spinBox1; - setSpinBox(centralConicalXSpinBox, SLOT(slotCentralConicalXChanged(double))); + setupSpinBox(centralConicalXSpinBox, &QtGradientEditorPrivate::slotCentralConicalXChanged); m_ui.label1->setText(QCoreApplication::translate("QtGradientEditor", "Central X")); centralConicalYSpinBox = m_ui.spinBox2; - setSpinBox(centralConicalYSpinBox, SLOT(slotCentralConicalYChanged(double))); + setupSpinBox(centralConicalYSpinBox, &QtGradientEditorPrivate::slotCentralConicalYChanged); m_ui.label2->setText(QCoreApplication::translate("QtGradientEditor", "Central Y")); angleConicalSpinBox = m_ui.spinBox3; - setSpinBox(angleConicalSpinBox, SLOT(slotAngleConicalChanged(double)), 360.0, 1.0, 1); + setupSpinBox(angleConicalSpinBox, &QtGradientEditorPrivate::slotAngleConicalChanged, 360.0, 1.0, 1); m_ui.label3->setText(QCoreApplication::translate("QtGradientEditor", "Angle")); setCentralConical(m_ui.gradientWidget->centralConical()); @@ -496,9 +596,20 @@ void QtGradientEditorPrivate::setType(QGradient::Type type) m_ui.label5->setVisible(row5Visible()); m_ui.spinBox5->setVisible(row5Visible()); - if (m_gridLayout) { + if (m_gridLayout) m_gridLayout->setEnabled(ena); - } +} + +void QtGradientEditorPrivate::setBackgroundCheckered(bool checkered) +{ + m_backgroundCheckered = checkered; + m_ui.hueColorLine->setBackgroundCheckered(checkered); + m_ui.saturationColorLine->setBackgroundCheckered(checkered); + m_ui.valueColorLine->setBackgroundCheckered(checkered); + m_ui.alphaColorLine->setBackgroundCheckered(checkered); + m_ui.gradientWidget->setBackgroundCheckered(checkered); + m_ui.gradientStopsWidget->setBackgroundCheckered(checkered); + m_ui.colorButton->setBackgroundCheckered(checkered); } void QtGradientEditorPrivate::slotGradientStopsChanged(const QGradientStops &stops) @@ -723,107 +834,8 @@ void QtGradientEditorPrivate::setAngleConical(qreal angle) } QtGradientEditor::QtGradientEditor(QWidget *parent) - : QWidget(parent), d_ptr(new QtGradientEditorPrivate()) -{ - d_ptr->q_ptr = this; - d_ptr->m_type = QGradient::RadialGradient; - d_ptr->m_ui.setupUi(this); - d_ptr->m_gridLayout = 0; - d_ptr->m_hiddenLayout = 0; - d_ptr->m_hiddenWidget = 0; - bool detailsDefault = false; - d_ptr->m_details = !detailsDefault; - d_ptr->m_detailsButtonVisible = true; - bool checkeredDefault = true; - d_ptr->m_backgroundCheckered = !checkeredDefault; - d_ptr->m_gradientStopsController = new QtGradientStopsController(this); - d_ptr->m_gradientStopsController->setUi(&d_ptr->m_ui); - d_ptr->reset(); - d_ptr->setType(QGradient::LinearGradient); - d_ptr->m_combos = true; - d_ptr->setCombos(!d_ptr->m_combos); - - d_ptr->showDetails(detailsDefault); - setBackgroundCheckered(checkeredDefault); - - d_ptr->setStartLinear(QPointF(0, 0)); - d_ptr->setEndLinear(QPointF(1, 1)); - d_ptr->setCentralRadial(QPointF(0.5, 0.5)); - d_ptr->setFocalRadial(QPointF(0.5, 0.5)); - d_ptr->setRadiusRadial(0.5); - d_ptr->setCentralConical(QPointF(0.5, 0.5)); - d_ptr->setAngleConical(0); - - QIcon icon; - icon.addPixmap(style()->standardPixmap(QStyle::SP_ArrowRight), QIcon::Normal, QIcon::Off); - icon.addPixmap(style()->standardPixmap(QStyle::SP_ArrowLeft), QIcon::Normal, QIcon::On); - d_ptr->m_ui.detailsButton->setIcon(icon); - - connect(d_ptr->m_ui.detailsButton, SIGNAL(clicked(bool)), this, SLOT(slotDetailsChanged(bool))); - connect(d_ptr->m_gradientStopsController, SIGNAL(gradientStopsChanged(QGradientStops)), - this, SLOT(slotGradientStopsChanged(QGradientStops))); - - QIcon iconLinear(QLatin1String(":/qt-project.org/qtgradienteditor/images/typelinear.png")); - QIcon iconRadial(QLatin1String(":/qt-project.org/qtgradienteditor/images/typeradial.png")); - QIcon iconConical(QLatin1String(":/qt-project.org/qtgradienteditor/images/typeconical.png")); - - d_ptr->m_ui.typeComboBox->addItem(iconLinear, tr("Linear")); - d_ptr->m_ui.typeComboBox->addItem(iconRadial, tr("Radial")); - d_ptr->m_ui.typeComboBox->addItem(iconConical, tr("Conical")); - - d_ptr->m_ui.linearButton->setIcon(iconLinear); - d_ptr->m_ui.radialButton->setIcon(iconRadial); - d_ptr->m_ui.conicalButton->setIcon(iconConical); - - d_ptr->m_typeGroup = new QButtonGroup(this); - d_ptr->m_typeGroup->addButton(d_ptr->m_ui.linearButton, 0); - d_ptr->m_typeGroup->addButton(d_ptr->m_ui.radialButton, 1); - d_ptr->m_typeGroup->addButton(d_ptr->m_ui.conicalButton, 2); - - connect(d_ptr->m_typeGroup, SIGNAL(buttonClicked(int)), - this, SLOT(slotTypeChanged(int))); - connect(d_ptr->m_ui.typeComboBox, SIGNAL(activated(int)), - this, SLOT(slotTypeChanged(int))); - - QIcon iconPad(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadpad.png")); - QIcon iconRepeat(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadrepeat.png")); - QIcon iconReflect(QLatin1String(":/qt-project.org/qtgradienteditor/images/spreadreflect.png")); - - d_ptr->m_ui.spreadComboBox->addItem(iconPad, tr("Pad")); - d_ptr->m_ui.spreadComboBox->addItem(iconRepeat, tr("Repeat")); - d_ptr->m_ui.spreadComboBox->addItem(iconReflect, tr("Reflect")); - - d_ptr->m_ui.padButton->setIcon(iconPad); - d_ptr->m_ui.repeatButton->setIcon(iconRepeat); - d_ptr->m_ui.reflectButton->setIcon(iconReflect); - - d_ptr->m_spreadGroup = new QButtonGroup(this); - d_ptr->m_spreadGroup->addButton(d_ptr->m_ui.padButton, 0); - d_ptr->m_spreadGroup->addButton(d_ptr->m_ui.repeatButton, 1); - d_ptr->m_spreadGroup->addButton(d_ptr->m_ui.reflectButton, 2); - connect(d_ptr->m_spreadGroup, SIGNAL(buttonClicked(int)), - this, SLOT(slotSpreadChanged(int))); - connect(d_ptr->m_ui.spreadComboBox, SIGNAL(activated(int)), - this, SLOT(slotSpreadChanged(int))); - - connect(d_ptr->m_ui.gradientWidget, SIGNAL(startLinearChanged(QPointF)), - this, SLOT(startLinearChanged(QPointF))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(endLinearChanged(QPointF)), - this, SLOT(endLinearChanged(QPointF))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(centralRadialChanged(QPointF)), - this, SLOT(centralRadialChanged(QPointF))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(focalRadialChanged(QPointF)), - this, SLOT(focalRadialChanged(QPointF))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(radiusRadialChanged(qreal)), - this, SLOT(radiusRadialChanged(qreal))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(centralConicalChanged(QPointF)), - this, SLOT(centralConicalChanged(QPointF))); - connect(d_ptr->m_ui.gradientWidget, SIGNAL(angleConicalChanged(qreal)), - this, SLOT(angleConicalChanged(qreal))); - - QGradientStops stops = gradient().stops(); - d_ptr->m_gradientStopsController->setGradientStops(stops); - d_ptr->m_ui.gradientWidget->setGradientStops(stops); + : QWidget(parent), d_ptr(new QtGradientEditorPrivate(this)) +{ } QtGradientEditor::~QtGradientEditor() @@ -903,14 +915,7 @@ void QtGradientEditor::setBackgroundCheckered(bool checkered) if (d_ptr->m_backgroundCheckered == checkered) return; - d_ptr->m_backgroundCheckered = checkered; - d_ptr->m_ui.hueColorLine->setBackgroundCheckered(checkered); - d_ptr->m_ui.saturationColorLine->setBackgroundCheckered(checkered); - d_ptr->m_ui.valueColorLine->setBackgroundCheckered(checkered); - d_ptr->m_ui.alphaColorLine->setBackgroundCheckered(checkered); - d_ptr->m_ui.gradientWidget->setBackgroundCheckered(checkered); - d_ptr->m_ui.gradientStopsWidget->setBackgroundCheckered(checkered); - d_ptr->m_ui.colorButton->setBackgroundCheckered(checkered); + d_ptr->setBackgroundCheckered(checkered); } bool QtGradientEditor::detailsVisible() const @@ -920,6 +925,9 @@ bool QtGradientEditor::detailsVisible() const void QtGradientEditor::setDetailsVisible(bool visible) { + if (d_ptr->m_details == visible) + return; + d_ptr->showDetails(visible); } @@ -949,4 +957,4 @@ void QtGradientEditor::setSpec(QColor::Spec spec) QT_END_NAMESPACE -#include "moc_qtgradienteditor.cpp" +#include "qtgradienteditor.moc" diff --git a/src/shared/qtgradienteditor/qtgradienteditor.h b/src/shared/qtgradienteditor/qtgradienteditor.h index 5d91fb0d4..297d041e8 100644 --- a/src/shared/qtgradienteditor/qtgradienteditor.h +++ b/src/shared/qtgradienteditor/qtgradienteditor.h @@ -71,7 +71,6 @@ public: void setSpec(QColor::Spec spec); signals: - void gradientChanged(const QGradient &gradient); void aboutToShowDetails(bool details, int extenstionWidthHint); @@ -79,29 +78,6 @@ private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientEditor) Q_DISABLE_COPY_MOVE(QtGradientEditor) - Q_PRIVATE_SLOT(d_func(), void slotGradientStopsChanged(const QGradientStops &stops)) - Q_PRIVATE_SLOT(d_func(), void slotTypeChanged(int type)) - Q_PRIVATE_SLOT(d_func(), void slotSpreadChanged(int type)) - Q_PRIVATE_SLOT(d_func(), void slotStartLinearXChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotStartLinearYChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotEndLinearXChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotEndLinearYChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotCentralRadialXChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotCentralRadialYChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotFocalRadialXChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotFocalRadialYChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotRadiusRadialChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotCentralConicalXChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotCentralConicalYChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotAngleConicalChanged(double value)) - Q_PRIVATE_SLOT(d_func(), void slotDetailsChanged(bool details)) - Q_PRIVATE_SLOT(d_func(), void startLinearChanged(const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void endLinearChanged(const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void centralRadialChanged(const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void focalRadialChanged(const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void radiusRadialChanged(qreal)) - Q_PRIVATE_SLOT(d_func(), void centralConicalChanged(const QPointF &)) - Q_PRIVATE_SLOT(d_func(), void angleConicalChanged(qreal)) }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp index 9fb44469a..c91b963f6 100644 --- a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp +++ b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp @@ -45,14 +45,17 @@ QT_BEGIN_NAMESPACE -class QtGradientStopsControllerPrivate +class QtGradientStopsControllerPrivate : public QObject { + Q_OBJECT QtGradientStopsController *q_ptr; Q_DECLARE_PUBLIC(QtGradientStopsController) public: typedef QMap PositionColorMap; typedef QMap PositionStopMap; + void setUi(Ui::QtGradientEditor *ui); + void slotHsvClicked(); void slotRgbClicked(); @@ -66,10 +69,10 @@ public: void slotUpdatePositionSpinBox(); void slotChangeColor(const QColor &color); - void slotChangeHue(const QColor &color); - void slotChangeSaturation(const QColor &color); - void slotChangeValue(const QColor &color); - void slotChangeAlpha(const QColor &color); + void slotChangeHueColor(const QColor &color); + void slotChangeSaturationColor(const QColor &color); + void slotChangeValueColor(const QColor &color); + void slotChangeAlphaColor(const QColor &color); void slotChangeHue(int color); void slotChangeSaturation(int color); void slotChangeValue(int color); @@ -88,12 +91,83 @@ public: QGradientStops makeGradientStops(const PositionColorMap &data) const; void updateZoom(double zoom); - QtGradientStopsModel *m_model; - QColor::Spec m_spec; + QtGradientStopsModel *m_model = nullptr; + QColor::Spec m_spec = QColor::Hsv; Ui::QtGradientEditor *m_ui; }; +void QtGradientStopsControllerPrivate::setUi(Ui::QtGradientEditor *ui) +{ + m_ui = ui; + + m_ui->hueColorLine->setColorComponent(QtColorLine::Hue); + m_ui->saturationColorLine->setColorComponent(QtColorLine::Saturation); + m_ui->valueColorLine->setColorComponent(QtColorLine::Value); + m_ui->alphaColorLine->setColorComponent(QtColorLine::Alpha); + + m_model = new QtGradientStopsModel(this); + m_ui->gradientStopsWidget->setGradientStopsModel(m_model); + connect(m_model, &QtGradientStopsModel::currentStopChanged, + this, &QtGradientStopsControllerPrivate::slotCurrentStopChanged); + connect(m_model, &QtGradientStopsModel::stopMoved, + this, &QtGradientStopsControllerPrivate::slotStopMoved); + connect(m_model, &QtGradientStopsModel::stopsSwapped, + this, &QtGradientStopsControllerPrivate::slotStopsSwapped); + connect(m_model, &QtGradientStopsModel::stopChanged, + this, &QtGradientStopsControllerPrivate::slotStopChanged); + connect(m_model, &QtGradientStopsModel::stopSelected, + this, &QtGradientStopsControllerPrivate::slotStopSelected); + connect(m_model, &QtGradientStopsModel::stopAdded, + this, &QtGradientStopsControllerPrivate::slotStopAdded); + connect(m_model, &QtGradientStopsModel::stopRemoved, + this, &QtGradientStopsControllerPrivate::slotStopRemoved); + + connect(m_ui->hueColorLine, &QtColorLine::colorChanged, + this, &QtGradientStopsControllerPrivate::slotChangeHueColor); + connect(m_ui->saturationColorLine, &QtColorLine::colorChanged, + this, &QtGradientStopsControllerPrivate::slotChangeSaturationColor); + connect(m_ui->valueColorLine, &QtColorLine::colorChanged, + this, &QtGradientStopsControllerPrivate::slotChangeValueColor); + connect(m_ui->alphaColorLine, &QtColorLine::colorChanged, + this, &QtGradientStopsControllerPrivate::slotChangeAlphaColor); + connect(m_ui->colorButton, &QtColorButton::colorChanged, + this, &QtGradientStopsControllerPrivate::slotChangeColor); + + connect(m_ui->hueSpinBox, &QSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangeHue); + connect(m_ui->saturationSpinBox, &QSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangeSaturation); + connect(m_ui->valueSpinBox, &QSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangeValue); + connect(m_ui->alphaSpinBox, &QSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangeAlpha); + + connect(m_ui->positionSpinBox, &QDoubleSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangePosition); + + connect(m_ui->zoomSpinBox, &QSpinBox::valueChanged, + this, &QtGradientStopsControllerPrivate::slotChangeZoom); + connect(m_ui->zoomInButton, &QToolButton::clicked, + this, &QtGradientStopsControllerPrivate::slotZoomIn); + connect(m_ui->zoomOutButton, &QToolButton::clicked, + this, &QtGradientStopsControllerPrivate::slotZoomOut); + connect(m_ui->zoomAllButton, &QToolButton::clicked, + this, &QtGradientStopsControllerPrivate::slotZoomAll); + connect(m_ui->gradientStopsWidget, &QtGradientStopsWidget::zoomChanged, + this, &QtGradientStopsControllerPrivate::slotZoomChanged); + + connect(m_ui->hsvRadioButton, &QRadioButton::clicked, + this, &QtGradientStopsControllerPrivate::slotHsvClicked); + connect(m_ui->rgbRadioButton, &QRadioButton::clicked, + this, &QtGradientStopsControllerPrivate::slotRgbClicked); + + enableCurrent(false); + m_ui->zoomInButton->setIcon(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/zoomin.png"))); + m_ui->zoomOutButton->setIcon(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/zoomout.png"))); + updateZoom(1); +} + void QtGradientStopsControllerPrivate::enableCurrent(bool enable) { m_ui->positionLabel->setEnabled(enable); @@ -274,7 +348,7 @@ void QtGradientStopsControllerPrivate::slotCurrentStopChanged(QtGradientStop *st } enableCurrent(true); - QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); + QTimer::singleShot(0, this, &QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox); m_ui->colorButton->setColor(stop->color()); m_ui->hueColorLine->setColor(stop->color()); @@ -286,7 +360,7 @@ void QtGradientStopsControllerPrivate::slotCurrentStopChanged(QtGradientStop *st void QtGradientStopsControllerPrivate::slotStopMoved(QtGradientStop *stop, qreal newPos) { - QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); + QTimer::singleShot(0, this, &QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox); PositionColorMap stops = stopsData(m_model->stops()); stops.remove(stop->position()); @@ -298,7 +372,7 @@ void QtGradientStopsControllerPrivate::slotStopMoved(QtGradientStop *stop, qreal void QtGradientStopsControllerPrivate::slotStopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2) { - QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); + QTimer::singleShot(0, this, &QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox); PositionColorMap stops = stopsData(m_model->stops()); const qreal pos1 = stop1->position(); @@ -350,7 +424,7 @@ void QtGradientStopsControllerPrivate::slotStopSelected(QtGradientStop *stop, bo { Q_UNUSED(stop); Q_UNUSED(selected); - QTimer::singleShot(0, q_ptr, SLOT(slotUpdatePositionSpinBox())); + QTimer::singleShot(0, this, &QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox); } void QtGradientStopsControllerPrivate::slotUpdatePositionSpinBox() @@ -409,7 +483,7 @@ void QtGradientStopsControllerPrivate::slotChangeColor(const QColor &color) } } -void QtGradientStopsControllerPrivate::slotChangeHue(const QColor &color) +void QtGradientStopsControllerPrivate::slotChangeHueColor(const QColor &color) { QtGradientStop *stop = m_model->currentStop(); if (!stop) @@ -435,10 +509,10 @@ void QtGradientStopsControllerPrivate::slotChangeHue(int color) c.setHsvF(qreal(color) / 360.0, c.saturationF(), c.valueF(), c.alphaF()); else c.setRed(color); - slotChangeHue(c); + slotChangeHueColor(c); } -void QtGradientStopsControllerPrivate::slotChangeSaturation(const QColor &color) +void QtGradientStopsControllerPrivate::slotChangeSaturationColor(const QColor &color) { QtGradientStop *stop = m_model->currentStop(); if (!stop) @@ -468,10 +542,10 @@ void QtGradientStopsControllerPrivate::slotChangeSaturation(int color) c.setHsvF(c.hueF(), qreal(color) / 255, c.valueF(), c.alphaF()); else c.setGreen(color); - slotChangeSaturation(c); + slotChangeSaturationColor(c); } -void QtGradientStopsControllerPrivate::slotChangeValue(const QColor &color) +void QtGradientStopsControllerPrivate::slotChangeValueColor(const QColor &color) { QtGradientStop *stop = m_model->currentStop(); if (!stop) @@ -501,10 +575,10 @@ void QtGradientStopsControllerPrivate::slotChangeValue(int color) c.setHsvF(c.hueF(), c.saturationF(), qreal(color) / 255, c.alphaF()); else c.setBlue(color); - slotChangeValue(c); + slotChangeValueColor(c); } -void QtGradientStopsControllerPrivate::slotChangeAlpha(const QColor &color) +void QtGradientStopsControllerPrivate::slotChangeAlphaColor(const QColor &color) { QtGradientStop *stop = m_model->currentStop(); if (!stop) @@ -534,7 +608,7 @@ void QtGradientStopsControllerPrivate::slotChangeAlpha(int color) c.setHsvF(c.hueF(), c.saturationF(), c.valueF(), qreal(color) / 255); else c.setAlpha(color); - slotChangeAlpha(c); + slotChangeAlphaColor(c); } void QtGradientStopsControllerPrivate::slotChangePosition(double value) @@ -581,79 +655,11 @@ QtGradientStopsController::QtGradientStopsController(QObject *parent) : QObject(parent), d_ptr(new QtGradientStopsControllerPrivate()) { d_ptr->q_ptr = this; - - d_ptr->m_spec = QColor::Hsv; } void QtGradientStopsController::setUi(Ui::QtGradientEditor *ui) { - d_ptr->m_ui = ui; - - d_ptr->m_ui->hueColorLine->setColorComponent(QtColorLine::Hue); - d_ptr->m_ui->saturationColorLine->setColorComponent(QtColorLine::Saturation); - d_ptr->m_ui->valueColorLine->setColorComponent(QtColorLine::Value); - d_ptr->m_ui->alphaColorLine->setColorComponent(QtColorLine::Alpha); - - d_ptr->m_model = new QtGradientStopsModel(this); - d_ptr->m_ui->gradientStopsWidget->setGradientStopsModel(d_ptr->m_model); - connect(d_ptr->m_model, SIGNAL(currentStopChanged(QtGradientStop*)), - this, SLOT(slotCurrentStopChanged(QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopMoved(QtGradientStop*,qreal)), - this, SLOT(slotStopMoved(QtGradientStop*,qreal))); - connect(d_ptr->m_model, SIGNAL(stopsSwapped(QtGradientStop*,QtGradientStop*)), - this, SLOT(slotStopsSwapped(QtGradientStop*,QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopChanged(QtGradientStop*,QColor)), - this, SLOT(slotStopChanged(QtGradientStop*,QColor))); - connect(d_ptr->m_model, SIGNAL(stopSelected(QtGradientStop*,bool)), - this, SLOT(slotStopSelected(QtGradientStop*,bool))); - connect(d_ptr->m_model, SIGNAL(stopAdded(QtGradientStop*)), - this, SLOT(slotStopAdded(QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopRemoved(QtGradientStop*)), - this, SLOT(slotStopRemoved(QtGradientStop*))); - - connect(d_ptr->m_ui->hueColorLine, SIGNAL(colorChanged(QColor)), - this, SLOT(slotChangeHue(QColor))); - connect(d_ptr->m_ui->saturationColorLine, SIGNAL(colorChanged(QColor)), - this, SLOT(slotChangeSaturation(QColor))); - connect(d_ptr->m_ui->valueColorLine, SIGNAL(colorChanged(QColor)), - this, SLOT(slotChangeValue(QColor))); - connect(d_ptr->m_ui->alphaColorLine, SIGNAL(colorChanged(QColor)), - this, SLOT(slotChangeAlpha(QColor))); - connect(d_ptr->m_ui->colorButton, SIGNAL(colorChanged(QColor)), - this, SLOT(slotChangeColor(QColor))); - - connect(d_ptr->m_ui->hueSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(slotChangeHue(int))); - connect(d_ptr->m_ui->saturationSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(slotChangeSaturation(int))); - connect(d_ptr->m_ui->valueSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(slotChangeValue(int))); - connect(d_ptr->m_ui->alphaSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(slotChangeAlpha(int))); - - connect(d_ptr->m_ui->positionSpinBox, SIGNAL(valueChanged(double)), - this, SLOT(slotChangePosition(double))); - - connect(d_ptr->m_ui->zoomSpinBox, SIGNAL(valueChanged(int)), - this, SLOT(slotChangeZoom(int))); - connect(d_ptr->m_ui->zoomInButton, SIGNAL(clicked()), - this, SLOT(slotZoomIn())); - connect(d_ptr->m_ui->zoomOutButton, SIGNAL(clicked()), - this, SLOT(slotZoomOut())); - connect(d_ptr->m_ui->zoomAllButton, SIGNAL(clicked()), - this, SLOT(slotZoomAll())); - connect(d_ptr->m_ui->gradientStopsWidget, SIGNAL(zoomChanged(double)), - this, SLOT(slotZoomChanged(double))); - - connect(d_ptr->m_ui->hsvRadioButton, SIGNAL(clicked()), - this, SLOT(slotHsvClicked())); - connect(d_ptr->m_ui->rgbRadioButton, SIGNAL(clicked()), - this, SLOT(slotRgbClicked())); - - d_ptr->enableCurrent(false); - d_ptr->m_ui->zoomInButton->setIcon(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/zoomin.png"))); - d_ptr->m_ui->zoomOutButton->setIcon(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/zoomout.png"))); - d_ptr->updateZoom(1); + d_ptr->setUi(ui); } QtGradientStopsController::~QtGradientStopsController() @@ -704,4 +710,4 @@ void QtGradientStopsController::setSpec(QColor::Spec spec) QT_END_NAMESPACE -#include "moc_qtgradientstopscontroller.cpp" +#include "qtgradientstopscontroller.moc" diff --git a/src/shared/qtgradienteditor/qtgradientstopscontroller.h b/src/shared/qtgradienteditor/qtgradientstopscontroller.h index 1b3bbd391..bdda9efaf 100644 --- a/src/shared/qtgradienteditor/qtgradientstopscontroller.h +++ b/src/shared/qtgradienteditor/qtgradientstopscontroller.h @@ -64,39 +64,12 @@ public: void setSpec(QColor::Spec spec); signals: - void gradientStopsChanged(const QGradientStops &stops); private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientStopsController) Q_DISABLE_COPY_MOVE(QtGradientStopsController) - Q_PRIVATE_SLOT(d_func(), void slotHsvClicked()) - Q_PRIVATE_SLOT(d_func(), void slotRgbClicked()) - Q_PRIVATE_SLOT(d_func(), void slotCurrentStopChanged(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotStopMoved(QtGradientStop *stop, qreal newPos)) - Q_PRIVATE_SLOT(d_func(), void slotStopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2)) - Q_PRIVATE_SLOT(d_func(), void slotStopChanged(QtGradientStop *stop, const QColor &newColor)) - Q_PRIVATE_SLOT(d_func(), void slotStopSelected(QtGradientStop *stop, bool selected)) - Q_PRIVATE_SLOT(d_func(), void slotStopAdded(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotStopRemoved(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotUpdatePositionSpinBox()) - Q_PRIVATE_SLOT(d_func(), void slotChangeColor(const QColor &color)) - Q_PRIVATE_SLOT(d_func(), void slotChangeHue(const QColor &color)) - Q_PRIVATE_SLOT(d_func(), void slotChangeSaturation(const QColor &color)) - Q_PRIVATE_SLOT(d_func(), void slotChangeValue(const QColor &color)) - Q_PRIVATE_SLOT(d_func(), void slotChangeAlpha(const QColor &color)) - Q_PRIVATE_SLOT(d_func(), void slotChangeHue(int)) - Q_PRIVATE_SLOT(d_func(), void slotChangeSaturation(int)) - Q_PRIVATE_SLOT(d_func(), void slotChangeValue(int)) - Q_PRIVATE_SLOT(d_func(), void slotChangeAlpha(int)) - //Q_PRIVATE_SLOT(d_func(), void slotChangePosition(double newPos)) - Q_PRIVATE_SLOT(d_func(), void slotChangePosition(double value)) - Q_PRIVATE_SLOT(d_func(), void slotChangeZoom(int value)) - Q_PRIVATE_SLOT(d_func(), void slotZoomIn()) - Q_PRIVATE_SLOT(d_func(), void slotZoomOut()) - Q_PRIVATE_SLOT(d_func(), void slotZoomAll()) - Q_PRIVATE_SLOT(d_func(), void slotZoomChanged(double)) }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp index 02c6434fe..5a3abea8b 100644 --- a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp +++ b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp @@ -51,14 +51,17 @@ QT_BEGIN_NAMESPACE -class QtGradientStopsWidgetPrivate +class QtGradientStopsWidgetPrivate : public QObject { + Q_OBJECT QtGradientStopsWidget *q_ptr; Q_DECLARE_PUBLIC(QtGradientStopsWidget) public: typedef QMap PositionColorMap; typedef QMap StopPositionMap; + void setGradientStopsModel(QtGradientStopsModel *model); + void slotStopAdded(QtGradientStop *stop); void slotStopRemoved(QtGradientStop *stop); void slotStopMoved(QtGradientStop *stop, qreal newPos); @@ -114,6 +117,60 @@ public: PositionColorMap m_moveOriginal; }; +void QtGradientStopsWidgetPrivate::setGradientStopsModel(QtGradientStopsModel *model) +{ + if (m_model == model) + return; + + if (m_model) { + disconnect(m_model, &QtGradientStopsModel::stopAdded, + this, &QtGradientStopsWidgetPrivate::slotStopAdded); + disconnect(m_model, &QtGradientStopsModel::stopRemoved, + this, &QtGradientStopsWidgetPrivate::slotStopRemoved); + disconnect(m_model, &QtGradientStopsModel::stopMoved, + this, &QtGradientStopsWidgetPrivate::slotStopMoved); + disconnect(m_model, &QtGradientStopsModel::stopsSwapped, + this, &QtGradientStopsWidgetPrivate::slotStopsSwapped); + disconnect(m_model, &QtGradientStopsModel::stopChanged, + this, &QtGradientStopsWidgetPrivate::slotStopChanged); + disconnect(m_model, &QtGradientStopsModel::stopSelected, + this, &QtGradientStopsWidgetPrivate::slotStopSelected); + disconnect(m_model, &QtGradientStopsModel::currentStopChanged, + this, &QtGradientStopsWidgetPrivate::slotCurrentStopChanged); + + m_stops.clear(); + } + + m_model = model; + + if (m_model) { + connect(m_model, &QtGradientStopsModel::stopAdded, + this, &QtGradientStopsWidgetPrivate::slotStopAdded); + connect(m_model, &QtGradientStopsModel::stopRemoved, + this, &QtGradientStopsWidgetPrivate::slotStopRemoved); + connect(m_model, &QtGradientStopsModel::stopMoved, + this, &QtGradientStopsWidgetPrivate::slotStopMoved); + connect(m_model, &QtGradientStopsModel::stopsSwapped, + this, &QtGradientStopsWidgetPrivate::slotStopsSwapped); + connect(m_model, &QtGradientStopsModel::stopChanged, + this, &QtGradientStopsWidgetPrivate::slotStopChanged); + connect(m_model, &QtGradientStopsModel::stopSelected, + this, &QtGradientStopsWidgetPrivate::slotStopSelected); + connect(m_model, &QtGradientStopsModel::currentStopChanged, + this, &QtGradientStopsWidgetPrivate::slotCurrentStopChanged); + + const QtGradientStopsModel::PositionStopMap stopsMap = m_model->stops(); + for (auto it = stopsMap.cbegin(), end = stopsMap.cend(); it != end; ++it) + slotStopAdded(it.value()); + + const auto selected = m_model->selectedStops(); + for (QtGradientStop *stop : selected) + slotStopSelected(stop, true); + + slotCurrentStopChanged(m_model->currentStop()); + } +} + double QtGradientStopsWidgetPrivate::fromViewport(int x) const { QSize size = q_ptr->viewport()->size(); @@ -406,56 +463,7 @@ bool QtGradientStopsWidget::isBackgroundCheckered() const void QtGradientStopsWidget::setGradientStopsModel(QtGradientStopsModel *model) { - if (d_ptr->m_model == model) - return; - - if (d_ptr->m_model) { - disconnect(d_ptr->m_model, SIGNAL(stopAdded(QtGradientStop*)), - this, SLOT(slotStopAdded(QtGradientStop*))); - disconnect(d_ptr->m_model, SIGNAL(stopRemoved(QtGradientStop*)), - this, SLOT(slotStopRemoved(QtGradientStop*))); - disconnect(d_ptr->m_model, SIGNAL(stopMoved(QtGradientStop*,qreal)), - this, SLOT(slotStopMoved(QtGradientStop*,qreal))); - disconnect(d_ptr->m_model, SIGNAL(stopsSwapped(QtGradientStop*,QtGradientStop*)), - this, SLOT(slotStopsSwapped(QtGradientStop*,QtGradientStop*))); - disconnect(d_ptr->m_model, SIGNAL(stopChanged(QtGradientStop*,QColor)), - this, SLOT(slotStopChanged(QtGradientStop*,QColor))); - disconnect(d_ptr->m_model, SIGNAL(stopSelected(QtGradientStop*,bool)), - this, SLOT(slotStopSelected(QtGradientStop*,bool))); - disconnect(d_ptr->m_model, SIGNAL(currentStopChanged(QtGradientStop*)), - this, SLOT(slotCurrentStopChanged(QtGradientStop*))); - - d_ptr->m_stops.clear(); - } - - d_ptr->m_model = model; - - if (d_ptr->m_model) { - connect(d_ptr->m_model, SIGNAL(stopAdded(QtGradientStop*)), - this, SLOT(slotStopAdded(QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopRemoved(QtGradientStop*)), - this, SLOT(slotStopRemoved(QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopMoved(QtGradientStop*,qreal)), - this, SLOT(slotStopMoved(QtGradientStop*,qreal))); - connect(d_ptr->m_model, SIGNAL(stopsSwapped(QtGradientStop*,QtGradientStop*)), - this, SLOT(slotStopsSwapped(QtGradientStop*,QtGradientStop*))); - connect(d_ptr->m_model, SIGNAL(stopChanged(QtGradientStop*,QColor)), - this, SLOT(slotStopChanged(QtGradientStop*,QColor))); - connect(d_ptr->m_model, SIGNAL(stopSelected(QtGradientStop*,bool)), - this, SLOT(slotStopSelected(QtGradientStop*,bool))); - connect(d_ptr->m_model, SIGNAL(currentStopChanged(QtGradientStop*)), - this, SLOT(slotCurrentStopChanged(QtGradientStop*))); - - const QtGradientStopsModel::PositionStopMap stopsMap = d_ptr->m_model->stops(); - for (auto it = stopsMap.cbegin(), end = stopsMap.cend(); it != end; ++it) - d_ptr->slotStopAdded(it.value()); - - const auto selected = d_ptr->m_model->selectedStops(); - for (QtGradientStop *stop : selected) - d_ptr->slotStopSelected(stop, true); - - d_ptr->slotCurrentStopChanged(d_ptr->m_model->currentStop()); - } + d_ptr->setGradientStopsModel(model); } void QtGradientStopsWidget::mousePressEvent(QMouseEvent *e) @@ -940,13 +948,13 @@ void QtGradientStopsWidget::contextMenuEvent(QContextMenuEvent *e) } else if (zoom() >= 100) { zoomInAction->setEnabled(false); } - connect(newStopAction, SIGNAL(triggered()), this, SLOT(slotNewStop())); - connect(deleteAction, SIGNAL(triggered()), this, SLOT(slotDelete())); - connect(flipAllAction, SIGNAL(triggered()), this, SLOT(slotFlipAll())); - connect(selectAllAction, SIGNAL(triggered()), this, SLOT(slotSelectAll())); - connect(zoomInAction, SIGNAL(triggered()), this, SLOT(slotZoomIn())); - connect(zoomOutAction, SIGNAL(triggered()), this, SLOT(slotZoomOut())); - connect(zoomAllAction, SIGNAL(triggered()), this, SLOT(slotResetZoom())); + connect(newStopAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotNewStop); + connect(deleteAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotDelete); + connect(flipAllAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotFlipAll); + connect(selectAllAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotSelectAll); + connect(zoomInAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotZoomIn); + connect(zoomOutAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotZoomOut); + connect(zoomAllAction, &QAction::triggered, d_ptr.data(), &QtGradientStopsWidgetPrivate::slotResetZoom); menu.addAction(newStopAction); menu.addAction(deleteAction); menu.addAction(flipAllAction); @@ -1132,4 +1140,4 @@ double QtGradientStopsWidget::zoom() const QT_END_NAMESPACE -#include "moc_qtgradientstopswidget.cpp" +#include "qtgradientstopswidget.moc" diff --git a/src/shared/qtgradienteditor/qtgradientstopswidget.h b/src/shared/qtgradienteditor/qtgradientstopswidget.h index 025f72846..c7a1d145f 100644 --- a/src/shared/qtgradienteditor/qtgradientstopswidget.h +++ b/src/shared/qtgradienteditor/qtgradientstopswidget.h @@ -67,7 +67,6 @@ public: double zoom() const; signals: - void zoomChanged(double zoom); protected: @@ -92,20 +91,6 @@ private: QScopedPointer d_ptr; Q_DECLARE_PRIVATE(QtGradientStopsWidget) Q_DISABLE_COPY_MOVE(QtGradientStopsWidget) - Q_PRIVATE_SLOT(d_func(), void slotStopAdded(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotStopRemoved(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotStopMoved(QtGradientStop *stop, qreal newPos)) - Q_PRIVATE_SLOT(d_func(), void slotStopsSwapped(QtGradientStop *stop1, QtGradientStop *stop2)) - Q_PRIVATE_SLOT(d_func(), void slotStopChanged(QtGradientStop *stop, const QColor &newColor)) - Q_PRIVATE_SLOT(d_func(), void slotStopSelected(QtGradientStop *stop, bool selected)) - Q_PRIVATE_SLOT(d_func(), void slotCurrentStopChanged(QtGradientStop *stop)) - Q_PRIVATE_SLOT(d_func(), void slotNewStop()) - Q_PRIVATE_SLOT(d_func(), void slotDelete()) - Q_PRIVATE_SLOT(d_func(), void slotFlipAll()) - Q_PRIVATE_SLOT(d_func(), void slotSelectAll()) - Q_PRIVATE_SLOT(d_func(), void slotZoomIn()) - Q_PRIVATE_SLOT(d_func(), void slotZoomOut()) - Q_PRIVATE_SLOT(d_func(), void slotResetZoom()) }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtgradientutils.h b/src/shared/qtgradienteditor/qtgradientutils.h index e0fe68193..fdb6dace0 100644 --- a/src/shared/qtgradienteditor/qtgradientutils.h +++ b/src/shared/qtgradienteditor/qtgradientutils.h @@ -56,7 +56,6 @@ public: static void restoreState(QtGradientManager *manager, const QString &state); static QPixmap gradientPixmap(const QGradient &gradient, const QSize &size = QSize(64, 64), bool checkeredBackground = false); - }; QT_END_NAMESPACE diff --git a/src/shared/qtgradienteditor/qtgradientview.cpp b/src/shared/qtgradienteditor/qtgradientview.cpp index 40e698818..061b9f776 100644 --- a/src/shared/qtgradienteditor/qtgradientview.cpp +++ b/src/shared/qtgradienteditor/qtgradientview.cpp @@ -149,7 +149,7 @@ void QtGradientView::slotRenameGradient() m_ui.listWidget->editItem(item); } -void QtGradientView::slotRenameGradient(QListWidgetItem *item) +void QtGradientView::slotRenameGradientItem(QListWidgetItem *item) { if (!item) return; @@ -202,19 +202,19 @@ QtGradientView::QtGradientView(QWidget *parent) pal.setBrush(QPalette::Base, QBrush(pm)); m_ui.listWidget->viewport()->setPalette(pal); - connect(m_ui.listWidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotGradientActivated(QListWidgetItem*))); - connect(m_ui.listWidget, SIGNAL(itemChanged(QListWidgetItem*)), this, SLOT(slotRenameGradient(QListWidgetItem*))); - connect(m_ui.listWidget, SIGNAL(currentItemChanged(QListWidgetItem*,QListWidgetItem*)), this, SLOT(slotCurrentItemChanged(QListWidgetItem*))); + connect(m_ui.listWidget, &QListWidget::itemDoubleClicked, this, &QtGradientView::slotGradientActivated); + connect(m_ui.listWidget, &QListWidget::itemChanged, this, &QtGradientView::slotRenameGradientItem); + connect(m_ui.listWidget, &QListWidget::currentItemChanged, this, &QtGradientView::slotCurrentItemChanged); m_newAction = new QAction(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/plus.png")), tr("New..."), this); m_editAction = new QAction(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/edit.png")), tr("Edit..."), this); m_renameAction = new QAction(tr("Rename"), this); m_removeAction = new QAction(QIcon(QLatin1String(":/qt-project.org/qtgradienteditor/images/minus.png")), tr("Remove"), this); - connect(m_newAction, SIGNAL(triggered()), this, SLOT(slotNewGradient())); - connect(m_editAction, SIGNAL(triggered()), this, SLOT(slotEditGradient())); - connect(m_removeAction, SIGNAL(triggered()), this, SLOT(slotRemoveGradient())); - connect(m_renameAction, SIGNAL(triggered()), this, SLOT(slotRenameGradient())); + connect(m_newAction, &QAction::triggered, this, &QtGradientView::slotNewGradient); + connect(m_editAction, &QAction::triggered, this, &QtGradientView::slotEditGradient); + connect(m_removeAction, &QAction::triggered, this, &QtGradientView::slotRemoveGradient); + connect(m_renameAction, &QAction::triggered, this, &QtGradientView::slotRenameGradient); m_ui.listWidget->addAction(m_newAction); m_ui.listWidget->addAction(m_editAction); @@ -235,14 +235,14 @@ void QtGradientView::setGradientManager(QtGradientManager *manager) return; if (m_manager) { - disconnect(m_manager, SIGNAL(gradientAdded(QString,QGradient)), - this, SLOT(slotGradientAdded(QString,QGradient))); - disconnect(m_manager, SIGNAL(gradientRenamed(QString,QString)), - this, SLOT(slotGradientRenamed(QString,QString))); - disconnect(m_manager, SIGNAL(gradientChanged(QString,QGradient)), - this, SLOT(slotGradientChanged(QString,QGradient))); - disconnect(m_manager, SIGNAL(gradientRemoved(QString)), - this, SLOT(slotGradientRemoved(QString))); + disconnect(m_manager, &QtGradientManager::gradientAdded, + this, &QtGradientView::slotGradientAdded); + disconnect(m_manager, &QtGradientManager::gradientRenamed, + this, &QtGradientView::slotGradientRenamed); + disconnect(m_manager, &QtGradientManager::gradientChanged, + this, &QtGradientView::slotGradientChanged); + disconnect(m_manager, &QtGradientManager::gradientRemoved, + this, &QtGradientView::slotGradientRemoved); m_ui.listWidget->clear(); m_idToItem.clear(); @@ -258,14 +258,14 @@ void QtGradientView::setGradientManager(QtGradientManager *manager) for (auto itGrad = gradients.cbegin(), end = gradients.cend(); itGrad != end; ++itGrad) slotGradientAdded(itGrad.key(), itGrad.value()); - connect(m_manager, SIGNAL(gradientAdded(QString,QGradient)), - this, SLOT(slotGradientAdded(QString,QGradient))); - connect(m_manager, SIGNAL(gradientRenamed(QString,QString)), - this, SLOT(slotGradientRenamed(QString,QString))); - connect(m_manager, SIGNAL(gradientChanged(QString,QGradient)), - this, SLOT(slotGradientChanged(QString,QGradient))); - connect(m_manager, SIGNAL(gradientRemoved(QString)), - this, SLOT(slotGradientRemoved(QString))); + connect(m_manager, &QtGradientManager::gradientAdded, + this, &QtGradientView::slotGradientAdded); + connect(m_manager, &QtGradientManager::gradientRenamed, + this, &QtGradientView::slotGradientRenamed); + connect(m_manager, &QtGradientManager::gradientChanged, + this, &QtGradientView::slotGradientChanged); + connect(m_manager, &QtGradientManager::gradientRemoved, + this, &QtGradientView::slotGradientRemoved); } QtGradientManager *QtGradientView::gradientManager() const diff --git a/src/shared/qtgradienteditor/qtgradientview.h b/src/shared/qtgradienteditor/qtgradientview.h index c1637cd8f..67e070412 100644 --- a/src/shared/qtgradienteditor/qtgradientview.h +++ b/src/shared/qtgradienteditor/qtgradientview.h @@ -75,7 +75,7 @@ private slots: void slotEditGradient(); void slotRemoveGradient(); void slotRenameGradient(); - void slotRenameGradient(QListWidgetItem *item); + void slotRenameGradientItem(QListWidgetItem *item); void slotCurrentItemChanged(QListWidgetItem *item); void slotGradientActivated(QListWidgetItem *item); diff --git a/src/shared/qtgradienteditor/qtgradientviewdialog.cpp b/src/shared/qtgradienteditor/qtgradientviewdialog.cpp index 103c4492e..281bef5ea 100644 --- a/src/shared/qtgradienteditor/qtgradientviewdialog.cpp +++ b/src/shared/qtgradienteditor/qtgradientviewdialog.cpp @@ -48,10 +48,10 @@ QtGradientViewDialog::QtGradientViewDialog(QWidget *parent) { m_ui.setupUi(this); m_ui.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); - connect(m_ui.gradientView, SIGNAL(currentGradientChanged(QString)), - this, SLOT(slotGradientSelected(QString))); - connect(m_ui.gradientView, SIGNAL(gradientActivated(QString)), - this, SLOT(slotGradientActivated(QString))); + connect(m_ui.gradientView, &QtGradientView::currentGradientChanged, + this, &QtGradientViewDialog::slotGradientSelected); + connect(m_ui.gradientView, &QtGradientView::gradientActivated, + this, &QtGradientViewDialog::slotGradientActivated); } void QtGradientViewDialog::setGradientManager(QtGradientManager *manager) diff --git a/src/shared/qtgradienteditor/qtgradientwidget.h b/src/shared/qtgradienteditor/qtgradientwidget.h index a5609e77b..dee31fd19 100644 --- a/src/shared/qtgradienteditor/qtgradientwidget.h +++ b/src/shared/qtgradienteditor/qtgradientwidget.h @@ -90,6 +90,7 @@ public: public slots: void setGradientStops(const QGradientStops &stops); + signals: void startLinearChanged(const QPointF &point); -- cgit v1.2.3