| 1 | /* smplayer, GUI front-end for mplayer.
|
|---|
| 2 | Copyright (C) 2006-2008 Ricardo Villalba <[email protected]>
|
|---|
| 3 |
|
|---|
| 4 | This program is free software; you can redistribute it and/or modify
|
|---|
| 5 | it under the terms of the GNU General Public License as published by
|
|---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
|---|
| 7 | (at your option) any later version.
|
|---|
| 8 |
|
|---|
| 9 | This program is distributed in the hope that it will be useful,
|
|---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 12 | GNU General Public License for more details.
|
|---|
| 13 |
|
|---|
| 14 | You should have received a copy of the GNU General Public License
|
|---|
| 15 | along with this program; if not, write to the Free Software
|
|---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|---|
| 17 | */
|
|---|
| 18 |
|
|---|
| 19 | #include "test.h"
|
|---|
| 20 | #include "smplayercorelib.h"
|
|---|
| 21 | #include "helper.h"
|
|---|
| 22 | #include "global.h"
|
|---|
| 23 | #include <QAction>
|
|---|
| 24 | #include <QMenuBar>
|
|---|
| 25 | #include <QToolBar>
|
|---|
| 26 | #include "timeslider.h"
|
|---|
| 27 | #include <QFileDialog>
|
|---|
| 28 |
|
|---|
| 29 | #include <QApplication>
|
|---|
| 30 |
|
|---|
| 31 | Gui::Gui( QWidget * parent, Qt::WindowFlags flags )
|
|---|
| 32 | : QMainWindow(parent, flags)
|
|---|
| 33 | {
|
|---|
| 34 | smplayerlib = new SmplayerCoreLib(this);
|
|---|
| 35 | core = smplayerlib->core();
|
|---|
| 36 | setCentralWidget(smplayerlib->mplayerWindow());
|
|---|
| 37 |
|
|---|
| 38 | QAction * openAct = new QAction( tr("&Open..."), this);
|
|---|
| 39 | connect( openAct, SIGNAL(triggered()), this, SLOT(open()) );
|
|---|
| 40 |
|
|---|
| 41 | QAction * closeAct = new QAction( tr("&Close"), this);
|
|---|
| 42 | connect( closeAct, SIGNAL(triggered()), this, SLOT(close()) );
|
|---|
| 43 |
|
|---|
| 44 | QMenu * open_menu = menuBar()->addMenu( tr("&Open") );
|
|---|
| 45 | open_menu->addAction(openAct);
|
|---|
| 46 | open_menu->addAction(closeAct);
|
|---|
| 47 |
|
|---|
| 48 | QAction * playAct = new QAction( tr("&Play/Pause"), this);
|
|---|
| 49 | playAct->setShortcut( Qt::Key_Space );
|
|---|
| 50 | connect( playAct, SIGNAL(triggered()),
|
|---|
| 51 | core, SLOT(play_or_pause()) );
|
|---|
| 52 |
|
|---|
| 53 | QAction * stopAct = new QAction( tr("&Stop"), this);
|
|---|
| 54 | connect( stopAct, SIGNAL(triggered()),
|
|---|
| 55 | core, SLOT(stop()) );
|
|---|
| 56 |
|
|---|
| 57 | QMenu * play_menu = menuBar()->addMenu( tr("&Play") );
|
|---|
| 58 | play_menu->addAction(playAct);
|
|---|
| 59 | play_menu->addAction(stopAct);
|
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 | TimeSlider * time_slider = new TimeSlider(this);
|
|---|
| 63 | connect( time_slider, SIGNAL(posChanged(int)),
|
|---|
| 64 | core, SLOT(goToPos(int)) );
|
|---|
| 65 | connect( core, SIGNAL(posChanged(int)),
|
|---|
| 66 | time_slider, SLOT(setPos(int)) );
|
|---|
| 67 |
|
|---|
| 68 | QToolBar * control = new QToolBar( tr("Control"), this);
|
|---|
| 69 | control->addAction(playAct);
|
|---|
| 70 | control->addAction(stopAct);
|
|---|
| 71 | control->addSeparator();
|
|---|
| 72 | control->addWidget(time_slider);
|
|---|
| 73 |
|
|---|
| 74 | addToolBar(Qt::BottomToolBarArea, control);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | Gui::~Gui() {
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | void Gui::closeEvent( QCloseEvent * event ) {
|
|---|
| 81 | core->stop();
|
|---|
| 82 | event->accept();
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void Gui::open() {
|
|---|
| 86 | QString f = QFileDialog::getOpenFileName( this, tr("Open file") );
|
|---|
| 87 |
|
|---|
| 88 | if (!f.isEmpty()) {
|
|---|
| 89 | core->open(f);
|
|---|
| 90 | }
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | int main( int argc, char ** argv ) {
|
|---|
| 94 | QApplication a( argc, argv );
|
|---|
| 95 | a.connect( &a, SIGNAL( lastWindowClosed() ), &a, SLOT( quit() ) );
|
|---|
| 96 |
|
|---|
| 97 | Helper::setAppPath( qApp->applicationDirPath() );
|
|---|
| 98 | Global::global_init();
|
|---|
| 99 |
|
|---|
| 100 | Gui * w = new Gui();
|
|---|
| 101 | w->show();
|
|---|
| 102 |
|
|---|
| 103 | int r = a.exec();
|
|---|
| 104 | Global::global_end();
|
|---|
| 105 |
|
|---|
| 106 | return r;
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | #include "moc_test.cpp"
|
|---|