File indexing completed on 2024-12-01 09:54:45

0001 // Copyright (C) 2002 Neil Stevens <neil@qualityassistant.com>
0002 //
0003 // Permission is hereby granted, free of charge, to any person obtaining a copy
0004 // of this software and associated documentation files (the "Software"), to deal
0005 // in the Software without restriction, including without limitation the rights
0006 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
0007 // copies of the Software, and to permit persons to whom the Software is
0008 // furnished to do so, subject to the following conditions:
0009 //
0010 // The above copyright notice and this permission notice shall be included in
0011 // all copies or substantial portions of the Software.
0012 //
0013 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0014 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0015 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
0016 // THE AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
0017 // AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
0018 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
0019 //
0020 // Except as contained in this notice, the name(s) of the author(s) shall not be
0021 // used in advertising or otherwise to promote the sale, use or other dealings
0022 // in this Software without prior written authorization from the author(s).
0023 
0024 #ifndef KMEDIAPLAYERVIEW_H
0025 #define KMEDIAPLAYERVIEW_H
0026 
0027 #include <QWidget>
0028 #include "kmediaplayer_export.h"
0029 
0030 #include <memory>
0031 
0032 namespace KMediaPlayer
0033 {
0034 
0035 /**
0036  * A user interface to control a Player object.
0037  *
0038  * Player::view() should be used to access an instance of this class.
0039  */
0040 class KMEDIAPLAYER_EXPORT View : public QWidget
0041 {
0042     Q_OBJECT
0043     Q_FLAGS(Button Buttons)
0044     /**
0045      * The controls that are displayed by the interface.
0046      */
0047     Q_PROPERTY(Buttons buttons READ buttons WRITE setButtons NOTIFY buttonsChanged)
0048     /**
0049      * The widget that displays video output.
0050      *
0051      * This may be 0 if video output is not supported.
0052      */
0053     Q_PROPERTY(QWidget* videoWidget READ videoWidget)
0054 
0055 public:
0056     /**
0057      * Creates the user interface widget.
0058      *
0059      * @param parent  The parent widget.
0060      */
0061     explicit View(QWidget *parent);
0062     /**
0063      * Destroys all related resources (but not the player object).
0064      */
0065     ~View() override;
0066 
0067     /** The controls that can appear in the interface. */
0068     enum Button {
0069         /**
0070          * A control to start playback.
0071          *
0072          * @see Player::play()
0073          */
0074         Play = 1,
0075         /**
0076          * A control to stop playback.
0077          *
0078          * @see Player::stop()
0079          */
0080         Stop = 2,
0081         /**
0082          * A control to pause playback.
0083          *
0084          * @see Player::pause()
0085          */
0086         Pause = 4,
0087         /**
0088          * A control to adjust the playback position.
0089          *
0090          * @see Player::seek()
0091          */
0092         Seeker = 8,
0093         /**
0094          * All controls.
0095          */
0096         All = 255
0097     };
0098     Q_DECLARE_FLAGS(Buttons, Button)
0099 
0100     /**
0101      * Returns which buttons are being displayed.
0102      */
0103     Buttons buttons();
0104 
0105     /**
0106      * Returns the widget used to display video output.
0107      *
0108      * May return 0 if video output is not supported.
0109      */
0110     QWidget *videoWidget();
0111 
0112 public Q_SLOTS:
0113     /**
0114      * Set the controls to display.
0115      *
0116      * @param buttons  A ORed combination of buttons to display.
0117      */
0118     void setButtons(Buttons buttons);
0119 
0120     /**
0121      * Queries whether a particular control is being displayed.
0122      *
0123      * @param button  The control to query.
0124      */
0125     bool button(Button button);
0126     /**
0127      * Display a control.
0128      *
0129      * If the control is already displayed, this has no effect. Otherwise, it
0130      * will be added to the set of controls to be displayed.
0131      *
0132      * @param button  The control to display.
0133      */
0134     void showButton(Button button);
0135     /**
0136      * Stop displaying a control.
0137      *
0138      * If the control is not already displayed, this has no effect. Otherwise,
0139      * it will be removed from the set of controls to be displayed.
0140      *
0141      * @param button  The control to stop displaying.
0142      */
0143     void hideButton(Button button);
0144     /**
0145      * Toggle the display of a control.
0146      *
0147      * If the control is not already displayed, it will be added to the set of
0148      * controls to be displayed. Otherwise, it will be removed from that set.
0149      *
0150      * @param button  The control to toggle.
0151      */
0152     void toggleButton(Button button);
0153 
0154 Q_SIGNALS:
0155     /**
0156      * Indicates that the value returned by buttons() has changed.
0157      *
0158      * Subclasses should connect to this signal to update the set of controls
0159      * they display.
0160      *
0161      * @param buttons  The new value.
0162      */
0163     void buttonsChanged(KMediaPlayer::View::Buttons buttons);
0164 
0165 protected:
0166     /**
0167      * Set the widget used to display video output.
0168      *
0169      * This should normally be created with this object as the parent, but users
0170      * of this object may use QWidget::setParent(QWidget*) to move it elsewhere.
0171      */
0172     void setVideoWidget(QWidget *videoWidget);
0173 
0174 private:
0175     std::unique_ptr<class ViewPrivate> const d;
0176 };
0177 
0178 Q_DECLARE_OPERATORS_FOR_FLAGS(View::Buttons)
0179 
0180 }
0181 
0182 Q_DECLARE_METATYPE(KMediaPlayer::View::Button)
0183 Q_DECLARE_METATYPE(KMediaPlayer::View::Buttons)
0184 
0185 #endif