MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent),
	m_ui(new Ui::MainWindow),
	m_currentSubtitle(0),
	m_currentTrack(0)
{
	m_subtitles.append(QList<Subtitle>());
	m_subtitles.append(QList<Subtitle>());

	m_ui->setupUi(this);

	Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(this);
	audioOutput->setVolume(QSettings().value("volume", 0.8).toReal());

	m_mediaObject = new Phonon::MediaObject(this);
	m_mediaObject->setTickInterval(100);

	Phonon::createPath(m_mediaObject, m_ui->videoWidget);
	Phonon::createPath(m_mediaObject, audioOutput);

	m_ui->actionPlayPause->setIcon(QIcon::fromTheme("media-playback-start", style()->standardIcon(QStyle::SP_MediaPlay)));
	m_ui->actionPlayPause->setShortcut(tr("Space"));
	m_ui->actionPlayPause->setDisabled(true);

	m_ui->actionStop->setIcon(QIcon::fromTheme("media-playback-stop", style()->standardIcon(QStyle::SP_MediaStop)));
	m_ui->actionStop->setDisabled(true);

	m_fileNameLabel = new QLabel(tr("No file loaded"), this);
	m_fileNameLabel->setMaximumWidth(300);
	m_timeLabel = new QLabel("00:00.0 / 00:00.0", this);

	m_ui->actionOpen->setIcon(QIcon::fromTheme("document-open", style()->standardIcon(QStyle::SP_DirOpenIcon)));
	m_ui->actionSave->setIcon(QIcon::fromTheme("document-save", style()->standardIcon(QStyle::SP_DialogSaveButton)));
	m_ui->actionSaveAs->setIcon(QIcon::fromTheme("document-save-as"));
	m_ui->actionExit->setIcon(QIcon::fromTheme("application-exit", style()->standardIcon(QStyle::SP_DialogCloseButton)));
	m_ui->actionAdd->setIcon(QIcon::fromTheme("list-add"));
	m_ui->actionRemove->setIcon(QIcon::fromTheme("list-remove"));
	m_ui->actionPrevious->setIcon(QIcon::fromTheme("go-previous"));
	m_ui->actionNext->setIcon(QIcon::fromTheme("go-next"));
	m_ui->actionRescale->setIcon(QIcon::fromTheme("chronometer"));
	m_ui->actionAboutApplication->setIcon(QIcon::fromTheme("help-about"));
	m_ui->playPauseButton->setDefaultAction(m_ui->actionPlayPause);
	m_ui->stopButton->setDefaultAction(m_ui->actionStop);
	m_ui->addButton->setDefaultAction(m_ui->actionAdd);
	m_ui->removeButton->setDefaultAction(m_ui->actionRemove);
	m_ui->previousButton->setDefaultAction(m_ui->actionPrevious);
	m_ui->nextButton->setDefaultAction(m_ui->actionNext);
	m_ui->seekSlider->setMediaObject(m_mediaObject);
	m_ui->volumeSlider->setAudioOutput(audioOutput);
	m_ui->statusBar->addPermanentWidget(m_fileNameLabel);
	m_ui->statusBar->addPermanentWidget(m_timeLabel);

	resize(QSettings().value("Window/size", size()).toSize());
	move(QSettings().value("Window/position", pos()).toPoint());
	restoreState(QSettings().value("Window/state", QByteArray()).toByteArray());

	setWindowTitle(tr("%1 - Unnamed").arg("Subtitles Editor"));

	connect(m_ui->actionOpen, SIGNAL(triggered()), this, SLOT(actionOpen()));
	connect(m_ui->actionSave, SIGNAL(triggered()), this, SLOT(actionSave()));
	connect(m_ui->actionSaveAs, SIGNAL(triggered()), this, SLOT(actionSaveAs()));
	connect(m_ui->actionExit, SIGNAL(triggered()), this, SLOT(close()));
	connect(m_ui->actionAdd, SIGNAL(triggered()), this, SLOT(addSubtitle()));
	connect(m_ui->actionRemove, SIGNAL(triggered()), this, SLOT(removeSubtitle()));
	connect(m_ui->actionPrevious, SIGNAL(triggered()), this, SLOT(previousSubtitle()));
	connect(m_ui->actionNext, SIGNAL(triggered()), this, SLOT(nextSubtitle()));
	connect(m_ui->actionRescale, SIGNAL(triggered()), this, SLOT(rescaleSubtitles()));
	connect(m_ui->actionPlayPause, SIGNAL(triggered()), this, SLOT(playPause()));
	connect(m_ui->actionStop, SIGNAL(triggered()), m_mediaObject, SLOT(stop()));
	connect(m_ui->actionAboutQt, SIGNAL(triggered()), QApplication::instance(), SLOT(aboutQt()));
	connect(m_ui->actionAboutApplication, SIGNAL(triggered()), this, SLOT(actionAboutApplication()));
	connect(m_ui->trackComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(selectTrack(int)));
	connect(m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)), this, SLOT(stateChanged(Phonon::State)));
	connect(m_mediaObject, SIGNAL(tick(qint64)), this, SLOT(tick()));
	connect(m_mediaObject, SIGNAL(finished()), this, SLOT(finished()));
}
示例#2
0
FramelessMainWindow::FramelessMainWindow( QWidget *parent ) :
   QMainWindow( parent ),
   m_scene( new QGraphicsScene( this ) ),
   m_browser( new GraphicsBrowser( m_scene, *this ) ),
   m_mouseFilter( *this, *qApp ),
   m_video( new EventfulVidgetVideo( this ) ),
   m_intro( new QGraphicsScene ),
   m_control( new VideoControl( this ) ),
   m_closeControl( new QFrame( this ) ),
   m_hostApp( new HostApp( m_browser->webView(), this ) )
{
    m_video->hide();
    m_control->hide();
    m_browser->webView()->page()->settings()->setAttribute( QWebSettings::JavascriptCanOpenWindows, true );

    m_control->setVolume( m_hostApp->getVolume() );

    m_closeControl->hide();
    m_closeControl->setStyleSheet( "QFrame{background-color:black; } "
                                   "QPushButton { background-image: url(':/close-styled'); width:31;} "
                                   "QWidget{border:none; padding:0; spacing:0; height:30;}" );
    QHBoxLayout *hl = new QHBoxLayout( m_closeControl );
    hl->setContentsMargins( QMargins() );
    hl->addSpacerItem( new QSpacerItem( 0, 0, QSizePolicy::Expanding, QSizePolicy::Minimum ) );

    m_closeButton = new QPushButton();
    m_closeButton->setCursor( Qt::PointingHandCursor );
//  btn->setFlat( true );
    hl->addWidget( m_closeButton );
    connect( m_control, SIGNAL( uiShow() ), m_closeButton, SLOT( show() ) );
    connect( m_control, SIGNAL( uiHide() ), m_closeButton, SLOT( hide() ) );


    setWindowTitle( "Popcorn Time" );
    m_intro->addPixmap( QPixmap( ":/intro" ).scaled( DEFAULT_WIDTH, DEFAULT_HEIGHT, Qt::IgnoreAspectRatio ) );
    m_browser->setScene( m_intro );
    new QShortcut( QKeySequence( "Ctrl+M" ), this, SLOT( minimize() ) );

    QObject::connect( m_hostApp->thread(), SIGNAL( torrentUrlAvailable( QString ) ),
                      this, SLOT( playMedia( QString ) ) );
    QObject::connect( m_browser->webView(), SIGNAL( loadFinished( bool ) ),
                      this, SLOT( removeIntro() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedClose() ),
                      this, SLOT( close() ) );
    QObject::connect( m_hostApp, SIGNAL( commandedMinimize() ),
                      this, SLOT( minimize() ) );
    QObject::connect( m_hostApp, SIGNAL( toggledMaximize() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( m_hostApp, SIGNAL( haveSubtitles( SubtitleItem ) ),
                      m_control, SLOT( addSubtitle( SubtitleItem ) ) );
    QObject::connect( m_hostApp, SIGNAL( downloadInfoChanged( DownloadInfo ) ),
                      m_control, SLOT( updateDownloadStatus( DownloadInfo ) ) );
    QObject::connect( m_control, SIGNAL( volumeChanged( int ) ),
                      m_hostApp, SLOT( setVolume( int ) ) );

    QObject::connect( m_control, SIGNAL( newImage( QString ) ),
                      m_video, SLOT( setImage( QString ) ) );

    QObject::connect( m_control->fullscreenButton(), SIGNAL( clicked() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( enterPressed() ),
                      this, SLOT( toggleMaximize() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( upPressed() ),
                      m_control, SLOT( volumeUp() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( downPressed() ),
                      m_control, SLOT( volumeDown() ) );
    QObject::connect( &m_mouseFilter, SIGNAL( pausePressed() ),
                      m_control, SLOT( pauseToggleReq() ) );

    connect( m_video, SIGNAL( mouseEnter() ), m_control, SLOT( showForDefaultPeriod() ) );

    this->setWindowFlags( Qt::FramelessWindowHint | Qt::WindowMinimizeButtonHint );
#ifdef Q_OS_MAC
    fixNativeWindow( this );
#endif
    this->setMinimumSize( 800, 330 );
    this->setMouseTracking( true );
    this->setCentralWidget( m_browser );
    qApp->installEventFilter( this );

    reconnectMediaPlayer();

    QObject::connect( VLC::VLCObject(), SIGNAL( mediaPlayerReplaced() ),
                      this, SLOT( reconnectMediaPlayer() ) );
}