summaryrefslogtreecommitdiffstats
path: root/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/qtgradienteditor/qtgradientstopscontroller.cpp')
-rw-r--r--src/shared/qtgradienteditor/qtgradientstopscontroller.cpp249
1 files changed, 106 insertions, 143 deletions
diff --git a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
index 20cea9499..8dcd0171a 100644
--- a/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
+++ b/src/shared/qtgradienteditor/qtgradientstopscontroller.cpp
@@ -1,41 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the tools applications of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qtgradientstopscontroller.h"
#include "ui_qtgradienteditor.h"
@@ -45,13 +9,18 @@
QT_BEGIN_NAMESPACE
-class QtGradientStopsControllerPrivate
+using namespace Qt::StringLiterals;
+
+class QtGradientStopsControllerPrivate : public QObject
{
+ Q_OBJECT
QtGradientStopsController *q_ptr;
Q_DECLARE_PUBLIC(QtGradientStopsController)
public:
- typedef QMap<qreal, QColor> PositionColorMap;
- typedef QMap<qreal, QtGradientStop *> PositionStopMap;
+ using PositionColorMap = QMap<qreal, QColor>;
+ using PositionStopMap = QMap<qreal, QtGradientStop *>;
+
+ void setUi(Ui::QtGradientEditor *ui);
void slotHsvClicked();
void slotRgbClicked();
@@ -66,10 +35,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 +57,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(":/qt-project.org/qtgradienteditor/images/zoomin.png"_L1));
+ m_ui->zoomOutButton->setIcon(QIcon(":/qt-project.org/qtgradienteditor/images/zoomout.png"_L1));
+ updateZoom(1);
+}
+
void QtGradientStopsControllerPrivate::enableCurrent(bool enable)
{
m_ui->positionLabel->setEnabled(enable);
@@ -124,25 +164,16 @@ void QtGradientStopsControllerPrivate::enableCurrent(bool enable)
QtGradientStopsControllerPrivate::PositionColorMap QtGradientStopsControllerPrivate::stopsData(const PositionStopMap &stops) const
{
PositionColorMap data;
- PositionStopMap::ConstIterator itStop = stops.constBegin();
- while (itStop != stops.constEnd()) {
- QtGradientStop *stop = itStop.value();
+ for (QtGradientStop *stop : stops)
data[stop->position()] = stop->color();
-
- ++itStop;
- }
return data;
}
QGradientStops QtGradientStopsControllerPrivate::makeGradientStops(const PositionColorMap &data) const
{
QGradientStops stops;
- PositionColorMap::ConstIterator itData = data.constBegin();
- while (itData != data.constEnd()) {
- stops << QPair<qreal, QColor>(itData.key(), itData.value());
-
- ++itData;
- }
+ for (auto itData = data.cbegin(), cend = data.cend(); itData != cend; ++itData)
+ stops << std::pair<qreal, QColor>(itData.key(), itData.value());
return stops;
}
@@ -274,7 +305,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 +317,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 +329,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 +381,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 +440,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 +466,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 +499,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 +532,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 +565,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 +612,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()
@@ -664,7 +627,7 @@ void QtGradientStopsController::setGradientStops(const QGradientStops &stops)
{
d_ptr->m_model->clear();
QtGradientStop *first = nullptr;
- for (const QPair<qreal, QColor> &pair : stops) {
+ for (const std::pair<qreal, QColor> &pair : stops) {
QtGradientStop *stop = d_ptr->m_model->addStop(pair.first, pair.second);
if (!first)
first = stop;
@@ -678,7 +641,7 @@ QGradientStops QtGradientStopsController::gradientStops() const
QGradientStops stops;
const auto stopsList = d_ptr->m_model->stops().values();
for (const QtGradientStop *stop : stopsList)
- stops << QPair<qreal, QColor>(stop->position(), stop->color());
+ stops.append({stop->position(), stop->color()});
return stops;
}
@@ -704,4 +667,4 @@ void QtGradientStopsController::setSpec(QColor::Spec spec)
QT_END_NAMESPACE
-#include "moc_qtgradientstopscontroller.cpp"
+#include "qtgradientstopscontroller.moc"