interface_widgets.hpp 9.24 KB
Newer Older
1
/*****************************************************************************
2
 * interface_widgets.hpp : Custom widgets for the main interface
3
 ****************************************************************************
4 5
 * Copyright (C) 2006 the VideoLAN team
 * $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 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

26 27
#ifndef _INTFWIDGETS_H_
#define _INTFWIDGETS_H_
28

Christophe Mutricy's avatar
Christophe Mutricy committed
29 30 31 32
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

33
#include <vlc_common.h>
zorglub's avatar
zorglub committed
34
#include <vlc_interface.h>
35
#include <vlc_aout.h>
36

zorglub's avatar
zorglub committed
37
#include "qt4.hpp"
38
#include "main_interface.hpp"
39
#include "input_manager.hpp"
zorglub's avatar
zorglub committed
40

41
#include <QWidget>
zorglub's avatar
zorglub committed
42
#include <QFrame>
43

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
44 45 46
class ResizeEvent;
class QPalette;
class QPixmap;
zorglub's avatar
zorglub committed
47
class QLabel;
48 49
class QHBoxLayout;

50
/******************** Video Widget ****************/
zorglub's avatar
zorglub committed
51
class VideoWidget : public QFrame
52
{
zorglub's avatar
zorglub committed
53
    Q_OBJECT
54 55
friend class MainInterface;

56
public:
57
    VideoWidget( intf_thread_t * );
58 59
    virtual ~VideoWidget();

60
    void *request( vout_thread_t *, int *, int *,
61
                   unsigned int *, unsigned int * );
62 63
    void  release( void * );
    int   control( void *, int, va_list );
64

65
    virtual QSize sizeHint() const;
66 67
private:
    intf_thread_t *p_intf;
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
68
    int i_vout;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
69

70
    QSize videoSize;
71

72
signals:
73
    void askVideoWidgetToShow( unsigned int, unsigned int );
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
74

75 76
public slots:
    void SetSizing( unsigned int, unsigned int );
77 78

protected:
79 80 81 82 83
    virtual QPaintEngine *paintEngine() const
    {
        return NULL;
    }

84
    virtual void paintEvent(QPaintEvent *);
85 86
};

87
/******************** Background Widget ****************/
88
class BackgroundWidget : public QWidget
89 90 91 92 93
{
    Q_OBJECT
public:
    BackgroundWidget( intf_thread_t * );
    virtual ~BackgroundWidget();
94

95 96 97
private:
    QPalette plt;
    QLabel *label;
98
    virtual void contextMenuEvent( QContextMenuEvent *event );
99
    intf_thread_t *p_intf;
100
    virtual void resizeEvent( QResizeEvent * event );
101
public slots:
102
    void toggle(){ TOGGLEV( this ); }
103
    void updateArt( QString );
104 105
};

Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
106
#if 0
zorglub's avatar
zorglub committed
107 108 109 110 111 112 113 114
class VisualSelector : public QFrame
{
    Q_OBJECT
public:
    VisualSelector( intf_thread_t *);
    virtual ~VisualSelector();
private:
    intf_thread_t *p_intf;
zorglub's avatar
zorglub committed
115 116 117 118
    QLabel *current;
private slots:
    void prev();
    void next();
zorglub's avatar
zorglub committed
119
};
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
120
#endif
121

122
/* Advanced Button Bar */
zorglub's avatar
zorglub committed
123
class QPushButton;
124
class AdvControlsWidget : public QFrame
zorglub's avatar
zorglub committed
125 126 127
{
    Q_OBJECT
public:
128
    AdvControlsWidget( intf_thread_t *, bool );
129
    virtual ~AdvControlsWidget();
130

zorglub's avatar
zorglub committed
131 132
    void enableInput( bool );
    void enableVideo( bool );
133

zorglub's avatar
zorglub committed
134 135
private:
    intf_thread_t *p_intf;
136
    QPushButton *recordButton, *ABButton;
137
    QPushButton *snapshotButton, *frameButton;
138

139
    static mtime_t timeA, timeB;
140
    int i_last_input_id;
141

zorglub's avatar
zorglub committed
142 143
private slots:
    void snapshot();
144
#if 0
145
    void frame();
146
#endif
147
    void fromAtoB();
148
    void record();
149
    void AtoBLoop( float, int, int );
150 151 152 153
    void setIcon();

signals:
    void timeChanged();
zorglub's avatar
zorglub committed
154 155
};

