1 /*****************************************************************************
2 * customwidgets.h: 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>
39 class QVLCFramelessButton : public QPushButton
43 QVLCFramelessButton( QWidget *parent = NULL );
44 virtual QSize sizeHint() const { return iconSize(); }
46 virtual void paintEvent( QPaintEvent * event );
50 class QVLCElidingLabel : public QLabel
53 QVLCElidingLabel( const QString &s = QString(),
54 Qt::TextElideMode mode = Qt::ElideRight,
55 QWidget * parent = NULL );
56 void setElideMode( Qt::TextElideMode );
58 virtual void paintEvent( QPaintEvent * event );
60 Qt::TextElideMode elideMode;
64 class QVLCStackedWidget : public QStackedWidget
67 QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
68 QSize minimumSizeHint () const
70 return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
74 class DebugLevelSpinBox : public QSpinBox
78 DebugLevelSpinBox( QWidget *parent ) : QSpinBox( parent ) { };
80 virtual QString textFromValue( int ) const;
81 /* DebugLevelSpinBox is read-only */
82 virtual int valueFromText( const QString& ) const { return -1; }
85 class AnimatedIcon : public QLabel
87 /** An animated pixmap
88 * Use this widget to display an animated icon based on a series of
89 * pixmaps. The pixmaps will be stored in memory and should be kept small.
90 * First, create the widget, add frames and then start playing. Looping
92 * Frames #1 to #n are displayed at regular intervals when playing.
93 * Frame #0 is the idle frame, displayed when the icon is not animated.
94 * If not #0 frame has been specified, the last frame will be shown when
101 /** Create an empty AnimatedIcon */
102 AnimatedIcon( QWidget *parent );
103 virtual ~AnimatedIcon();
105 /** Adds a frame to play in the loop.
106 * @param pixmap The QPixmap to display. Data will be copied internally.
107 * @param index If -1, append the frame. If 0, replace the idle frame.
108 * Otherwise, insert the frame at the given position.
110 void addFrame( const QPixmap &pixmap, int index = -1 );
112 /** Play the animation (or restart it)
113 * @param loops Number of times to play the loop. 0 means stop, while -1
114 * means play forever. When stopped, the frame #0 will be
115 * displayed until play() is called again.
116 * @param interval Delay between frames, in milliseconds (minimum 20ms)
117 * @note If isPlaying() is true, then restart the animation from frame #1
119 void play( int loops = 1, int interval = 200 );
121 /** Stop playback. Same as play(0). */
127 /** Is the animation currently running? */
128 inline bool isPlaying()
130 return mTimer.isActive();
136 QList<QPixmap*> mFrames; // Keeps deep copies of all the frames
137 int mCurrentFrame, mRemainingLoops;
140 /** Slot connected to the timeout() signal of our internal timer */
144 class SpinningIcon : public AnimatedIcon
146 /** This spinning icon, to the colors of the VLC cone, will show
147 * that there is some background activity running
153 SpinningIcon( QWidget *parent, bool noIdleFrame = false );
154 virtual ~SpinningIcon();
157 /* VLC Key/Wheel hotkeys interactions */
163 int qtKeyModifiersToVLC( QInputEvent* e );
164 int qtEventToVLCKey( QKeyEvent *e );
165 int qtWheelEventToVLCKey( QWheelEvent *e );
166 QString VLCKeyToString( int val );