zondoran

Untitled

Apr 18th, 2011
311
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "phononvideoplayer.h"
  2. #include "ui_phononvideoplayer.h"
  3.  
  4. phononVideoPlayer::phononVideoPlayer(QWidget *parent) :
  5.     QWidget(parent),
  6.     ui(new Ui::phononVideoPlayer)
  7. {
  8.     ui->setupUi(this);
  9.     setupLook();
  10.     setupWidgets();
  11.     setupConnections();
  12.     setupMenus();
  13.  
  14.  
  15.  
  16.     playVideo("pathto/MrTambourineman.mp4"); //works
  17. }
  18.  
  19. void phononVideoPlayer::setupLook()
  20. {
  21.     //Window status
  22. //   setWindowFlags(Qt::FramelessWindowHint);  //window without borders
  23.  
  24.     //Mouse
  25.  
  26.     //icons
  27.     QIcon icon(QIcon(":/icon/mainicon"));
  28.     setWindowIcon(icon);
  29.         //Tray
  30.     QSystemTrayIcon *trayIcon = new QSystemTrayIcon(this);
  31.     trayIcon->setIcon(icon);
  32.     trayIcon->setVisible(true);
  33. }
  34.  
  35.  
  36. void phononVideoPlayer::setupMenus()
  37. {
  38.     //Quit Action, makes the app quit.
  39.     act_Quit = new QAction(tr("Quit"),this);
  40.     act_Quit->setIcon(QIcon(":/icon/quit"));
  41.     act_Quit->setIconVisibleInMenu(true);
  42.     connect(act_Quit,SIGNAL(triggered()),this,SLOT(close()));
  43.  
  44.     //Pause Action, makes the video pause.
  45.     act_Pause = new QAction(tr("Pause"),this);
  46.     act_Pause->setIcon(QIcon(":/icon/pause"));
  47.     act_Pause->setIconVisibleInMenu(true);
  48.     connect(act_Pause,SIGNAL(triggered()),obj_MediaObject,SLOT(pause()));
  49.  
  50.     //Play Action, makes the video play.
  51.     act_Play = new QAction(tr("Play"),this);
  52.     act_Play->setIcon(QIcon(":/icon/play"));
  53.     act_Play->setIconVisibleInMenu(true);
  54.     connect(act_Play,SIGNAL(triggered()),obj_MediaObject,SLOT(play()));
  55.  
  56.     //Stop Action, makes the video stop.
  57.     act_Stop = new QAction(tr("Stop"),this);
  58.     act_Stop->setIcon(QIcon(":/icon/stop"));
  59.     act_Stop->setIconVisibleInMenu(true);
  60.     connect(act_Stop,SIGNAL(triggered()),obj_MediaObject,SLOT(stop()));
  61.  
  62.     //VolumeSetting Action, shows a volume slider to set the volume for the video
  63.     act_VolumeSetting = new QAction(tr("Volume Setting"),this);
  64.     act_VolumeSetting->setIcon(QIcon(":/icon/volume"));
  65.     act_VolumeSetting->setIconVisibleInMenu(true);
  66.     connect(act_VolumeSetting,SIGNAL(triggered()),this,SLOT(showVolumeSlider()));
  67.  
  68.     //Making the Playlist submenu
  69.     act_addToPlaylist = new QAction(tr("Add to playlist"),this);
  70.  
  71.  
  72.  
  73.     //Making the videoMenu
  74.     men_videoMenu = new QMenu("VideoMenu",this);
  75.     men_videoMenu->addAction(act_Play);
  76.     men_videoMenu->addAction(act_Pause);
  77.     men_videoMenu->addAction(act_Stop);
  78.     men_videoMenu->addSeparator();
  79.     men_videoMenu->addAction(act_VolumeSetting);
  80.     men_videoMenu->addSeparator();
  81.   //  men_videoMenu->addMenu("men_playlistMenu");
  82.     men_videoMenu->addSeparator();
  83.     men_videoMenu->addAction(act_Quit);
  84. }
  85.  
  86. //Setup and making of widgets en connections
  87.  
  88. void phononVideoPlayer::setupWidgets()
  89. {
  90.     //phonon
  91.     obj_MediaObject = new Phonon::MediaObject(this);
  92.     wid_videoWidget = new Phonon::VideoWidget(this);
  93.     wid_videoWidget->resize(this->size());
  94.  
  95.     //volumeslider
  96.     volumeSlider = new QSlider(this);
  97.     volumeSlider->setRange(0,100);
  98.     volumeSlider->setOrientation(Qt::Horizontal);
  99.     volumeSlider->setWindowFlags(Qt::Popup | Qt::FramelessWindowHint);
  100.     volumeSlider->hide();
  101. }
  102.  
  103. void phononVideoPlayer::setupConnections()
  104. {
  105.  
  106.     //connect the VolumeSlider
  107.     connect(volumeSlider,SIGNAL(valueChanged(int)),this,SLOT(changeVolume()));
  108. }
  109.  
  110. //Play video functions
  111. int phononVideoPlayer::playVideo(QString filename)
  112. {
  113.     obj_MediaObject->clearQueue ();
  114.     obj_MediaObject->enqueue(Phonon::MediaSource(filename));
  115.     //var_MediaObject->setCurrentSource(filename); //is also possible
  116.  
  117.     Phonon::createPath(obj_MediaObject, wid_videoWidget);
  118.     aio_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory,this);
  119.     Phonon::createPath(obj_MediaObject, aio_audioOutput);
  120.     obj_MediaObject->play();
  121.  
  122.     return 0;
  123. }
  124.  
  125. //Resize functions
  126. void phononVideoPlayer::resizeEvent(QResizeEvent *event)
  127. {
  128.       wid_videoWidget->resize(this->size());
  129. }
  130.  
  131. //mouse handling functions
  132. void phononVideoPlayer::mousePressEvent(QMouseEvent *event)
  133. {
  134.     if (event->button() == Qt::RightButton)
  135.     {
  136.         globalPos = wid_videoWidget->mapToGlobal(event->pos());
  137.         men_videoMenu->exec( globalPos );
  138.     }
  139.     if (event->button() == Qt::LeftButton)
  140.     {
  141.  
  142.        /* werkt maar doe ik nog niets mee
  143.         Qt::WindowFlags flags = windowFlags();
  144.         flags &= ~Qt::FramelessWindowHint;
  145.         setWindowFlags(flags);
  146.         this->show();
  147.       */
  148.     }
  149. }
  150.  
  151. void phononVideoPlayer::mouseDoubleClickEvent(QMouseEvent *event)
  152. {
  153.     if (event->button() == Qt::RightButton)
  154.     {}
  155.     if (event->button() == Qt::LeftButton)
  156.     {}
  157.  
  158. }
  159.  
  160.  
  161.  
  162.  
  163.  
  164. //Slots & Signals
  165. void phononVideoPlayer::showVolumeSlider()         //called by menuaction "VolumeSetting"
  166. {
  167.     //Not in setup because aio_audioOutput is set later on when
  168.     //connecting with the videosource:
  169.     volumeSlider->setValue(aio_audioOutput->volume()*100);
  170.  
  171.     //not in setup because globalPos is set later in the menu call:
  172.     volumeSlider->setGeometry(globalPos.x(),globalPos.y()+85,50,8);
  173.     volumeSlider->show();
  174.  
  175. }
  176.  
  177.  
  178. void phononVideoPlayer::changeVolume()
  179. {
  180.     float volume = float(volumeSlider->value())/100.0;
  181.     aio_audioOutput->setVolume(volume);
  182.     connect(volumeSlider,SIGNAL(sliderReleased()),volumeSlider,SLOT(hide()));
  183. }
  184.  
  185. //Destruct fuctions
  186. phononVideoPlayer::~phononVideoPlayer()
  187. {
  188.     obj_MediaObject->stop();
  189.     obj_MediaObject->clearQueue();
  190.     delete ui;
  191. }
Advertisement
Add Comment
Please, Sign In to add comment