UBMediaWidget.h 3.47 KB
Newer Older
1 2 3
/*
 * 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
Claudio Valerio's avatar
Claudio Valerio committed
4
 * the Free Software Foundation, either version 2 of the License, or
5 6 7 8 9 10 11 12 13 14
 * (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, see <http://www.gnu.org/licenses/>.
 */
15 16 17 18 19 20 21 22 23
#ifndef UBMEDIAWIDGET_H
#define UBMEDIAWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QLabel>
#include <QSlider>
#include <QMouseEvent>
24
#include <QStackedWidget>
25 26 27 28 29

#include <phonon/MediaObject>
#include <phonon/VideoWidget>
#include <phonon/AudioOutput>

30
#include "UBActionableWidget.h"
31 32 33 34

#define UBMEDIABUTTON_SIZE              32
#define TICK_INTERVAL                   1000

35 36 37
/**
  * \brief The media type
  */
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
typedef enum{
    eMediaType_Video,
    eMediaType_Audio
}eMediaType;

class UBMediaButton : public QLabel
{
    Q_OBJECT
public:
    UBMediaButton(QWidget* parent=0, const char* name="UBMediaButton");
    ~UBMediaButton();

signals:
    void clicked();

protected:
    void mousePressEvent(QMouseEvent* ev);
    void mouseReleaseEvent(QMouseEvent* ev);

private:
58
    /** And indicator of the press event in progress */
59 60 61
    bool mPressed;
};

62
class UBMediaWidget : public UBActionableWidget
63 64 65 66 67 68 69 70
{
    Q_OBJECT
public:
    UBMediaWidget(eMediaType type = eMediaType_Video, QWidget* parent=0, const char* name="UBMediaWidget");
    ~UBMediaWidget();
    void setFile(const QString& filePath);
    eMediaType mediaType();
    int border();
shibakaneki's avatar
shibakaneki committed
71
    void setAudioCover(const QString& coverPath);
72 73
    void setUrl(const QString& url){mUrl = url;}
    QString url(){return mUrl;}
74 75 76

protected:
    void resizeEvent(QResizeEvent* ev);
77
    void showEvent(QShowEvent* event);
78
    void hideEvent(QHideEvent* event);
79 80
    /** The current media file path */
    QString mFilePath;
81 82 83 84 85 86 87 88 89 90 91 92 93

private slots:
    void onPlayStopClicked();
    void onPauseClicked();
    void onStateChanged(Phonon::State newState, Phonon::State oldState);
    void onTotalTimeChanged(qint64 total);
    void onTick(qint64 currentTime);
    void onSliderChanged(int value);

private:
    void createMediaPlayer();
    void adaptSizeToVideo();

94
    /** The current media type */
95
    eMediaType mType;
96
    /** The media object */
97
    Phonon::MediaObject* mpMediaObject;
98
    /** The video renderer */
99
    Phonon::VideoWidget* mpVideoWidget;
100
    /** The audio renderer */
101
    Phonon::AudioOutput* mpAudioOutput;
102
    /** The principal layout of this widget */
103
    QVBoxLayout* mpLayout;
104
    /** The seeker layout */
105
    QHBoxLayout* mpSeekerLayout;
106
    /** The play-stop button */
107
    UBMediaButton* mpPlayStopButton;
108
    /** The pause button */
109
    UBMediaButton* mpPauseButton;
110
    /** The seeker slider */
111
    QSlider* mpSlider;
112
    /** An indicator of the seeker auto update in progress */
113
    bool mAutoUpdate;
114
    /** An indicator of the thumbnail generation in progress */
115
    bool mGeneratingThumbnail;
116
    /** The border */
117
    int mBorder;
118
    /** A widget that will contain the media */
shibakaneki's avatar
shibakaneki committed
119
    QWidget* mpMediaContainer;
120
    /** The media layout */
121
    QHBoxLayout* mMediaLayout;
122
    /** The audio cover */
shibakaneki's avatar
shibakaneki committed
123
    QLabel* mpCover;
124 125
    /** The media url */
    QString mUrl;
126 127 128
};

#endif // UBMEDIAWIDGET_H