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

0001 /***************************************************************************
0002  *  Copyright (C) 2007 by Romain Campioni                                  *
0003  *  Copyright (C) 2009 by Renaud Guezennec                                 *
0004  *   https://rolisteam.org/contact                   *
0005  *                                                                         *
0006  *   rolisteam is free software; you can redistribute it and/or modify     *
0007  *   it under the terms of the GNU General Public License as published by  *
0008  *   the Free Software Foundation; either version 2 of the License, or     *
0009  *   (at your option) any later version.                                   *
0010  *                                                                         *
0011  *   This program is distributed in the hope that it will be useful,       *
0012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0014  *   GNU General Public License for more details.                          *
0015  *                                                                         *
0016  *   You should have received a copy of the GNU General Public License     *
0017  *   along with this program; if not, write to the                         *
0018  *   Free Software Foundation, Inc.,                                       *
0019  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
0020  ***************************************************************************/
0021 #include "audioPlayer.h"
0022 
0023 #include <QContextMenuEvent>
0024 #include <QDebug>
0025 #include <QFileDialog>
0026 #include <QListView>
0027 #include <QMenu>
0028 #include <QPushButton>
0029 #include <QToolButton>
0030 #include <array>
0031 
0032 #include "controller/audiocontroller.h"
0033 
0034 namespace
0035 {
0036 QString musicStatus= QStringLiteral("music_player_%1_status");
0037 }
0038 
0039 AudioPlayer::AudioPlayer(AudioController* ctrl, QWidget* parent) : QDockWidget(parent), m_ctrl(ctrl)
0040 {
0041     setObjectName("MusicPlayer");
0042     setupUi();
0043     setWidget(m_mainWidget);
0044     m_mainWidget->setVisible(true);
0045 }
0046 
0047 void AudioPlayer::contextMenuEvent(QContextMenuEvent* ev)
0048 {
0049     QMenu menu;
0050     if(m_ctrl->localIsGM())
0051     {
0052         for(auto& tmp : m_players)
0053         {
0054             if(tmp->isVisible() && tmp->geometry().contains(ev->pos(), true))
0055             {
0056                 tmp->addActionsIntoMenu(&menu);
0057                 menu.addSeparator();
0058             }
0059         }
0060     }
0061     for(auto& act : m_playerActionsList)
0062     {
0063         menu.addAction(act);
0064     }
0065 
0066     menu.exec(ev->globalPos());
0067     ev->accept();
0068 }
0069 AudioPlayer::~AudioPlayer()
0070 {
0071     delete m_mainWidget;
0072 }
0073 
0074 void AudioPlayer::setupUi()
0075 {
0076     setWindowTitle(tr("Background Music"));
0077     setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
0078     setFeatures(QDockWidget::DockWidgetClosable | QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
0079     setMinimumWidth(255);
0080     m_mainWidget= new QWidget(this);
0081 
0082     m_mainLayout= new QVBoxLayout();
0083     m_mainLayout->setSpacing(0);
0084     m_mainLayout->setContentsMargins(QMargins());
0085 
0086     if(m_ctrl)
0087     {
0088 
0089         std::array<AudioPlayerController*, 3> array{m_ctrl->firstController(), m_ctrl->secondController(),
0090                                                     m_ctrl->thirdController()};
0091 
0092         for(int i= 0; i < 3; ++i)
0093         {
0094             auto* playerWidget= new PlayerWidget(array[i], this);
0095             connect(playerWidget, &PlayerWidget::changePlayerDirectory, this, &AudioPlayer::changePlayerDirectory);
0096 
0097             m_players.append(playerWidget);
0098             auto* act= new QAction(tr("Show/hide Player %1").arg(i + 1), this);
0099             act->setCheckable(true);
0100             act->setChecked(array[i]->visible());
0101             connect(act, &QAction::triggered, array[i], &AudioPlayerController::setVisible);
0102             m_playerActionsList.append(act);
0103             m_mainLayout->addWidget(m_players[i]);
0104             playerWidget->setVisible(array[i]->visible());
0105         }
0106     }
0107 
0108     m_mainWidget->setLayout(m_mainLayout);
0109 }
0110 
0111 /**/