156
/* Button Bar */
157 158 159 160
class InputSlider;
class QSlider;
class QGridLayout;
class VolumeClickHandler;
161
class SoundSlider;
162
class QAbstractSlider;
163
class QToolButton;
164

165 166 167 168
class ControlsWidget : public QFrame
{
    Q_OBJECT
public:
169
    /* p_intf, advanced control visible or not, blingbling or not */
lukas.durfina's avatar
lukas.durfina committed
170 171
    ControlsWidget( intf_thread_t *_p_i, MainInterface *_p_mi,
        bool b_advControls, bool b_shiny, bool b_fsCreation = false);
172 173 174 175
    virtual ~ControlsWidget();

    QPushButton *playlistButton;
    void setStatus( int );
176
    void enableInput( bool );
177
    void enableVideo( bool );
178 179 180 181 182
public slots:
    void setNavigation( int );
protected:
    friend class MainInterface;
    friend class VolumeClickHandler;
lukas.durfina's avatar
lukas.durfina committed
183
protected:
184
    intf_thread_t       *p_intf;
185 186
    QWidget             *discFrame;
    QWidget             *telexFrame;
187
    QGridLayout         *controlLayout;
188
    InputSlider         *slider;
189
    QPushButton         *prevSectionButton, *nextSectionButton, *menuButton;
lukas.durfina's avatar
lukas.durfina committed
190
    QPushButton         *playButton, *fullscreenButton, *extSettingsButton;
lukas.durfina's avatar
lukas.durfina committed
191
    QPushButton         *telexTransparent, *telexOn;
192
    QSpinBox            *telexPage;
193
    QToolButton         *slowerButton, *fasterButton;
lukas.durfina's avatar
lukas.durfina committed
194
    QHBoxLayout         *controlButLayout;
195
    AdvControlsWidget   *advControls;
196
    QLabel              *volMuteLabel;
197
    QAbstractSlider     *volumeSlider;
lukas.durfina's avatar
lukas.durfina committed
198
    VolumeClickHandler  *hVolLabel;
199 200

    bool                 b_advancedVisible;
201 202
    bool                 b_telexTransparent;
    bool                 b_telexEnabled;
lukas.durfina's avatar
lukas.durfina committed
203
protected slots:
204 205 206 207 208
    void play();
    void stop();
    void prev();
    void next();
    void updateVolume( int );
209
    void updateVolume( void );
210
    void updateInput();
211 212
    void fullscreen();
    void extSettings();
213 214
    void faster();
    void slower();
215
    void toggleAdvanced();
216 217
    void toggleTeletext();
    void toggleTeletextTransparency();
218
    void enableTeletext( bool );
219
signals:
220
    void advancedControlsToggled( bool );
221 222
};

223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
/* on WIN32 hide() for fullscreen controller doesnt work, so it have to be
   done by trick with setting the opacity of window */
#ifdef WIN32
    #define WIN32TRICK
#endif

/* to trying transparency with fullscreen controller on windows enable that */
/* it can be enabled on-non windows systems,
   but it will be transparent only with composite manager */
#ifndef WIN32
    #define HAVE_TRANSPARENCY 1
#else
    #define HAVE_TRANSPARENCY 0
#endif

/* Default value of opacity for FS controller */
#define DEFAULT_OPACITY 0.75

lukas.durfina's avatar
lukas.durfina committed
241 242 243 244 245 246 247 248 249 250
/***********************************
 * Fullscreen controller
 ***********************************/
class FullscreenControllerWidget : public ControlsWidget
{
    Q_OBJECT
public:
    FullscreenControllerWidget( intf_thread_t *, MainInterface*, bool, bool );
    virtual ~FullscreenControllerWidget();

251 252
    /* */
    void attachVout( vout_thread_t *p_vout );
253
    void detachVout();
254
    void fullscreenChanged( vout_thread_t *, bool b_fs, int i_timeout );
lukas.durfina's avatar
lukas.durfina committed
255 256 257 258 259 260 261 262 263 264 265 266

protected:
    friend class MainInterface;
    friend class VolumeClickHandler;

