]> git.sesse.net Git - vlc/blob - modules/gui/qt4/util/customwidgets.hpp
Qt: PixmapAnimator: fix wrong iterator bound
[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 <QCheckBox>
36 #include <QList>
37 #include <QTimer>
38 #include <QToolButton>
39 #include <QAbstractAnimation>
40
41 class QPixmap;
42 class QWidget;
43
44 class QFramelessButton : public QPushButton
45 {
46     Q_OBJECT
47 public:
48     QFramelessButton( QWidget *parent = NULL );
49     virtual QSize sizeHint() const { return iconSize(); }
50 protected:
51     virtual void paintEvent( QPaintEvent * event );
52 };
53
54 class QToolButtonExt : public QToolButton
55 {
56     Q_OBJECT
57 public:
58     QToolButtonExt( QWidget *parent = 0, int ms = 0 );
59 private:
60     bool shortClick;
61     bool longClick;
62 private slots:
63     void releasedSlot();
64     void clickedSlot();
65 signals:
66     void shortClicked();
67     void longClicked();
68 };
69
70 class QElidingLabel : public QLabel
71 {
72 public:
73     QElidingLabel( const QString &s = QString(),
74                       Qt::TextElideMode mode = Qt::ElideRight,
75                       QWidget * parent = NULL );
76     void setElideMode( Qt::TextElideMode );
77 protected:
78     virtual void paintEvent( QPaintEvent * event );
79 private:
80     Qt::TextElideMode elideMode;
81 };
82
83
84 class QVLCStackedWidget : public QStackedWidget
85 {
86 public:
87     QVLCStackedWidget( QWidget *parent ) : QStackedWidget( parent ) { }
88     QSize minimumSizeHint () const
89     {
90         return currentWidget() ? currentWidget()->minimumSizeHint() : QSize();
91     }
92 };
93
94 class QVLCDebugLevelSpinBox : public QSpinBox
95 {
96     Q_OBJECT
97 public:
98     QVLCDebugLevelSpinBox( QWidget *parent ) : QSpinBox( parent ) { };
99 protected:
100     virtual QString textFromValue( int ) const;
101     /* QVLCDebugLevelSpinBox is read-only */
102     virtual int valueFromText( const QString& ) const { return -1; }
103 };
104
105 /** An animated pixmap
106      * Use this widget to display an animated icon based on a series of
107      * pixmaps. The pixmaps will be stored in memory and should be kept small.
108      * First, create the widget, add frames and then start playing. Looping
109      * is supported.
110      **/
111 class PixmapAnimator : public QAbstractAnimation
112 {
113     Q_OBJECT
114
115 public:
116     PixmapAnimator( QWidget *parent, QList<QString> _frames );
117     void setFps( int _fps ) { fps = _fps; interval = 1000.0 / fps; };
118     virtual int duration() const { return interval * pixmaps.count(); };
119     virtual ~PixmapAnimator() { qDeleteAll( pixmaps ); };
120     QPixmap *getPixmap() { return currentPixmap; }
121 protected:
122     virtual void updateCurrentTime ( int msecs );
123     QList<QPixmap *> pixmaps;
124     QPixmap *currentPixmap;
125     int fps;
126     int interval;
127     int lastframe_msecs;
128     int current_frame;
129 signals:
130     void pixmapReady( const QPixmap & );
131 };
132
133 /** This spinning icon, to the colors of the VLC cone, will show
134  * that there is some background activity running
135  **/
136 class SpinningIcon : public QLabel
137 {
138     Q_OBJECT
139
140 public:
141     SpinningIcon( QWidget *parent );
142     void play( int loops = -1, int fps = 0 )
143     {
144         animator->setLoopCount( loops );
145         if ( fps ) animator->setFps( fps );
146         animator->start();
147     }
148     void stop() { animator->stop(); }
149     bool isPlaying() { return animator->state() == PixmapAnimator::Running; }
150 private:
151     PixmapAnimator *animator;
152 };
153
154 class YesNoCheckBox : public QCheckBox
155 {
156     Q_OBJECT
157 public:
158     YesNoCheckBox( QWidget *parent );
159 };
160
161 /* VLC Key/Wheel hotkeys interactions */
162
163 class QKeyEvent;
164 class QWheelEvent;
165 class QInputEvent;
166
167 int qtKeyModifiersToVLC( QInputEvent* e );
168 int qtEventToVLCKey( QKeyEvent *e );
169 int qtWheelEventToVLCKey( QWheelEvent *e );
170 QString VLCKeyToString( unsigned val );
171
172 #endif