Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "phononvideoplayer.h"
- #include "ui_phononvideoplayer.h"
- phononVideoPlayer::phononVideoPlayer(QWidget *parent) :
- QWidget(parent),
- ui(new Ui::phononVideoPlayer)
- {
- ui->setupUi(this);
- setupLook();
- setupWidgets();
- setupConnections();
- setupMenus();
- playVideo("pathto/MrTambourineman.mp4"); //works
- }
- void phononVideoPlayer::setupLook()
- {
- //Window status
- // setWindowFlags(Qt::FramelessWindowHint); //window without borders
- //Mouse
- //icons
- QIcon icon(QIcon(":/icon/mainicon"));
- setWindowIcon(icon);
- //Tray
- QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
- trayIcon->setIcon(icon);
- trayIcon->setVisible(true);
- }
- void phononVideoPlayer::setupMenus()
- {
- //Quit Action, makes the app quit.
- act_Quit = new QAction(tr("Quit"),this);
- act_Quit->setIcon(QIcon(":/icon/quit"));
- act_Quit->setIconVisibleInMenu(true);
- connect(act_Quit,SIGNAL(triggered()),this,SLOT(close()));
- //Pause Action, makes the video pause.
- act_Pause = new QAction(tr("Pause"),this);
- act_Pause->setIcon(QIcon(":/icon/pause"));
- act_Pause->setIconVisibleInMenu(true);
- connect(act_Pause,SIGNAL(triggered()),obj_MediaObject,SLOT(pause()));
- //Play Action, makes the video play.
- act_Play = new QAction(tr("Play"),this);
- act_Play->setIcon(QIcon(":/icon/play"));
- act_Play->setIconVisibleInMenu(true);
- connect(act_Play,SIGNAL(triggered()),obj_MediaObject,SLOT(play()));
- //Stop Action, makes the video stop.
- act_Stop = new QAction(tr("Stop"),this);
- act_Stop->setIcon(QIcon(":/icon/stop"));
- act_Stop->setIconVisibleInMenu(true);
- connect(act_Stop,SIGNAL(triggered()),obj_MediaObject,SLOT(stop()));
- //VolumeSetting Action, shows a volume slider to set the volume for the video
- act_VolumeSetting = new QAction(tr("Volume Setting"),this);
- act_VolumeSetting->setIcon(QIcon(":/icon/volume"));
- act_VolumeSetting->setIconVisibleInMenu(true);
- connect(act_VolumeSetting,SIGNAL(triggered()),this,SLOT(showVolumeSlider()));
- //Making the Playlist submenu
- act_addToPlaylist = new QAction(tr("Add to playlist"),this);
- //Making the videoMenu
- men_videoMenu = new QMenu("VideoMenu",this);
- men_videoMenu->addAction(act_Play);
- men_videoMenu->addAction(act_Pause);
- men_videoMenu->addAction(act_Stop);
- men_videoMenu->addSeparator();
- men_videoMenu->addAction(act_VolumeSetting);
- men_videoMenu->addSeparator();
- // men_videoMenu->addMenu("men_playlistMenu");
- men_videoMenu->addSeparator();
- men_videoMenu->addAction(act_Quit);
- }
- //Setup and making of widgets en connections
- void phononVideoPlayer::setupWidgets()
- {
- //phonon
- obj_MediaObject = new Phonon::MediaObject(this);
- wid_videoWidget = new Phonon::VideoWidget(this);
- wid_videoWidget->resize(this->size());
- //volumeslider
- volumeSlider = new QSlider(this);
- volumeSlider->setRange(0,100);
- volumeSlider->setOrientation(Qt::Horizontal);
- volumeSlider->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
- volumeSlider->hide();
- }
- void phononVideoPlayer::setupConnections()
- {
- //connect the VolumeSlider
- connect(volumeSlider,SIGNAL(valueChanged(int)),this,SLOT(changeVolume()));
- }
- //Play video functions
- int phononVideoPlayer::playVideo(QString filename)
- {
- obj_MediaObject->clearQueue ();
- obj_MediaObject->enqueue(Phonon::MediaSource(filename));
- //var_MediaObject->setCurrentSource(filename); //is also possible
- Phonon::createPath(obj_MediaObject, wid_videoWidget);
- aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
- Phonon::createPath(obj_MediaObject, aio_audioOutput);
- obj_MediaObject->play();
- return 0;
- }
- //Resize functions
- void phononVideoPlayer::resizeEvent(QResizeEvent *event)
- {
- wid_videoWidget->resize(this->size());
- }
- //mouse handling functions
- void phononVideoPlayer::mousePressEvent(QMouseEvent *event)
- {
- if (event->button() == Qt::RightButton)
- {
- globalPos = wid_videoWidget->mapToGlobal(event->pos());
- men_videoMenu->exec( globalPos );
- }
- if (event->button() == Qt::LeftButton)
- {
- /* werkt maar doe ik nog niets mee
- Qt::WindowFlags flags = windowFlags();
- flags &= ~Qt::FramelessWindowHint;
- setWindowFlags(flags);
- this->show();
- */
- }
- }
- void phononVideoPlayer::mouseDoubleClickEvent(QMouseEvent *event)
- {
- if (event->button() == Qt::RightButton)
- {}
- if (event->button() == Qt::LeftButton)
- {}
- }
- //Slots & Signals
- void phononVideoPlayer::showVolumeSlider() //called by menuaction "VolumeSetting"
- {
- //Not in setup because aio_audioOutput is set later on when
- //connecting with the videosource:
- volumeSlider->setValue(aio_audioOutput->volume()*100);
- //not in setup because globalPos is set later in the menu call:
- volumeSlider->setGeometry(globalPos.x(),globalPos.y()+85,50,8);
- volumeSlider->show();
- }
- void phononVideoPlayer::changeVolume()
- {
- float volume = float(volumeSlider->value())/100.0;
- aio_audioOutput->setVolume(volume);
- connect(volumeSlider,SIGNAL(sliderReleased()),volumeSlider,SLOT(hide()));
- }
- //Destruct fuctions
- phononVideoPlayer::~phononVideoPlayer()
- {
- obj_MediaObject->stop();
- obj_MediaObject->clearQueue();
- delete ui;
- }
Advertisement
Add Comment
Please, Sign In to add comment