    virtual void mouseMoveEvent( QMouseEvent *event );
    virtual void mousePressEvent( QMouseEvent *event );
    virtual void enterEvent( QEvent *event );
    virtual void leaveEvent( QEvent *event );
    virtual void keyPressEvent( QKeyEvent *event );

private slots:
267 268 269 270
    void showFSC();
    void planHideFSC();
    void hideFSC();

lukas.durfina's avatar
lukas.durfina committed
271 272
    void slowHideFSC();

273

lukas.durfina's avatar
lukas.durfina committed
274 275
private:
    QTimer *p_hideTimer;
276
#if HAVE_TRANSPARENCY
lukas.durfina's avatar
lukas.durfina committed
277
    QTimer *p_slowHideTimer;
278
#endif
lukas.durfina's avatar
lukas.durfina committed
279

280 281 282 283 284 285 286
    int i_mouse_last_x;
    int i_mouse_last_y;

    bool b_mouse_over;

    bool b_slow_hide_begin;
    int  i_slow_hide_timeout;
lukas.durfina's avatar
lukas.durfina committed
287

288
#ifdef WIN32TRICK
289
    bool b_fscHidden;
290
#endif
lukas.durfina's avatar
lukas.durfina committed
291 292

    virtual void customEvent( QEvent *event );
293

294 295
    vout_thread_t *p_vout;

296 297 298 299
    /* Shared variable between FSC and VLC (protected by a lock) */
    vlc_mutex_t lock;
    bool        b_fullscreen;
    int         i_hide_timeout;  /* FSC hiding timeout, same as mouse hiding timeout */
lukas.durfina's avatar
lukas.durfina committed
300 301 302
};


303
#define VOLUME_MAX 200
304 305 306 307 308 309 310 311
class VolumeClickHandler : public QObject
{
public:
    VolumeClickHandler( intf_thread_t *_p_intf, ControlsWidget *_m ) :QObject(_m)
    {m = _m; p_intf = _p_intf; }
    virtual ~VolumeClickHandler() {};
    bool eventFilter( QObject *obj, QEvent *e )
    {
312
        if (e->type() == QEvent::MouseButtonPress  )
313 314
        {
            aout_VolumeMute( p_intf, NULL );
315 316
            audio_volume_t i_volume;
            aout_VolumeGet( p_intf, &i_volume );
317
            m->updateVolume( i_volume *  VOLUME_MAX / (AOUT_VOLUME_MAX/2) );
318 319 320 321 322 323 324 325 326
            return true;
        }
        return false;
    }
private:
    ControlsWidget *m;
    intf_thread_t *p_intf;
};

327 328 329 330 331 332 333
#include <QLabel>
#include <QMouseEvent>
class TimeLabel : public QLabel
{
    Q_OBJECT
    void mousePressEvent( QMouseEvent *event )
    {
334
        emit timeLabelClicked();
335
    }
336 337 338 339
    void mouseDoubleClickEvent( QMouseEvent *event )
    {
        emit timeLabelDoubleClicked();
    }
340 341
signals:
    void timeLabelClicked();
342
    void timeLabelDoubleClicked();
343
};
zorglub's avatar
zorglub committed
344

345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
class SpeedLabel : public QLabel
{
    Q_OBJECT
public:
    SpeedLabel( intf_thread_t *_p_intf, const QString text ): QLabel( text)
    { p_intf = _p_intf; }

protected:
    virtual void mouseDoubleClickEvent ( QMouseEvent * event )
    {
        THEMIM->getIM()->setRate( INPUT_RATE_DEFAULT );
    }
private:
    intf_thread_t *p_intf;
};
360

361 362 363 364 365 366 367 368 369 370 371
/******************** Speed Control Widgets ****************/
class SpeedControlWidget : public QFrame
{
    Q_OBJECT
public:
    SpeedControlWidget( intf_thread_t *);
    virtual ~SpeedControlWidget();
    void updateControls( int );
private:
    intf_thread_t *p_intf;
    QSlider *speedSlider;
372 373
public slots:
    void setEnable( bool );
374 375 376 377 378
private slots:
    void updateRate( int );
    void resetRate();
};

379
#endif