digiKam
dgradientslider.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-07-03
7  * Description : a color gradient slider
8  *
9  * Copyright (C) 2008-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
10  * Copyright (C) 2008 by Cyrille Berger <cberger at cberger dot net>
11  *
12  * This program is free software; you can redistribute it
13  * and/or modify it under the terms of the GNU General
14  * Public License as published by the Free Software Foundation;
15  * either version 2, or (at your option)
16  * any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * ============================================================ */
24 
25 #ifndef DIGIKAM_DGRADIENT_SLIDER_H
26 #define DIGIKAM_DGRADIENT_SLIDER_H
27 
28 // Qt includes
29 
30 #include <QWidget>
31 #include <QColor>
32 
33 // Local includes
34 
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class DIGIKAM_EXPORT DGradientSlider : public QWidget
41 {
42  Q_OBJECT
43 
44 public:
45 
46  explicit DGradientSlider(QWidget* const parent = nullptr);
47  ~DGradientSlider() override;
48 
49  void showMiddleCursor(bool b);
50  double leftValue() const;
51  double rightValue() const;
52  double middleValue() const;
53  int gradientOffset() const;
54 
55  void setColors(const QColor& lcolor,
56  const QColor& rcolor);
57 
58 public Q_SLOTS:
59 
60  void setLeftValue(double);
61  void setRightValue(double);
62  void setMiddleValue(double);
63 
64 Q_SIGNALS:
65 
66  void leftValueChanged(double);
67  void rightValueChanged(double);
68  void middleValueChanged(double);
69 
70 protected:
71 
72  void paintEvent(QPaintEvent*) override;
73  void mousePressEvent(QMouseEvent*) override;
74  void mouseReleaseEvent(QMouseEvent*) override;
75  void mouseMoveEvent(QMouseEvent*) override;
76  void leaveEvent(QEvent*) override;
77 
78 private:
79 
80  void adjustMiddleValue(double newLeftValue,
81  double newRightValue);
82  inline void drawCursorAt(QPainter& painter,
83  double pos,
84  const QColor& brushColor,
85  int width,
86  int height,
87  int gradientWidth);
88 
89 private:
90 
91  class Private;
92  Private* const d;
93 };
94 
95 } // namespace Digikam
96 
97 #endif // DIGIKAM_DGRADIENT_SLIDER_H
Definition: dgradientslider.h:41
void leftValueChanged(double)
void rightValueChanged(double)
void middleValueChanged(double)
Definition: datefolderview.cpp:43