summaryrefslogtreecommitdiffstats
path: root/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/qtgradienteditor/qtgradientstopswidget.cpp')
-rw-r--r--src/shared/qtgradienteditor/qtgradientstopswidget.cpp195
1 files changed, 80 insertions, 115 deletions
diff --git a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
index 80bc3ed68..c0aff22eb 100644
--- a/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
+++ b/src/shared/qtgradienteditor/qtgradientstopswidget.cpp
@@ -1,46 +1,11 @@
-/****************************************************************************
-**
-** 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 "qtgradientstopswidget.h"
#include "qtgradientstopsmodel.h"
#include <QtCore/QMap>
+#include <QtCore/QHash>
#include <QtCore/QMimeData>
#include <QtGui/QImage>
#include <QtGui/QPainter>
@@ -51,13 +16,13 @@
QT_BEGIN_NAMESPACE
-class QtGradientStopsWidgetPrivate
+class QtGradientStopsWidgetPrivate : public QObject
{
+ Q_OBJECT
QtGradientStopsWidget *q_ptr;
Q_DECLARE_PUBLIC(QtGradientStopsWidget)
public:
- typedef QMap<qreal, QColor> PositionColorMap;
- typedef QMap<QtGradientStop *, qreal> StopPositionMap;
+ void setGradientStopsModel(QtGradientStopsModel *model);
void slotStopAdded(QtGradientStop *stop);
void slotStopRemoved(QtGradientStop *stop);
@@ -109,11 +74,65 @@ public:
bool m_moving;
int m_moveOffset;
- StopPositionMap m_moveStops;
+ QHash<QtGradientStop *, qreal> m_moveStops;
- PositionColorMap m_moveOriginal;
+ QMap<qreal, QColor> 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 auto 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,61 +425,11 @@ 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)
{
- typedef QtGradientStopsModel::PositionStopMap PositionStopMap;
if (!d_ptr->m_model)
return;
@@ -479,8 +448,8 @@ void QtGradientStopsWidget::mousePressEvent(QMouseEvent *e)
} else if (e->modifiers() & Qt::ShiftModifier) {
QtGradientStop *oldCurrent = d_ptr->m_model->currentStop();
if (oldCurrent) {
- PositionStopMap stops = d_ptr->m_model->stops();
- PositionStopMap::ConstIterator itSt = stops.constFind(oldCurrent->position());
+ const auto stops = d_ptr->m_model->stops();
+ auto itSt = stops.constFind(oldCurrent->position());
if (itSt != stops.constEnd()) {
while (itSt != stops.constFind(stop->position())) {
d_ptr->m_model->selectStop(itSt.value(), true);
@@ -523,9 +492,6 @@ void QtGradientStopsWidget::mouseReleaseEvent(QMouseEvent *e)
void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
{
- typedef QtGradientStopsWidgetPrivate::PositionColorMap PositionColorMap;
- typedef QtGradientStopsModel::PositionStopMap PositionStopMap;
- typedef QtGradientStopsWidgetPrivate::StopPositionMap StopPositionMap;
if (!d_ptr->m_model)
return;
@@ -539,7 +505,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
double maxOffset = 0.0;
double minOffset = 0.0;
bool first = true;
- StopPositionMap::ConstIterator itStop = d_ptr->m_moveStops.constBegin();
+ auto itStop = d_ptr->m_moveStops.cbegin();
while (itStop != d_ptr->m_moveStops.constEnd()) {
double offset = itStop.value();
@@ -559,7 +525,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
double viewportMin = d_ptr->toViewport(-minOffset);
double viewportMax = d_ptr->toViewport(1.0 - maxOffset);
- PositionStopMap newPositions;
+ QtGradientStopsModel::PositionStopMap newPositions;
int viewportX = e->position().toPoint().x() - d_ptr->m_moveOffset;
@@ -585,7 +551,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
}
bool forward = true;
- PositionStopMap::ConstIterator itNewPos = newPositions.constBegin();
+ auto itNewPos = newPositions.cbegin();
if (itNewPos.value()->position() < itNewPos.key())
forward = false;
@@ -609,7 +575,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
++itNewPos;
}
- PositionColorMap::ConstIterator itOld = d_ptr->m_moveOriginal.constBegin();
+ auto itOld = d_ptr->m_moveOriginal.cbegin();
while (itOld != d_ptr->m_moveOriginal.constEnd()) {
double position = itOld.key();
if (!d_ptr->m_model->at(position))
@@ -658,7 +624,7 @@ void QtGradientStopsWidget::mouseMoveEvent(QMouseEvent *e)
double x1 = d_ptr->fromViewport(xv1);
double x2 = d_ptr->fromViewport(xv2);
- for (QtGradientStop *stop : qAsConst(d_ptr->m_stops)) {
+ for (QtGradientStop *stop : std::as_const(d_ptr->m_stops)) {
if ((stop->position() >= x1 && stop->position() <= x2) ||
beginList.contains(stop) || endList.contains(stop))
d_ptr->m_model->selectStop(stop, true);
@@ -699,7 +665,6 @@ void QtGradientStopsWidget::mouseDoubleClickEvent(QMouseEvent *e)
void QtGradientStopsWidget::keyPressEvent(QKeyEvent *e)
{
- typedef QtGradientStopsModel::PositionStopMap PositionStopMap;
if (!d_ptr->m_model)
return;
@@ -707,7 +672,7 @@ void QtGradientStopsWidget::keyPressEvent(QKeyEvent *e)
d_ptr->m_model->deleteStops();
} else if (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right ||
e->key() == Qt::Key_Home || e->key() == Qt::Key_End) {
- PositionStopMap stops = d_ptr->m_model->stops();
+ const auto stops = d_ptr->m_model->stops();
if (stops.isEmpty())
return;
QtGradientStop *newCurrent = nullptr;
@@ -718,7 +683,7 @@ void QtGradientStopsWidget::keyPressEvent(QKeyEvent *e)
else if (e->key() == Qt::Key_Right || e->key() == Qt::Key_End)
newCurrent = (--stops.constEnd()).value();
} else {
- PositionStopMap::ConstIterator itStop = stops.constBegin();
+ auto itStop = stops.cbegin();
while (itStop.value() != current)
++itStop;
if (e->key() == Qt::Key_Left && itStop != stops.constBegin())
@@ -940,13 +905,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 +1097,4 @@ double QtGradientStopsWidget::zoom() const
QT_END_NAMESPACE
-#include "moc_qtgradientstopswidget.cpp"
+#include "qtgradientstopswidget.moc"