Phonon

swiftslider.cpp
1/* This file is part of the KDE project
2 Copyright (C) 2006-2008 Ricardo Villalba <rvm@escomposlinux.org>
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) version 3, or any
8 later version accepted by the membership of KDE e.V. (or its
9 successor approved by the membership of KDE e.V.), Nokia Corporation
10 (or its successors, if any) and the KDE Free Qt Foundation, which shall
11 act as a proxy defined in Section 6 of version 3 of the license.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library. If not, see <http://www.gnu.org/licenses/>.
20
21*/
22
23#include "swiftslider_p.h"
24
25#include <QMouseEvent>
26#include <QStyle>
27#include <QStyleOption>
28
29#if !defined(QT_NO_PHONON_SEEKSLIDER) && !defined(QT_NO_PHONON_VOLUMESLIDER)
30
31namespace Phonon
32{
33
34SwiftSlider::SwiftSlider(Qt::Orientation orientation, QWidget * parent)
35 : QSlider(orientation, parent)
36 , m_wheelTimer(this)
37{
38 m_wheelTimer.setInterval(100);
39 m_wheelTimer.setSingleShot(true);
40 connect(&m_wheelTimer, SIGNAL(timeout()), this, SIGNAL(scrollEnd()));
41}
42
43SwiftSlider::~SwiftSlider()
44{
45}
46
47// Function copied from qslider.cpp
48inline int SwiftSlider::pick(const QPoint &pt) const
49{
50 return orientation() == Qt::Horizontal ? pt.x() : pt.y();
51}
52
53// Function copied from qslider.cpp and modified to make it compile
54int SwiftSlider::pixelPosToRangeValue(int pos) const
55{
57 initStyleOption(&opt);
58 QRect gr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
59 QRect sr = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
60 int sliderMin, sliderMax, sliderLength;
61
62 if (orientation() == Qt::Horizontal) {
63 sliderLength = sr.width();
64 sliderMin = gr.x();
65 sliderMax = gr.right() - sliderLength + 1;
66 } else {
67 sliderLength = sr.height();
68 sliderMin = gr.y();
69 sliderMax = gr.bottom() - sliderLength + 1;
70 }
71 return QStyle::sliderValueFromPosition(minimum(), maximum(), pos - sliderMin,
72 sliderMax - sliderMin, opt.upsideDown);
73}
74
75// Based on code from qslider.cpp
76void SwiftSlider::mousePressEvent(QMouseEvent *event)
77{
78 if (event->button() == Qt::LeftButton) {
80 initStyleOption(&opt);
81 const QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderHandle, this);
82 const QPoint center = sliderRect.center() - sliderRect.topLeft();
83 // to take half of the slider off for the setSliderPosition call we use the center - topLeft
84
85 if (!sliderRect.contains(event->pos())) {
86 event->accept();
87
88 setSliderPosition(pixelPosToRangeValue(pick(event->pos() - center)));
89 triggerAction(SliderMove);
90 setRepeatAction(SliderNoAction);
91 } else {
93 }
94 } else {
96 }
97}
98
99void SwiftSlider::wheelEvent(QWheelEvent *event)
100{
101 m_wheelTimer.start();
102 QSlider::wheelEvent(event);
103}
104
105} // namespace Phonon
106
107#endif //QT_NO_PHONON_VOLUMESLIDER && QT_NO_PHONON_VOLUMESLIDER
108
109#include "moc_swiftslider_p.cpp"
AKONADI_CALENDAR_EXPORT KCalendarCore::Event::Ptr event(const Akonadi::Item &item)
virtual void wheelEvent(QWheelEvent *e) override
int x() const const
int y() const const
int bottom() const const
QPoint center() const const
bool contains(const QPoint &point, bool proper) const const
int height() const const
int right() const const
QPoint topLeft() const const
int width() const const
int x() const const
int y() const const
virtual void mousePressEvent(QMouseEvent *ev) override
int sliderValueFromPosition(int min, int max, int position, int span, bool upsideDown)
LeftButton
Orientation
QTextStream & center(QTextStream &stream)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:53:28 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.