File indexing completed on 2024-12-08 09:42:39

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 #include "view.h"
0025 
0026 class KMediaPlayer::ViewPrivate
0027 {
0028 public:
0029     ViewPrivate()
0030         : videoWidget(nullptr)
0031         , currentButtons(View::All)
0032     {
0033         if (!buttonEnumRegistered) {
0034             buttonEnumRegistered = qRegisterMetaType<KMediaPlayer::View::Button>("KMediaPlayer::View::Button");
0035         }
0036         if (!buttonsFlagsRegistered) {
0037             buttonsFlagsRegistered = qRegisterMetaType<KMediaPlayer::View::Buttons>("KMediaPlayer::View::Buttons");
0038         }
0039     }
0040 
0041     QWidget *videoWidget;
0042     View::Buttons currentButtons;
0043 
0044     static bool buttonEnumRegistered;
0045     static bool buttonsFlagsRegistered;
0046 };
0047 bool KMediaPlayer::ViewPrivate::buttonEnumRegistered = false;
0048 bool KMediaPlayer::ViewPrivate::buttonsFlagsRegistered = false;
0049 
0050 KMediaPlayer::View::View(QWidget *parent)
0051     : QWidget(parent)
0052     , d(new ViewPrivate())
0053 {
0054 }
0055 
0056 KMediaPlayer::View::~View() = default;
0057 
0058 KMediaPlayer::View::Buttons KMediaPlayer::View::buttons()
0059 {
0060     return d->currentButtons;
0061 }
0062 
0063 void KMediaPlayer::View::setButtons(Buttons buttons)
0064 {
0065     if (buttons != d->currentButtons) {
0066         d->currentButtons = buttons;
0067         Q_EMIT buttonsChanged(buttons);
0068     }
0069 }
0070 
0071 bool KMediaPlayer::View::button(Button b)
0072 {
0073     return d->currentButtons & b;
0074 }
0075 
0076 void KMediaPlayer::View::showButton(Button b)
0077 {
0078     setButtons(d->currentButtons | b);
0079 }
0080 
0081 void KMediaPlayer::View::hideButton(Button b)
0082 {
0083     setButtons(d->currentButtons & ~b);
0084 }
0085 
0086 void KMediaPlayer::View::toggleButton(Button b)
0087 {
0088     setButtons(d->currentButtons ^ b);
0089 }
0090 
0091 void KMediaPlayer::View::setVideoWidget(QWidget *videoWidget)
0092 {
0093     d->videoWidget = videoWidget;
0094 }
0095 
0096 QWidget *KMediaPlayer::View::videoWidget()
0097 {
0098     return d->videoWidget;
0099 }
0100 
0101 #include "moc_view.cpp"