File indexing completed on 2024-12-22 04:13:07

0001 /*
0002  *  SPDX-FileCopyrightText: 2004 Cyrille Berger <cberger@cberger.net>
0003  *  SPDX-FileCopyrightText: 2016 Sven Langkamp <sven.langkamp@gmail.com>
0004  *
0005  *  SPDX-License-Identifier: GPL-2.0-or-later
0006  */
0007 
0008 #ifndef _KIS_STOP_GRADIENT_SLIDER_H_
0009 #define _KIS_STOP_GRADIENT_SLIDER_H_
0010 
0011 #include <QWidget>
0012 #include <QScopedPointer>
0013 
0014 #include <KoStopGradient.h>
0015 #include <kis_signal_compressor.h>
0016 
0017 class QEvent;
0018 class QMouseEvent;
0019 class QKeyEvent;
0020 
0021 class KisStopGradientSlider : public QWidget
0022 {
0023     Q_OBJECT
0024 
0025 public:
0026     KisStopGradientSlider(QWidget *parent = 0, Qt::WindowFlags f = Qt::WindowFlags());
0027 
0028     int selectedStop();
0029 
0030     QSize sizeHint() const override;
0031     QSize minimumSizeHint() const override;
0032 
0033 public Q_SLOTS:
0034     void setGradientResource(KoStopGradientSP gradient);
0035     void setSelectedStop(int selected);
0036     void selectPreviousStop();
0037     void selectNextStop();
0038     void deleteSelectedStop(bool selectNeighborStop = true);
0039     void chooseSelectedStopColor();
0040 
0041 Q_SIGNALS:
0042     void sigSelectedStop(int stop);
0043     void updateRequested();
0044 
0045 protected:
0046     void paintEvent(QPaintEvent *) override;
0047     void mousePressEvent(QMouseEvent *e) override;
0048     void mouseReleaseEvent(QMouseEvent *e) override;
0049     void mouseMoveEvent(QMouseEvent *e) override;
0050     void mouseDoubleClickEvent(QMouseEvent *e) override;
0051     void wheelEvent(QWheelEvent *e) override;
0052     void keyPressEvent(QKeyEvent *e) override;
0053     void leaveEvent(QEvent *e) override;
0054 
0055 private Q_SLOTS:
0056     void updateHandleSize();
0057 
0058 private:
0059     void insertStop(double t);
0060 
0061     QRect sliderRect() const;
0062     QRect gradientStripeRect() const;
0063     QRect handlesStripeRect() const;
0064     QRegion allowedClickRegion(int tolerance) const;
0065 
0066     void updateHoveredStop(const QPoint &pos);
0067     int handleClickTolerance() const;
0068     void handleIncrementInput(int direction, Qt::KeyboardModifiers modifiers);
0069     int minimalHeight() const;
0070 
0071 private:
0072     static constexpr int removeStopDistance{32};
0073 
0074     KoStopGradientSP m_defaultGradient;
0075     KoStopGradientSP m_gradient;
0076     int m_selectedStop;
0077     int m_hoveredStop;
0078     KoGradientStop m_removedStop;
0079     bool m_drag;
0080     QSize m_handleSize;
0081     KisSignalCompressor m_updateCompressor;
0082 };
0083 
0084 #endif