interface_widgets.hpp 7.32 KB
Newer Older
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 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 VLC_QT_INTERFACE_WIDGETS_HPP_
#define VLC_QT_INTERFACE_WIDGETS_HPP_
28

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

33 34
#include "main_interface.hpp" /* Interface integration */
#include "input_manager.hpp"  /* Speed control */
35

36
#include "components/controller.hpp"
37
#include "components/controller_widget.hpp"
38 39
#include "dialogs_provider.hpp"
#include "components/info_panels.hpp"
40

41
#include <QWidget>
42
#include <QFrame>
43 44
#include <QLabel>
#include <QMouseEvent>
45
#include <QPropertyAnimation>
46
#include <QLinkedList>
47

48
class QMenu;
49
class QSlider;
50
class QWidgetAction;
51
class SpeedControlWidget;
52
struct vout_window_t;
53

54
/******************** Video Widget ****************/
55
class VideoWidget : public QFrame
56
{
57
    Q_OBJECT
58
public:
59
    VideoWidget( intf_thread_t *, QWidget* p_parent );
60 61
    virtual ~VideoWidget();

62 63 64
    bool request( struct vout_window_t * );
    void release( void );
    void sync( void );
65

66
protected:
67
    QPaintEngine *paintEngine() const Q_DECL_OVERRIDE
68 69 70 71
    {
        return NULL;
    }

72
    bool nativeEvent(const QByteArray &eventType, void *message, long *result) Q_DECL_OVERRIDE;
73
    virtual void resizeEvent(QResizeEvent *) Q_DECL_OVERRIDE;
74 75 76 77
    void mousePressEvent(QMouseEvent *) Q_DECL_OVERRIDE;
    void mouseMoveEvent(QMouseEvent *) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QMouseEvent *) Q_DECL_OVERRIDE;
    void mouseDoubleClickEvent(QMouseEvent *) Q_DECL_OVERRIDE;
78
    QSize physicalSize() const;
79

80
private:
81
    int qtMouseButton2VLC( Qt::MouseButton );
82
    intf_thread_t *p_intf;
83
    vout_window_t *p_window;
Jean-Baptiste Kempf's avatar
Jean-Baptiste Kempf committed
84

85
    QWidget *stable;
86
    QLayout *layout;
87 88 89

    void reportSize();

90
signals:
91
    void sizeChanged( int, int );
92

93
public slots:
Rémi Denis-Courmont's avatar
Rémi Denis-Courmont committed
94
    void setSize( unsigned int, unsigned int );
95 96
};

97
/******************** Background Widget ****************/
98
class BackgroundWidget : public QWidget
99 100 101 102
{
    Q_OBJECT
public:
    BackgroundWidget( intf_thread_t * );
103
    void setExpandstoHeight( bool b_expand ) { b_expandPixmap = b_expand; }
104
    void setWithArt( bool b_withart_ ) { b_withart = b_withart_; };
105
private:
106
    intf_thread_t *p_intf;
107 108
    QString pixmapUrl;
    bool b_expandPixmap;
109
    bool b_withart;
110
    QPropertyAnimation *fadeAnimation;
111
    void contextMenuEvent( QContextMenuEvent *event ) Q_DECL_OVERRIDE;
112
protected:
113 114
    void paintEvent( QPaintEvent *e ) Q_DECL_OVERRIDE;
    void showEvent( QShowEvent * e ) Q_DECL_OVERRIDE;
115
    static const int MARGIN = 5;
116
    QString defaultArt;
117
public slots:
118
    void toggle(){ isVisible() ? hide() : show(); }
119
    void updateArt( const QString& );
120 121
};

122 123 124 125 126 127 128 129 130 131 132 133
class EasterEggBackgroundWidget : public BackgroundWidget
{
    Q_OBJECT

public:
    EasterEggBackgroundWidget( intf_thread_t * );
    virtual ~EasterEggBackgroundWidget();

public slots:
    void animate();

protected:
134 135 136 137
    void paintEvent( QPaintEvent *e ) Q_DECL_OVERRIDE;
    void showEvent( QShowEvent *e ) Q_DECL_OVERRIDE;
    void hideEvent( QHideEvent * ) Q_DECL_OVERRIDE;
    void resizeEvent( QResizeEvent * ) Q_DECL_OVERRIDE;
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156

private slots:
    void spawnFlakes();
    void reset();

private:
    struct flake
    {
        QPoint point;
        bool b_fat;
    };
    QTimer *timer;
    QLinkedList<flake *> *flakes;
    int i_rate;
    int i_speed;
    bool b_enabled;
    static const int MAX_FLAKES = 1000;
};

