bool Player::eventFilter(QObject *obj, QEvent *e) { static QPoint windowPos, mousePos, dPos; static bool ctrl_pressed = false; //Move window if (obj == ui->titleBar) { QMouseEvent* me = static_cast<QMouseEvent*>(e); if (e->type() == QEvent::MouseButtonPress) { windowPos = pos(); mousePos = me->globalPos(); dPos = mousePos - windowPos; } else if (e->type() == QEvent::MouseMove) move(me->globalPos() - dPos); return false; } // Hide or show progressbar, toolbar and playlist else if (e->type() == QEvent::Enter && obj == ui->toolBar) { ui->progressBar->show(); return true; } else if (e->type() == QEvent::Leave && obj == ui->toolBar) { ui->progressBar->hide(); if (is_fullscreen) { ui->toolBar->hide(); toolbar_visible = false; } return true; } else if (e->type() == QEvent::Leave && obj == playlist) { playlist->hide(); return true; } else if (e->type() == QEvent::MouseMove) { QMouseEvent* me = static_cast<QMouseEvent*>(e); if (is_fullscreen && me->y() > toolbar_pos_y && !toolbar_visible) //mouse enters toolbar { ui->toolBar->show(); toolbar_visible = true; } else if (!is_fullscreen && me->x() > width() - 100) playlist->show(); return true; } //key pressed else if (e->type() == QEvent::KeyRelease) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); if (ke->key() == Qt::Key_Control) { ctrl_pressed = false; return true; } return false; } else if (e->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent*>(e); switch (ke->key()) { case Qt::Key_Control: ctrl_pressed = true; return true; case Qt::Key_S: mplayer->screenShot(); return true; case Qt::Key_C: showCutterbar(); return true; case Qt::Key_Return: setFullScreen(); return true; case Qt::Key_F3: if (!is_fullscreen) hidePlaylist(); return true; case Qt::Key_Space: mplayer->changeState(); return true; case Qt::Key_R: mplayer->speedSetToDefault(); return true; case Qt::Key_Left: if (ctrl_pressed) mplayer->speedDown(); else ui->progressBar->setValue(ui->progressBar->value() - 1); return true; case Qt::Key_Right: if (ctrl_pressed) mplayer->speedUp(); else ui->progressBar->setValue(ui->progressBar->value() + 1); return true; case Qt::Key_Up: ui->volumeSlider->setValue(ui->volumeSlider->value() + 1); return true; case Qt::Key_Down: ui->volumeSlider->setValue(ui->volumeSlider->value() - 1); return true; default:return false; } } return false; }
Player::Player(QWidget *parent) : QWidget(parent), ui(new Ui::Player) { std::cout << "Initialize player..." << std::endl; ui->setupUi(this); //Add MPlayer frame mplayer = new MPlayer; ui->playerLayout->setMargin(0); ui->playerLayout->addWidget(mplayer, 1); //enable autohiding toolbar mplayer->installEventFilter(this); mplayer->setMouseTracking(true); mplayer->getLayer()->installEventFilter(this); mplayer->getLayer()->setMouseTracking(true); ui->toolBar->installEventFilter(this); //move window ui->titleBar->installEventFilter(this); //Add Playlist playlist = new Playlist; ui->playerLayout->addWidget(playlist); //Add Border topLeftBorder = new Border(this, Border::LEFT); topLeftBorder->setObjectName("topLeftBorder"); topRightBorder = new Border(this, Border::RIGHT); topRightBorder->setObjectName("topRightBorder"); ui->titleBarLayout->insertWidget(0, topLeftBorder); ui->titleBarLayout->addWidget(topRightBorder); leftBorder = new Border(this, Border::LEFT); leftBorder->setObjectName("leftBorder"); rightBorder = new Border(this, Border::RIGHT); rightBorder->setObjectName("rightBorder"); bottomBorder = new Border(this, Border::BOTTOM); bottomBorder->setObjectName("bottomBorder"); ui->playerLayout->insertWidget(0, leftBorder); ui->playerLayout->addWidget(rightBorder); ui->mainLayout->addWidget(bottomBorder); //Add WebVideo webvideo = new WebVideo; //add downloader downloader = new Downloader; webvideo->addTab(downloader, tr("Downloader")); //add transformer transformer = new Transformer; //Add menu menubar = new QMenuBar; menu = menubar->addMenu(tr("Player")); menu->addAction(tr("Online video"), webvideo, SLOT(show())); menu->addAction(tr("Transform video"), transformer, SLOT(show())); menu->addAction(tr("Settings"), this, SLOT(onSetButton())); menu->addSeparator(); menu->addAction(tr("Homepage"), this, SLOT(openHomepage())); ui->mainLayout->insertWidget(0, menubar); //Add time show timeShow = new QLabel(mplayer); timeShow->move(0, 0); timeShow->hide(); //Connect connect(ui->playButton, SIGNAL(clicked()), mplayer, SLOT(changeState())); connect(ui->stopButton, SIGNAL(clicked()), this, SLOT(onStopButton())); connect(ui->progressBar, SIGNAL(valueChanged(int)), this, SLOT(onPBarChanged(int))); connect(ui->progressBar, SIGNAL(sliderPressed()), this, SLOT(onPBarPressed())); connect(ui->progressBar, SIGNAL(sliderReleased()), this, SLOT(onPBarReleased())); connect(ui->volumeSlider, SIGNAL(valueChanged(int)), mplayer, SLOT(setVolume(int))); connect(ui->hideButton, SIGNAL(clicked()), this, SLOT(hidePlaylist())); connect(ui->netButton, SIGNAL(clicked()), webvideo, SLOT(show())); connect(ui->closeButton, SIGNAL(clicked()), this, SLOT(close())); connect(ui->minButton, SIGNAL(clicked()), this, SLOT(showMinimized())); connect(ui->maxButton, SIGNAL(clicked()), this, SLOT(setMaxNormal())); connect(ui->menuButton, SIGNAL(clicked()), this, SLOT(showMenu())); connect(mplayer, SIGNAL(played()), this, SLOT(setIconToPause())); connect(mplayer, SIGNAL(paused()), this, SLOT(setIconToPlay())); connect(mplayer, SIGNAL(stopped()), this, SLOT(onStopped())); connect(mplayer, SIGNAL(timeChanged(int)), this, SLOT(onProgressChanged(int))); connect(mplayer, SIGNAL(lengthChanged(int)), this, SLOT(onLengthChanged(int))); connect(mplayer, SIGNAL(fullScreen()), this, SLOT(setFullScreen())); connect(mplayer, SIGNAL(sizeChanged(QSize&)), this, SLOT(onSizeChanged(QSize&))); connect(playlist, SIGNAL(fileSelected(const QString&)), mplayer, SLOT(openFile(const QString&))); connect(playlist, SIGNAL(needPause(bool)), this, SLOT(onNeedPause(bool))); connect(downloader, SIGNAL(newPlay(const QString&,const QString&)), playlist, SLOT(addFileAndPlay(const QString&,const QString&))); connect(downloader, SIGNAL(newFile(const QString&,const QString&)), playlist, SLOT(addFile(const QString&,const QString&))); //Set skin if (Settings::useSkin) setSkin(Settings::skinList[Settings::currentSkin]); else setNoSkin(); no_play_next = false; is_fullscreen = false; }