]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/directslider.hpp
qt4 - Mousewheel (2)
[vlc] / modules / gui / qt4 / util / directslider.hpp
1 /*****************************************************************************
2  * directslider.hpp : A slider that goes where you click
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * $Id$
6  *
7  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
8  *          with precious help from ahigerd on #qt@freenode
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. *****************************************************************************/
23
24 #ifndef _DIRECTSLIDER_H_
25 #define _DIRECTSLIDER_H_
26
27 #include <QSlider>
28 #include <QMouseEvent>
29 #include <QLayout>
30
31 class DirectSlider : public QSlider
32 {
33 public:
34     DirectSlider( QWidget *_parent ) : QSlider( _parent ) {};
35     DirectSlider( Qt::Orientation q,QWidget *_parent ) : QSlider( q,_parent )
36     {};
37     virtual ~DirectSlider()   {};
38
39     void mousePressEvent(QMouseEvent* event)
40     {
41         if(event->button() == Qt::LeftButton)
42         {
43 #ifdef WIN32
44             int width1 = qobject_cast<QWidget*>(parent())->sizeHint().width() -
45                      2 * qobject_cast<QWidget*>(parent())->layout()->margin();
46 #else
47             int width1 = width();
48 #endif
49             int pos = (int)(minimum() +
50                           (double)(event->x())/width1*(maximum()-minimum()) );
51             setValue( pos );
52             QSlider::mousePressEvent(event);
53         }
54     }
55 };
56 #endif