157 158 159 160
class ClickableQLabel : public QLabel
{
    Q_OBJECT
public:
161
    void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
162 163 164 165 166 167 168 169 170
    {
        Q_UNUSED( event );
        emit doubleClicked();
    }
signals:
    void doubleClicked();
};

class TimeLabel : public ClickableQLabel
171 172
{
    Q_OBJECT
173
public:
174 175 176 177 178 179 180 181
    enum Display
    {
        Elapsed,
        Remaining,
        Both
    };

    TimeLabel( intf_thread_t *_p_intf, TimeLabel::Display _displayType = TimeLabel::Both );
182
protected:
183
    void mousePressEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
184
    {
185
        if( displayType == TimeLabel::Elapsed ) return;
186
        toggleTimeDisplay();
187
        event->accept();
188
    }
189
    void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
190
    {
191
        if( displayType != TimeLabel::Both ) return;
192
        event->accept();
193
        toggleTimeDisplay();
194
        ClickableQLabel::mouseDoubleClickEvent( event );
195
    }
196 197 198
private:
    intf_thread_t *p_intf;
    bool b_remainingTime;
199
    int cachedLength;
200
    TimeLabel::Display displayType;
201

202 203
    char psz_length[MSTRTIME_MAX_SIZE];
    char psz_time[MSTRTIME_MAX_SIZE];
204
    void toggleTimeDisplay();
205
private slots:
206
    void setRemainingTime( bool );
207
    void setDisplayPosition( float pos, int64_t time, int length );
208
    void setDisplayPosition( float pos );
209 210
signals:
    void broadcastRemainingTime( bool );
211
};
Clément Stenac's avatar
Clément Stenac committed
212

213 214 215 216
class SpeedLabel : public QLabel
{
    Q_OBJECT
public:
217
    SpeedLabel( intf_thread_t *, QWidget * );
218
    virtual ~SpeedLabel();
219 220

protected:
221
    void mousePressEvent ( QMouseEvent * event ) Q_DECL_OVERRIDE
222
    {
223
        showSpeedMenu( event->pos() );
224
    }
225 226
private slots:
    void showSpeedMenu( QPoint );
227
    void setRate( float );
228 229
private:
    intf_thread_t *p_intf;
230
    QMenu *speedControlMenu;
231
    QString tooltipStringPattern;
232
    SpeedControlWidget *speedControl;
233
    QWidgetAction *widgetAction;
234
};
235

236 237 238 239 240
/******************** Speed Control Widgets ****************/
class SpeedControlWidget : public QFrame
{
    Q_OBJECT
public:
241
    SpeedControlWidget( intf_thread_t *, QWidget * );
242
    void updateControls( float );
243
private:
244 245 246
    intf_thread_t* p_intf;
    QSlider* speedSlider;
    QDoubleSpinBox* spinBox;
247
    int lastValue;
248

249
public slots:
250
    void activateOnState();
251

252 253
private slots:
    void updateRate( int );
254
    void updateSpinBoxRate( double );
255 256 257
    void resetRate();
};

258 259 260 261
class CoverArtLabel : public QLabel
{
    Q_OBJECT
public:
262
    CoverArtLabel( QWidget *parent, intf_thread_t * );
263
    void setItem( input_item_t * );
264
    virtual ~CoverArtLabel();
265

266
protected:
267
    void mouseDoubleClickEvent( QMouseEvent *event ) Q_DECL_OVERRIDE
268
    {
269
        if( ! p_item && qobject_cast<MetaPanel *>(this->window()) == NULL )
270 271 272 273 274
        {
            THEDP->mediaInfoDialog();
        }
        event->accept();
    }
275
private:
276
    intf_thread_t *p_intf;
277
    input_item_t *p_item;
278 279

public slots:
280
    void showArtUpdate( const QString& );
281
    void showArtUpdate( input_item_t * );
282
    void askForUpdate();
Angelo Haller's avatar
Angelo Haller committed
283
    void setArtFromFile();
284
    void clear();
285 286
};

287
#endif