]> git.sesse.net Git - vlc/blob - modules/gui/qt4/components/interface_widgets.hpp
qt4: do not access a widget from another thread
[vlc] / modules / gui / qt4 / components / interface_widgets.hpp
1 /*****************************************************************************
2  * interface_widgets.hpp : Custom widgets for the main interface
3  ****************************************************************************
4  * Copyright (C) 2006 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 #include <vlc/vlc.h>
30 #include <vlc_interface.h>
31
32 #include <vlc_aout.h>
33 #include "qt4.hpp"
34
35 #include <QWidget>
36 #include <QFrame>
37 #define VOLUME_MAX 200
38
39 class ResizeEvent;
40 class QPalette;
41 class QPixmap;
42 class QLabel;
43 class QHBoxLayout;
44
45 /******************** Video Widget ****************/
46 class VideoWidget : public QFrame
47 {
48     Q_OBJECT
49 public:
50     VideoWidget( intf_thread_t * );
51     virtual ~VideoWidget();
52
53     void *request( vout_thread_t *, int *, int *,
54                    unsigned int *, unsigned int * );
55     void release( void * );
56     int control( void *, int, va_list );
57
58     int i_video_height, i_video_width;
59     vout_thread_t *p_vout;
60
61     QSize widgetSize;
62     virtual QSize sizeHint() const;
63 private:
64     QWidget *frame;
65     intf_thread_t *p_intf;
66     vlc_mutex_t lock;
67 signals:
68     void askResize();
69     void askVideoToShow();
70 private slots:
71     void SetMinSize();
72 };
73
74 /******************** Background Widget ****************/
75 class BackgroundWidget : public QFrame
76 {
77     Q_OBJECT
78 public:
79     BackgroundWidget( intf_thread_t * );
80     virtual ~BackgroundWidget();
81     QSize widgetSize;
82     virtual QSize sizeHint() const;
83 private:
84     QPalette plt;
85     QLabel *label;
86     QHBoxLayout *backgroundLayout;
87     virtual void resizeEvent( QResizeEvent *e );
88     virtual void contextMenuEvent( QContextMenuEvent *event );
89     int DrawBackground();
90     int CleanBackground();
91     intf_thread_t *p_intf;
92 public slots:
93     void setArt( QString );
94 };
95
96 class VisualSelector : public QFrame
97 {
98     Q_OBJECT
99 public:
100     VisualSelector( intf_thread_t *);
101     virtual ~VisualSelector();
102 private:
103     intf_thread_t *p_intf;
104     QLabel *current;
105 private slots:
106     void prev();
107     void next();
108 };
109
110 class QPushButton;
111 class AdvControlsWidget : public QFrame
112 {
113     Q_OBJECT
114 public:
115     AdvControlsWidget( intf_thread_t *);
116     virtual ~AdvControlsWidget();
117     void enableInput( bool );
118     void enableVideo( bool );
119 private:
120     intf_thread_t *p_intf;
121     QPushButton *normalButton, *recordButton, *ABButton;
122     QPushButton *snapshotButton, *frameButton;
123 private slots:
124     void normal();
125     void snapshot();
126     void frame();
127     void fromAtoB();
128     void record();
129 };
130
131
132
133 class InputSlider;
134 class QSlider;
135 class QGridLayout;
136 class VolumeClickHandler;
137 class ControlsWidget : public QFrame
138 {
139     Q_OBJECT
140 public:
141     ControlsWidget( intf_thread_t *, bool );
142     virtual ~ControlsWidget();
143
144     QPushButton *playlistButton;
145     QSlider *volumeSlider;
146     void setStatus( int );
147     void enableInput( bool );
148     void enableVideo( bool );
149 public slots:
150     void setNavigation( int );
151     void updateOnTimer();
152 protected:
153     friend class MainInterface;
154     friend class VolumeClickHandler;
155 private:
156     intf_thread_t       *p_intf;
157     QFrame              *discFrame;
158     QGridLayout         *controlLayout;
159     InputSlider         *slider;
160     QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
161     QPushButton         *playButton, *fullscreenButton;
162     QPushButton         *slowerButton, *fasterButton;
163     AdvControlsWidget   *advControls;
164     QLabel              *volMuteLabel;
165
166     bool                 b_advancedVisible;
167 private slots:
168     void play();
169     void stop();
170     void prev();
171     void next();
172     void updateVolume( int );
173     void fullscreen();
174     void extSettings();
175     void faster();
176     void slower();
177     void toggleAdvanced();
178 signals:
179     void advancedControlsToggled( bool );
180 };
181
182 class VolumeClickHandler : public QObject
183 {
184 public:
185     VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
186     {m = _m; p_intf = _p_intf; }
187     virtual ~VolumeClickHandler() {};
188     bool eventFilter( QObject *obj, QEvent *e )
189     {
190         if (e->type() == QEvent::MouseButtonPress  )
191         {
192             aout_VolumeMute( p_intf, NULL );
193             audio_volume_t i_volume;
194             aout_VolumeGet( p_intf, &i_volume );
195             m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
196             return true;
197         }
198         return false;
199     }
200 private:
201     ControlsWidget *m;
202     intf_thread_t *p_intf;
203 };
204
205 #include <QLabel>
206 #include <QMouseEvent>
207 class TimeLabel : public QLabel
208 {
209     Q_OBJECT
210     void mousePressEvent( QMouseEvent *event )
211     {
212         if( event->button() == Qt::LeftButton ) emit timeLabelClicked();
213     }
214     void mouseDoubleClickEvent( QMouseEvent *event )
215     {
216         emit timeLabelDoubleClicked();
217     }
218 signals:
219     void timeLabelClicked();
220     void timeLabelDoubleClicked();
221 };
222
223 /******************** Playlist Widgets ****************/
224 #include <QModelIndex>
225 #include <QSplitter>
226 class QSignalMapper;
227 class PLSelector;
228 class PLPanel;
229 class QPushButton;
230
231 class PlaylistWidget : public QSplitter
232 {
233     Q_OBJECT;
234 public:
235     PlaylistWidget( intf_thread_t *_p_i ) ;
236     virtual ~PlaylistWidget();
237     QSize widgetSize;
238     virtual QSize sizeHint() const;
239 private:
240     PLSelector *selector;
241     PLPanel *rightPanel;
242     QPushButton *addButton;
243     QLabel *art;
244     QString prevArt;
245 protected:
246      intf_thread_t *p_intf;
247 private slots:
248     void setArt( QString );
249 signals:
250     void rootChanged( int );
251     void artSet( QString );
252 };
253
254
255 /******************** Speed Control Widgets ****************/
256 class SpeedControlWidget : public QFrame
257 {
258     Q_OBJECT
259 public:
260     SpeedControlWidget( intf_thread_t *);
261     virtual ~SpeedControlWidget();
262     void updateControls( int );
263 private:
264     intf_thread_t *p_intf;
265     QSlider *speedSlider;
266     QPushButton *normalSpeedButton;
267 private slots:
268     void updateRate( int );
269     void resetRate();
270 };
271
272
273 #endif