1 /*
2  *  spinbox2_p.h  -  private classes for SpinBox2
3  *  Program:  kalarm
4  *  SPDX-FileCopyrightText: 2005-2021 David Jarvie <djarvie@kde.org>
5  *
6  *  SPDX-License-Identifier: GPL-2.0-or-later
7  */
8 
9 #pragma once
10 
11 #include "spinbox.h"
12 
13 #include <QGraphicsView>
14 class QMouseEvent;
15 class QPaintEvent;
16 
17 
18 /*=============================================================================
19 = Class ExtraSpinBox
20 * Extra pair of spin buttons for SpinBox2.
21 * The widget is actually a whole spin box, but only the buttons are displayed.
22 =============================================================================*/
23 
24 class ExtraSpinBox : public SpinBox
25 {
26     Q_OBJECT
27 public:
ExtraSpinBox(QWidget * parent)28     explicit ExtraSpinBox(QWidget* parent)
29                  : SpinBox(parent), mInhibitPaintSignal(0) { }
ExtraSpinBox(int minValue,int maxValue,QWidget * parent)30     ExtraSpinBox(int minValue, int maxValue, QWidget* parent)
31                  : SpinBox(minValue, maxValue, parent), mInhibitPaintSignal(0) { }
inhibitPaintSignal(int i)32     void inhibitPaintSignal(int i)  { mInhibitPaintSignal = i; }
33 
34 Q_SIGNALS:
35     void painted();
36 
37 protected:
38     void paintEvent(QPaintEvent*) override;
39 
40 private:
41     int  mInhibitPaintSignal;
42 };
43 
44 
45 /*=============================================================================
46 = Class SpinMirror
47 * Displays the left-to-right mirror image of a pair of spin buttons, for use
48 * as the extra spin buttons in a SpinBox2. All mouse clicks are passed on to
49 * the real extra pair of spin buttons for processing.
50 * Mirroring in this way allows styles with rounded corners to display correctly.
51 =============================================================================*/
52 
53 class SpinMirror : public QGraphicsView
54 {
55     Q_OBJECT
56 public:
57     explicit SpinMirror(ExtraSpinBox*, SpinBox*, QWidget* parent = nullptr);
setReadOnly(bool ro)58     void    setReadOnly(bool ro)        { mReadOnly = ro; }
isReadOnly()59     bool    isReadOnly() const          { return mReadOnly; }
60     void    setFrameImage();
61     void    setButtonsImage();
62     void    setButtonPos(const QPoint&);
63     void    rearrange();
64 
65 protected:
66     bool    event(QEvent*) override;
67     void    resizeEvent(QResizeEvent*) override;
mousePressEvent(QMouseEvent * e)68     void    mousePressEvent(QMouseEvent* e) override        { mouseEvent(e); }
mouseReleaseEvent(QMouseEvent * e)69     void    mouseReleaseEvent(QMouseEvent* e) override      { mouseEvent(e); }
mouseMoveEvent(QMouseEvent * e)70     void    mouseMoveEvent(QMouseEvent* e) override         { mouseEvent(e); }
mouseDoubleClickEvent(QMouseEvent * e)71     void    mouseDoubleClickEvent(QMouseEvent* e) override  { mouseEvent(e); }
72     void    wheelEvent(QWheelEvent*) override;
73 
74 private:
75     void    mouseEvent(QMouseEvent*);
76     void    setMirroredState(bool clear = false);
77     QPointF spinboxPoint(const QPointF&) const;
78 
79     ExtraSpinBox*        mSpinbox;    // spinbox whose spin buttons are being mirrored
80     SpinBox*             mMainSpinbox;
81     QGraphicsPixmapItem* mButtons;    // image of spin buttons
82     bool                 mReadOnly;   // value cannot be changed
83     bool                 mMirrored;   // mirror left-to-right
84 };
85 
86 // vim: et sw=4:
87