1 /*
2  * Pixmap Dial, a custom Qt4 widget
3  * Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of
8  * the License, or any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * For a full copy of the GNU General Public License see the COPYING file
16  */
17 
18 #ifndef __PIXMAPDIAL_HPP__
19 #define __PIXMAPDIAL_HPP__
20 
21 #include <QtGui/QPixmap>
22 #include <QtWidgets/QDial>
23 
24 class PixmapDial : public QDial
25 {
26 public:
27     enum CustomPaint {
28         CUSTOM_PAINT_NULL      = 0,
29         CUSTOM_PAINT_CARLA_WET = 1,
30         CUSTOM_PAINT_CARLA_VOL = 2,
31         CUSTOM_PAINT_CARLA_L   = 3,
32         CUSTOM_PAINT_CARLA_R   = 4
33     };
34 
35     PixmapDial(QWidget* parent);
36 
37     int  getSize() const;
38     void setCustomPaint(CustomPaint paint);
39     void setEnabled(bool enabled);
40     void setLabel(QString label);
41     void setPixmap(int pixmapId);
42 
43     QSize minimumSizeHint() const;
44     QSize sizeHint() const;
45 
46 protected:
47     void updateSizes();
48 
49     void enterEvent(QEvent* event);
50     void leaveEvent(QEvent* event);
51     void paintEvent(QPaintEvent* event);
52     void resizeEvent(QResizeEvent* event);
53 
54 private:
55     enum Orientation {
56         HORIZONTAL = 0,
57         VERTICAL   = 1
58     };
59 
60     static const unsigned short HOVER_MIN = 0;
61     static const unsigned short HOVER_MAX = 9;
62 
63     // -------------------------------------
64 
65     QPixmap fPixmap;
66     QString fPixmapNum;
67 
68     CustomPaint fCustomPaint;
69     Orientation fOrientation;
70 
71     bool fHovered;
72     unsigned short fHoverStep;
73 
74     QString fLabel;
75     QPointF fLabelPos;
76     QFont   fLabelFont;
77     int     fLabelWidth;
78     int     fLabelHeight;
79 
80     QLinearGradient fLabelGradient;
81     QRectF fLabelGradientRect;
82 
83     QColor fColor1;
84     QColor fColor2;
85     QColor fColorT[2];
86 
87     int fWidth, fHeight, fSize, fCount;
88 };
89 
90 #endif // __PIXMAPDIAL_HPP__
91