1 /* This file is part of the KDE project
2    Copyright (c) 2007 C. Boemann <cbo@boemann.dk>
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Library General Public
6    License as published by the Free Software Foundation; either
7    version 2 of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Library General Public License for more details.
13 
14    You should have received a copy of the GNU Library General Public License
15    along with this library; see the file COPYING.LIB.  If not, write to
16    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18 */
19 #ifndef KoSliderCombo_p_h
20 #define KoSliderCombo_p_h
21 
22 #include "KoSliderCombo.h"
23 
24 #include <QTimer>
25 #include <QApplication>
26 #include <QSize>
27 #include <QSlider>
28 #include <QStyle>
29 #include <QStylePainter>
30 #include <QStyleOptionSlider>
31 #include <QLineEdit>
32 #include <QValidator>
33 #include <QHBoxLayout>
34 #include <QFrame>
35 #include <QMenu>
36 #include <QMouseEvent>
37 #include <QDoubleSpinBox>
38 #include <QDesktopWidget>
39 
40 #include <klocalizedstring.h>
41 #include <WidgetsDebug.h>
42 
43 class KoSliderComboContainer : public QMenu
44 {
45 public:
KoSliderComboContainer(KoSliderCombo * parent)46     KoSliderComboContainer(KoSliderCombo *parent) : QMenu(parent ), m_parent(parent) {}
47 
48 protected:
49     void mousePressEvent(QMouseEvent *e) override;
50 private:
51     KoSliderCombo *m_parent;
52 };
53 
mousePressEvent(QMouseEvent * e)54 void KoSliderComboContainer::mousePressEvent(QMouseEvent *e)
55 {
56     QStyleOptionComboBox opt;
57     opt.init(m_parent);
58     opt.subControls = QStyle::SC_All;
59     opt.activeSubControls = QStyle::SC_ComboBoxArrow;
60     QStyle::SubControl sc = style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt,
61                                                            m_parent->mapFromGlobal(e->globalPos()),
62                                                            m_parent);
63     if (sc == QStyle::SC_ComboBoxArrow)
64         setAttribute(Qt::WA_NoMouseReplay);
65     QMenu::mousePressEvent(e);
66 }
67 
68 class Q_DECL_HIDDEN KoSliderCombo::KoSliderComboPrivate {
69 public:
70     KoSliderCombo *thePublic;
71     QValidator *m_validator;
72     QTimer m_timer;
73     KoSliderComboContainer *container;
74     QSlider *slider;
75     QStyle::StateFlag arrowState;
76     qreal minimum;
77     qreal maximum;
78     int decimals;
79     bool firstShowOfSlider;
80 
81     void showPopup();
82     void hidePopup();
83 
84     void sliderValueChanged(int value);
85     void sliderReleased();
86     void lineEditFinished();
87 };
88 
89 #endif
90