File indexing completed on 2024-04-28 05:38:13

0001 /***************************************************************************
0002  *  Copyright (C) 2015 by Renaud Guezennec                                 *
0003  *   http://www.renaudguezennec.eu/accueil,3.html                          *
0004  *                                                                         *
0005  *   rolisteam is free software; you can redistribute it and/or modify     *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; if not, write to the                         *
0017  *   Free Software Foundation, Inc.,                                       *
0018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0019  ***************************************************************************/
0020 #include "mediacontainer.h"
0021 
0022 #include <QMdiArea>
0023 #include <QMenu>
0024 #include <QMessageBox>
0025 
0026 MediaContainer::MediaContainer(MediaControllerBase* ctrl, ContainerType containerType, QWidget* parent)
0027     : QMdiSubWindow(parent)
0028     , m_lifeCycleCtrl(ctrl)
0029     , m_preferences(PreferencesManager::getInstance())
0030     , m_currentCursor(nullptr)
0031     , m_containerType(containerType)
0032 {
0033     setAttribute(Qt::WA_DeleteOnClose, false);
0034     m_detachedDialog= new QAction(tr("Detach the view"), this);
0035     m_detachedDialog->setCheckable(true);
0036 
0037     connect(m_detachedDialog, &QAction::triggered, this, &MediaContainer::detachView);
0038     connect(m_lifeCycleCtrl, &MediaControllerBase::closeContainer, this, &MediaContainer::close);
0039     connect(m_lifeCycleCtrl, &MediaControllerBase::ownerIdChanged, this, &MediaContainer::ownerIdChanged);
0040     connect(m_lifeCycleCtrl, &MediaControllerBase::nameChanged, this,
0041             [this]() { setWindowTitle(m_lifeCycleCtrl->name()); });
0042 }
0043 
0044 MediaContainer::~MediaContainer() {}
0045 
0046 MediaControllerBase* MediaContainer::ctrl() const
0047 {
0048     return m_lifeCycleCtrl;
0049 }
0050 
0051 void MediaContainer::error(QString err, QWidget* parent)
0052 {
0053     if(nullptr != parent)
0054     {
0055         QMessageBox msgBox(parent);
0056         msgBox.addButton(QMessageBox::Cancel);
0057         msgBox.setIcon(QMessageBox::Critical);
0058         msgBox.setWindowTitle(QObject::tr("Loading error"));
0059         msgBox.move(QPoint(parent->width() / 2, parent->height() / 2) + QPoint(-100, -50));
0060 
0061         Qt::WindowFlags flags= msgBox.windowFlags();
0062         msgBox.setWindowFlags(flags ^ Qt::WindowSystemMenuHint);
0063 
0064         msgBox.setText(err);
0065         msgBox.exec();
0066     }
0067 }
0068 
0069 void MediaContainer::setVisible(bool b)
0070 {
0071     if(nullptr != widget())
0072     {
0073         widget()->setVisible(b);
0074     }
0075     QMdiSubWindow::setVisible(b);
0076 }
0077 
0078 QString MediaContainer::mediaId() const
0079 {
0080     return m_lifeCycleCtrl->uuid();
0081 }
0082 
0083 void MediaContainer::addActionToMenu(QMenu& menu)
0084 {
0085     menu.addAction(m_detachedDialog);
0086 }
0087 
0088 void MediaContainer::hideEvent(QHideEvent*)
0089 {
0090     emit visibleChanged(false);
0091 }
0092 
0093 void MediaContainer::showEvent(QShowEvent*)
0094 {
0095     emit visibleChanged(true);
0096 }
0097 
0098 void MediaContainer::detachView(bool b)
0099 {
0100     static QMdiArea* parent= mdiArea();
0101     if(b)
0102     {
0103         setParent(nullptr);
0104         setVisible(true);
0105     }
0106     else
0107     {
0108         // m_window->setParent(parent);
0109         if(nullptr != parent)
0110         {
0111             parent->addSubWindow(this);
0112         }
0113         setVisible(true);
0114     }
0115 }
0116 MediaContainer::ContainerType MediaContainer::getContainerType() const
0117 {
0118     return m_containerType;
0119 }
0120 
0121 void MediaContainer::closeEvent(QCloseEvent* event)
0122 {
0123     hide();
0124     event->accept();
0125 }
0126 
0127 void MediaContainer::setContainerType(const ContainerType& containerType)
0128 {
0129     m_containerType= containerType;
0130 }
0131 QString MediaContainer::ownerId() const
0132 {
0133     return m_lifeCycleCtrl ? m_lifeCycleCtrl->ownerId() : QString();
0134 }
0135 
0136 void MediaContainer::setOwnerId(const QString& ownerId)
0137 {
0138     if(m_lifeCycleCtrl)
0139         m_lifeCycleCtrl->setOwnerId(ownerId);
0140 }