]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
Qt: fix selection of dropdown-menu of playlist view mode
[vlc] / modules / gui / qt4 / components / interface_widgets.hpp
1 /*****************************************************************************
2  * interface_widgets.hpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006-2008 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Clément Stenac <zorglub@videolan.org>
8  *          Jean-Baptiste Kempf <jb@videolan.org>
9  *          Rafaël Carré <funman@videolanorg>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24  *****************************************************************************/
25
26 #ifndef _INTFWIDGETS_H_
27 #define _INTFWIDGETS_H_
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include "main_interface.hpp" /* Interface integration */
34 #include "input_manager.hpp"  /* Speed control */
35
36 #include "components/controller.hpp"
37 #include "components/controller_widget.hpp"
38 #include "dialogs_provider.hpp"
39 #include "components/info_panels.hpp"
40
41 #include <QWidget>
42 #include <QFrame>
43 #include <QLabel>
44 #include <QMouseEvent>
45
46 class ResizeEvent;
47 class QPixmap;
48 class QHBoxLayout;
49 class QMenu;
50 class QSlider;
51
52 /******************** Video Widget ****************/
53 class VideoWidget : public QFrame
54 {
55     Q_OBJECT
56 public:
57     VideoWidget( intf_thread_t * );
58     virtual ~VideoWidget();
59
60     WId request( int *, int *, unsigned int *, unsigned int *, bool );
61     void  release( void );
62     int   control( void *, int, va_list );
63     void  sync( void );
64
65 protected:
66     virtual QPaintEngine *paintEngine() const
67     {
68         return NULL;
69     }
70
71 private:
72     intf_thread_t *p_intf;
73
74     QWidget *stable;
75     QLayout *layout;
76 signals:
77     void sizeChanged( int, int );
78
79 public slots:
80     void SetSizing( unsigned int, unsigned int );
81 };
82
83 /******************** Background Widget ****************/
84 class BackgroundWidget : public QWidget
85 {
86     Q_OBJECT
87 public:
88     BackgroundWidget( intf_thread_t * );
89     void setExpandstoHeight( bool b_expand ) { b_expandPixmap = b_expand; }
90     void setWithArt( bool b_withart_ ) { b_withart = b_withart_; };
91 private:
92     intf_thread_t *p_intf;
93     QString pixmapUrl;
94     bool b_expandPixmap;
95     bool b_withart;
96     virtual void contextMenuEvent( QContextMenuEvent *event );
97 protected:
98     void paintEvent( QPaintEvent *e );
99     static const int MARGIN = 5;
100 public slots:
101     void toggle(){ TOGGLEV( this ); }
102     void updateArt( const QString& );
103 };
104
105 #if 0
106 class VisualSelector : public QFrame
107 {
108     Q_OBJECT
109 public:
110     VisualSelector( intf_thread_t *);
111     virtual ~VisualSelector();
112 private:
113     intf_thread_t *p_intf;
114     QLabel *current;
115 private slots:
116     void prev();
117     void next();
118 };
119 #endif
120
121 class ClickableQLabel : public QLabel
122 {
123     Q_OBJECT
124 public:
125     virtual void mouseDoubleClickEvent( QMouseEvent *event )
126     {
127         Q_UNUSED( event );
128         emit doubleClicked();
129     }
130 signals:
131     void doubleClicked();
132 };
133
134 class TimeLabel : public ClickableQLabel
135 {
136     Q_OBJECT
137 public:
138     enum Display
139     {
140         Elapsed,
141         Remaining,
142         Both
143     };
144
145     TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType = TimeLabel::Both );
146 protected:
147     virtual void mousePressEvent( QMouseEvent *event )
148     {
149         if( displayType == TimeLabel::Elapsed ) return;
150         toggleTimeDisplay();
151         event->accept();
152     }
153     virtual void mouseDoubleClickEvent( QMouseEvent *event )
154     {
155         if( displayType != TimeLabel::Both ) return;
156         event->accept();
157         toggleTimeDisplay();
158         ClickableQLabel::mouseDoubleClickEvent( event );
159     }
160 private:
161     intf_thread_t *p_intf;
162     bool b_remainingTime;
163     int cachedLength;
164     QTimer *bufTimer;
165
166     bool buffering;
167     bool showBuffering;
168     float bufVal;
169     TimeLabel::Display displayType;
170
171     char psz_length[MSTRTIME_MAX_SIZE];
172     char psz_time[MSTRTIME_MAX_SIZE];
173     void toggleTimeDisplay();
174     void paintEvent( QPaintEvent* );
175 private slots:
176     void setDisplayPosition( float pos, int64_t time, int length );
177     void setDisplayPosition( float pos );
178     void updateBuffering( float );
179     void updateBuffering();
180 };
181
182 class SpeedLabel : public QLabel
183 {
184     Q_OBJECT
185 public:
186     SpeedLabel( intf_thread_t *, QWidget * );
187     virtual ~SpeedLabel();
188
189 protected:
190     virtual void mousePressEvent ( QMouseEvent * event )
191     {
192         showSpeedMenu( event->pos() );
193     }
194 private slots:
195     void showSpeedMenu( QPoint );
196     void setRate( float );
197 private:
198     intf_thread_t *p_intf;
199     QMenu *speedControlMenu;
200     QString tooltipStringPattern;
201     SpeedControlWidget *speedControl;
202 };
203
204 /******************** Speed Control Widgets ****************/
205 class SpeedControlWidget : public QFrame
206 {
207     Q_OBJECT
208 public:
209     SpeedControlWidget( intf_thread_t *, QWidget * );
210     void updateControls( float );
211 private:
212     intf_thread_t* p_intf;
213     QSlider* speedSlider;
214     QDoubleSpinBox* spinBox;
215     int lastValue;
216
217 public slots:
218     void activateOnState();
219
220 private slots:
221     void updateRate( int );
222     void updateSpinBoxRate( double );
223     void resetRate();
224 };
225
226 class CoverArtLabel : public QLabel
227 {
228     Q_OBJECT
229 public:
230     CoverArtLabel( QWidget *parent, intf_thread_t * );
231     virtual ~CoverArtLabel();
232
233 protected:
234     virtual void mouseDoubleClickEvent( QMouseEvent *event )
235     {
236         if( qobject_cast<MetaPanel *>(this->window()) == NULL )
237         {
238             THEDP->mediaInfoDialog();
239         }
240         event->accept();
241     }
242 private:
243     intf_thread_t *p_intf;
244
245 public slots:
246     void requestUpdate() { emit updateRequested(); }
247     void update( )
248     {
249         requestUpdate();
250     }
251     void showArtUpdate( const QString& );
252
253 private slots:
254     void askForUpdate();
255
256 signals:
257     void updateRequested();
258 };
259
260 #endif