"Fossies" - the Fresh Open Source Software Archive

Member "kaffeine-2.0.18/src/mediawidget.h" (14 May 2019, 8093 Bytes) of package /linux/misc/kaffeine-2.0.18.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "mediawidget.h" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 2.0.17_vs_2.0.18.

    1 /*
    2  * mediawidget.h
    3  *
    4  * Copyright (C) 2007-2011 Christoph Pfister <christophpfister@gmail.com>
    5  *
    6  * This program is free software; you can redistribute it and/or modify
    7  * it under the terms of the GNU General Public License as published by
    8  * the Free Software Foundation; either version 2 of the License, or
    9  * (at your option) any later version.
   10  *
   11  * This program is distributed in the hope that it will be useful,
   12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14  * GNU General Public License for more details.
   15  *
   16  * You should have received a copy of the GNU General Public License along
   17  * with this program; if not, write to the Free Software Foundation, Inc.,
   18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   19  */
   20 
   21 #ifndef MEDIAWIDGET_H
   22 #define MEDIAWIDGET_H
   23 
   24 #include <QWidget>
   25 #include <QIcon>
   26 #include <QWeakPointer>
   27 #include <QUrl>
   28 #include <QToolBar>
   29 #include <QMenu>
   30 
   31 class KActionCollection;
   32 class KToolBar;
   33 class QActionGroup;
   34 class QComboBox;
   35 class QMenu;
   36 class QPushButton;
   37 class QSlider;
   38 class QStringListModel;
   39 class QWidgetAction;
   40 
   41 class AbstractMediaWidget;
   42 class MediaSource;
   43 class OsdWidget;
   44 class SeekSlider;
   45 
   46 class MediaWidget : public QWidget
   47 {
   48     Q_OBJECT
   49 public:
   50     MediaWidget(QMenu *menu_, QToolBar *toolBar, KActionCollection *collection,
   51         QWidget *parent);
   52     ~MediaWidget();
   53 
   54     static QString extensionFilter(); // usable for KFileDialog::setFilter()
   55 
   56     enum AspectRatio
   57     {
   58         AspectRatioAuto,
   59         AspectRatio1_1,
   60         AspectRatio4_3,
   61         AspectRatio5_4,
   62         AspectRatio16_9,
   63         AspectRatio16_10,
   64         AspectRatio221_100,
   65         AspectRatio235_100,
   66         AspectRatio239_100,
   67     };
   68 
   69     enum DeinterlaceMode
   70     {
   71         DeinterlaceDisabled,
   72         DeinterlaceDiscard,
   73         DeinterlaceBob,
   74         DeinterlaceLinear,
   75         DeinterlaceYadif,
   76         DeinterlaceYadif2x,
   77         DeinterlacePhosphor,
   78         DeinterlaceX,
   79         DeinterlaceMean,
   80         DeinterlaceBlend,
   81         DeinterlaceIvtc,
   82     };
   83 
   84     enum DisplayMode
   85     {
   86         NormalMode,
   87         FullScreenMode,
   88         FullScreenReturnToMinimalMode,
   89         MinimalMode
   90     };
   91 
   92     enum MetadataType
   93     {
   94         Title,
   95         Artist,
   96         Album,
   97         TrackNumber
   98     };
   99 
  100     enum PlaybackStatus
  101     {
  102         Idle,
  103         Playing,
  104         Paused
  105     };
  106 
  107     DisplayMode getDisplayMode() const;
  108     void setDisplayMode(DisplayMode displayMode_);
  109 
  110     /*
  111      * loads the media and starts playback
  112      */
  113 
  114     void play(MediaSource *source_);
  115     void play(const QUrl &url, const QUrl &subtitleUrl = QUrl());
  116     void playAudioCd(const QString &device);
  117     void playVideoCd(const QString &device);
  118     void playDvd(const QString &device);
  119 
  120     OsdWidget *getOsdWidget();
  121 
  122     PlaybackStatus getPlaybackStatus() const;
  123     int getPosition() const; // milliseconds
  124     int getVolume() const; // 0 - 100
  125 
  126     void play(); // (re-)starts the current media
  127     void togglePause();
  128     void setPosition(int position); // milliseconds
  129     void setVolume(int volume); // 0 - 100
  130     void toggleMuted();
  131     void mediaSourceDestroyed(MediaSource *mediaSource);
  132     void setAspectRatio(MediaWidget::AspectRatio aspectRatio);
  133 
  134 public slots:
  135     void previous();
  136     void next();
  137     void stop();
  138     void increaseVolume();
  139     void decreaseVolume();
  140     void toggleFullScreen();
  141     void toggleMinimalMode();
  142     void shortSkipBackward();
  143     void shortSkipForward();
  144     void longSkipBackward();
  145     void longSkipForward();
  146     void getAudioDevices();
  147     void openSubtitle();
  148     void setSubtitle(QUrl text);
  149 
  150 public:
  151     void playbackFinished();
  152     void playbackStatusChanged();
  153     void currentTotalTimeChanged();
  154     void metadataChanged();
  155     void seekableChanged();
  156     void audioStreamsChanged();
  157     void subtitlesChanged();
  158     void titlesChanged();
  159     void chaptersChanged();
  160     void anglesChanged();
  161     void dvdMenuChanged();
  162     void videoSizeChanged();
  163 
  164 signals:
  165     void displayModeChanged();
  166     void changeCaption(const QString &caption);
  167     void resizeToVideo(float resizeFactor);
  168 
  169     void playlistPrevious();
  170     void playlistNext();
  171     void playlistUrlsDropped(const QList<QUrl> &urls);
  172     void playlistTrackLengthChanged(int length);
  173     void playlistTrackMetadataChanged(const QMap<MediaWidget::MetadataType, QString> &metadata);
  174     void osdKeyPressed(int key);
  175 
  176 private slots:
  177     void checkScreenSaver();
  178 
  179     void setAudioCard();
  180     void mutedChanged();
  181     void volumeChanged(int volume);
  182     void seek(int position);
  183     void deinterlacingChanged(QAction *action);
  184     void aspectRatioChanged(QAction *action);
  185     void setVideoSize();
  186     void autoResizeTriggered(QAction *action);
  187     void pausedChanged(bool paused);
  188     void timeButtonClicked();
  189     void jumpToPosition();
  190     void currentAudioStreamChanged(int currentAudioStream);
  191     void currentSubtitleChanged(int currentSubtitle);
  192     void toggleMenu();
  193     void currentTitleChanged(QAction *action);
  194     void currentChapterChanged(QAction *action);
  195     void currentAngleChanged(QAction *action);
  196     void shortSkipDurationChanged(int shortSkipDuration);
  197     void longSkipDurationChanged(int longSkipDuration);
  198 
  199 private:
  200     void contextMenuEvent(QContextMenuEvent *event);
  201     void mouseDoubleClickEvent(QMouseEvent *event);
  202     void dragEnterEvent(QDragEnterEvent *event);
  203     void dropEvent(QDropEvent *event);
  204     void keyPressEvent(QKeyEvent *event);
  205     void resizeEvent(QResizeEvent *event);
  206     void wheelEvent(QWheelEvent *event);
  207     void setVolumeUnderMouse(int volume);
  208 
  209     bool event(QEvent* event) override;
  210 
  211     QMenu *menu;
  212     AbstractMediaWidget *backend;
  213     OsdWidget *osdWidget;
  214 
  215     QWidgetAction *actionPrevious;
  216     QWidgetAction *actionPlayPause;
  217     QString textPlay;
  218     QString textPause;
  219     QIcon iconPlay;
  220     QIcon iconPause;
  221     QWidgetAction *actionStop;
  222     QWidgetAction *actionNext;
  223     QWidgetAction *fullScreenAction;
  224     QWidgetAction *minimalModeAction;
  225     QComboBox *audioStreamBox;
  226     QComboBox *subtitleBox;
  227     QStringListModel *audioStreamModel;
  228     QStringListModel *subtitleModel;
  229     QString textSubtitlesOff;
  230     QWidgetAction *muteAction;
  231     QIcon mutedIcon;
  232     QIcon unmutedIcon;
  233     QSlider *volumeSlider;
  234     SeekSlider *seekSlider;
  235     QWidgetAction *longSkipBackwardAction;
  236     QWidgetAction *shortSkipBackwardAction;
  237     QWidgetAction *shortSkipForwardAction;
  238     QWidgetAction *longSkipForwardAction;
  239     QWidgetAction *menuAction;
  240     QMenu *audioDevMenu;
  241     QMenu *titleMenu;
  242     QMenu *chapterMenu;
  243     QMenu *angleMenu;
  244     QActionGroup *titleGroup;
  245     QActionGroup *chapterGroup;
  246     QActionGroup *angleGroup;
  247     QMenu *navigationMenu;
  248     QWidgetAction *jumpToPositionAction;
  249     QPushButton *timeButton;
  250 
  251     DisplayMode displayMode;
  252     int autoResizeFactor;
  253     int deinterlaceMode;
  254     QScopedPointer<MediaSource> dummySource;
  255     MediaSource *source;
  256     bool blockBackendUpdates;
  257     bool muted;
  258     bool screenSaverSuspended;
  259     bool showElapsedTime;
  260 };
  261 
  262 class MediaSource
  263 {
  264 public:
  265     MediaSource() { }
  266 
  267     virtual ~MediaSource()
  268     {
  269         setMediaWidget(NULL);
  270     }
  271 
  272     enum Type
  273     {
  274         Url,
  275         AudioCd,
  276         VideoCd,
  277         Dvd,
  278         Dvb
  279     };
  280 
  281     virtual Type getType() const { return Url; }
  282     virtual QUrl getUrl() const { return QUrl(); }
  283     virtual void validateCurrentTotalTime(int &, int &) const { }
  284     virtual bool hideCurrentTotalTime() const { return false; }
  285     virtual bool overrideAudioStreams() const { return false; }
  286     virtual bool overrideSubtitles() const { return false; }
  287     virtual QStringList getAudioStreams() const { return QStringList(); }
  288     virtual QStringList getSubtitles() const { return QStringList(); }
  289     virtual int getCurrentAudioStream() const { return -1; }
  290     virtual int getCurrentSubtitle() const { return -1; }
  291     virtual bool overrideCaption() const { return false; }
  292     virtual QString getDefaultCaption() const { return QString(); }
  293     virtual void setCurrentAudioStream(int ) { }
  294     virtual void setCurrentSubtitle(int ) { }
  295     virtual void trackLengthChanged(int ) { }
  296     virtual void metadataChanged(const QMap<MediaWidget::MetadataType, QString> &) { }
  297     virtual void playbackFinished() { }
  298     virtual void playbackStatusChanged(MediaWidget::PlaybackStatus ) { }
  299     virtual void replay() { }
  300     virtual void previous() { }
  301     virtual void next() { }
  302 
  303     void setMediaWidget(const MediaWidget *mediaWidget)
  304     {
  305         MediaWidget *oldMediaWidget = weakMediaWidget.data();
  306 
  307         if (mediaWidget != oldMediaWidget) {
  308             if (oldMediaWidget != NULL) {
  309                 oldMediaWidget->mediaSourceDestroyed(this);
  310             }
  311 // FIXME:
  312 //          weakMediaWidget = mediaWidget;
  313         }
  314     }
  315 private:
  316     QWeakPointer<MediaWidget> weakMediaWidget;
  317 };
  318 
  319 #endif /* MEDIAWIDGET_H */