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