1 /*****************************************************************************
2 * customwidgets.hpp: Custom widgets
3 ****************************************************************************
4 * Copyright (C) 2006 the VideoLAN team
5 * Copyright (C) 2004 Daniel Molkentin <molkentin@kde.org>
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
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.
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.
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 *****************************************************************************/
27 #ifndef _CUSTOMWIDGETS_H_
28 #define _CUSTOMWIDGETS_H_
31 #include <QPushButton>
33 #include <QStackedWidget>
37 #include <QToolButton>
41 class QFramelessButton : public QPushButton
45 QFramelessButton( QWidget *parent = NULL );
46 virtual QSize sizeHint() const { return iconSize(); }
48 virtual void paintEvent( QPaintEvent * event );
51 class QToolButtonExt : public QToolButton
55 QToolButtonExt( QWidget *parent = 0, int ms = 0 );
67 class QElidingLabel : public QLabel
70 QElidingLabel( const QString &s = QString(),
71 Qt::TextElideMode mode = Qt::ElideRight,
72 QWidget * parent = NULL );
73 void setElideMode( Qt::TextElideMode );
75 virtual void paintEvent( QPaintEvent * event );
77 Qt::TextElideMode elideMode;
81 class QVLCStackedWidget : public QStackedWidget
84 QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
85 QSize minimumSizeHint () const
87 return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
91 class QVLCDebugLevelSpinBox : public QSpinBox
95 QVLCDebugLevelSpinBox( QWidget *parent ) : QSpinBox( parent ) { };
97 virtual QString textFromValue( int ) const;
98 /* QVLCDebugLevelSpinBox is read-only */
99 virtual int valueFromText( const QString& ) const { return -1; }
102 class AnimatedIcon : public QLabel
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
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
118 /** Create an empty AnimatedIcon */
119 AnimatedIcon( QWidget *parent );
120 virtual ~AnimatedIcon();
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.
127 void addFrame( const QPixmap &pixmap, int index = -1 );
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
136 void play( int loops = 1, int interval = 200 );
138 /** Stop playback. Same as play(0). */
144 /** Is the animation currently running? */
145 inline bool isPlaying()
147 return mTimer.isActive();
153 QList<QPixmap*> mFrames; // Keeps deep copies of all the frames
154 int mCurrentFrame, mRemainingLoops;
157 /** Slot connected to the timeout() signal of our internal timer */
161 class SpinningIcon : public AnimatedIcon
163 /** This spinning icon, to the colors of the VLC cone, will show
164 * that there is some background activity running
170 SpinningIcon( QWidget *parent, bool noIdleFrame = false );
173 /* VLC Key/Wheel hotkeys interactions */
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 );