]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/customwidgets.hpp
Qt: handle special mouse buttons
[vlc] / modules / gui / qt4 / util / customwidgets.hpp
1 /*****************************************************************************
2  * customwidgets.hpp: Custom widgets
3  ****************************************************************************
4  * Copyright (C) 2006 the VideoLAN team
5  * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
6  * $Id$
7  *
8  * Authors: ClĂ©ment Stenac <zorglub@videolan.org>
9  * The "ClickLineEdit" control is based on code by  Daniel Molkentin
10  * <molkentin@kde.org> for libkdepim
11  *
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25  *****************************************************************************/
26
27 #ifndef _CUSTOMWIDGETS_H_
28 #define _CUSTOMWIDGETS_H_
29
30 #include <QLineEdit>
31 #include <QPushButton>
32 #include <QLabel>
33 #include <QStackedWidget>
34 #include <QSpinBox>
35 #include <QList>
36 #include <QTimer>
37 #include <QToolButton>
38
39 class QPixmap;
40
41 class QFramelessButton : public QPushButton
42 {
43     Q_OBJECT
44 public:
45     QFramelessButton( QWidget *parent = NULL );
46     virtual QSize sizeHint() const { return iconSize(); }
47 protected:
48     virtual void paintEvent( QPaintEvent * event );
49 };
50
51 class QToolButtonExt : public QToolButton
52 {
53     Q_OBJECT
54 public:
55     QToolButtonExt( QWidget *parent = 0, int ms = 0 );
56 private:
57     bool shortClick;
58     bool longClick;
59 private slots:
60     void releasedSlot();
61     void clickedSlot();
62 signals:
63     void shortClicked();
64     void longClicked();
65 };
66
67 class QElidingLabel : public QLabel
68 {
69 public:
70     QElidingLabel( const QString &s = QString(),
71                       Qt::TextElideMode mode = Qt::ElideRight,
72                       QWidget * parent = NULL );
73     void setElideMode( Qt::TextElideMode );
74 protected:
75     virtual void paintEvent( QPaintEvent * event );
76 private:
77     Qt::TextElideMode elideMode;
78 };
79
80
81 class QVLCStackedWidget : public QStackedWidget
82 {
83 public:
84     QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
85     QSize minimumSizeHint () const
86     {
87         return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
88     }
89 };
90
91 class QVLCDebugLevelSpinBox : public QSpinBox
92 {
93     Q_OBJECT
94 public:
95     QVLCDebugLevelSpinBox( QWidget *parent ) : QSpinBox( parent ) { };
96 protected:
97     virtual QString textFromValue( int ) const;
98     /* QVLCDebugLevelSpinBox is read-only */
99     virtual int valueFromText( const QString& ) const { return -1; }
100 };
101
102 class AnimatedIcon : public QLabel
103 {
104     /** An animated pixmap
105      * Use this widget to display an animated icon based on a series of
106      * pixmaps. The pixmaps will be stored in memory and should be kept small.
107      * First, create the widget, add frames and then start playing. Looping
108      * is supported.
109      * Frames #1 to #n are displayed at regular intervals when playing.
110      * Frame #0 is the idle frame, displayed when the icon is not animated.
111      * If not #0 frame has been specified, the last frame will be shown when
112      * idle.
113      **/
114
115     Q_OBJECT
116
117 public:
118     /** Create an empty AnimatedIcon */
119     AnimatedIcon( QWidget *parent );
120     virtual ~AnimatedIcon();
121
122     /** Adds a frame to play in the loop.
123      * @param pixmap The QPixmap to display. Data will be copied internally.
124      * @param index If -1, append the frame. If 0, replace the idle frame.
125      *              Otherwise, insert the frame at the given position.
126      **/
127     void addFrame( const QPixmap &pixmap, int index = -1 );
128
129     /** Play the animation (or restart it)
130      * @param loops Number of times to play the loop. 0 means stop, while -1
131      *              means play forever. When stopped, the frame #0 will be
132      *              displayed until play() is called again.
133      * @param interval Delay between frames, in milliseconds (minimum 20ms)
134      * @note If isPlaying() is true, then restart the animation from frame #1
135      **/
136     void play( int loops = 1, int interval = 200 );
137
138     /** Stop playback. Same as play(0). */
139     inline void stop()
140     {
141         play( 0 );
142     }
143
144     /** Is the animation currently running? */
145     inline bool isPlaying()
146     {
147         return mTimer.isActive();
148     }
149
150 private:
151     QTimer mTimer;
152     QPixmap *mIdleFrame;
153     QList<QPixmap*> mFrames; // Keeps deep copies of all the frames
154     int mCurrentFrame, mRemainingLoops;
155
156 private slots:
157     /** Slot connected to the timeout() signal of our internal timer */
158     void onTimerTick();
159 };
160
161 class SpinningIcon : public AnimatedIcon
162 {
163     /** This spinning icon, to the colors of the VLC cone, will show
164      * that there is some background activity running
165      **/
166
167     Q_OBJECT
168
169 public:
170     SpinningIcon( QWidget *parent, bool noIdleFrame = false );
171 };
172
173 /* VLC Key/Wheel hotkeys interactions */
174
175 class QKeyEvent;
176 class QWheelEvent;
177 class QInputEvent;
178
179 int qtKeyModifiersToVLC( QInputEvent* e );
180 int qtEventToVLCKey( QKeyEvent *e );
181 int qtWheelEventToVLCKey( QWheelEvent *e );
182 int qtMouseEventToVLCKey( QMouseEvent *e );
183 QString VLCKeyToString( unsigned val );
184
185 #endif