Exemplo n.º 1
0
void ofApp::keyPressed(int key){
    if(key == ' ') {
        togglePlaying();
    } else if(key == '[') {
        togglePlaying();
        note--;
        togglePlaying();
    } else if(key == ']') {
        togglePlaying();
        note++;
        togglePlaying();
    } else {
        manager.keyPressed(key);
    }
}
Exemplo n.º 2
0
void StateWidget::mouseReleaseEvent( QMouseEvent* )
{
    if( m_holdtimer->isActive() ) {
        togglePlaying();
        m_holdtimer->stop();
    }
}
Exemplo n.º 3
0
void StateWidget::keyPressEvent( QKeyEvent* e )
{
    switch( e->key() )
    {
    case Qt::Key_Select:
        e->accept();
        togglePlaying();
        break;
    case KEY_SELECT_HOLD:
        e->accept();
        setStopped();
        break;
    default:
        QWidget::keyPressEvent(e);
        break;
    }
}
Exemplo n.º 4
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    m_fileMenu(new QMenu(tr("&File"), this)),
    m_viewMenu(new QMenu(tr("&View"), this)),
    m_playbackMenu(new QMenu(tr("&Playback"), this)),
    m_transfersMenu(new QMenu(tr("&Downloads"), this)),
    m_editMenu(new QMenu(tr("&Edit"), this)),
    m_helpMenu(new QMenu(tr("&About"), this)),
    m_openFilesAction(new QAction(QIcon::fromTheme("document-open"), tr("&Open files"), this)),
    m_openUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Open &URL"), this)),
    m_addFilesAction(new QAction(QIcon::fromTheme("list-add"), tr("&Add files"), this)),
    m_addUrlAction(new QAction(QIcon::fromTheme("folder-remote"), tr("Add &URL"), this)),
    m_searchAction(new QAction(QIcon::fromTheme("edit-find"), tr("&Search"), this)),
    m_pluginsAction(new QAction(QIcon::fromTheme("view-refresh"), tr("Load &plugins"), this)),
    m_quitAction(new QAction(QIcon::fromTheme("application-exit"), tr("&Quit"), this)),
    m_showPlaybackQueueAction(new QAction(QIcon::fromTheme("music-library"), tr("Show &playback queue"), this)),
    m_showTransfersAction(new QAction(QIcon::fromTheme("folder-publicshare"), tr("Show &transfers"), this)),
    m_reloadAction(new QAction(QIcon::fromTheme("view-refresh"), tr("&Reload current tab"), this)),
    m_closeAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Close current tab"), this)),
    m_playPauseAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Play"), this)),
    m_stopAction(new QAction(QIcon::fromTheme("media-playback-stop"), tr("&Stop"), this)),
    m_previousAction(new QAction(QIcon::fromTheme("media-skip-backward"), tr("&Previous"), this)),
    m_nextAction(new QAction(QIcon::fromTheme("media-skip-forward"), tr("&Next"), this)),
    m_repeatAction(new QAction(QIcon::fromTheme("media-playlist-repeat"), tr("&Repeat"), this)),
    m_shuffleAction(new QAction(QIcon::fromTheme("media-playlist-shuffle"), tr("&Shuffle"), this)),
    m_stopAfterCurrentAction(new QAction(tr("Stop &after current track"), this)),
    m_clearAction(new QAction(QIcon::fromTheme("list-remove"), tr("&Clear playback queue"), this)),
    m_startTransfersAction(new QAction(QIcon::fromTheme("media-playback-start"), tr("&Start transfers"), this)),
    m_pauseTransfersAction(new QAction(QIcon::fromTheme("media-playback-pause"), tr("&Pause transfers"), this)),
    m_settingsAction(new QAction(QIcon::fromTheme("preferences-desktop"), tr("&Preferences"), this)),
    m_aboutAction(new QAction(QIcon::fromTheme("help-about"), tr("&About"), this)),
    m_positionSpacer(new QWidget(this)),
    m_positionSpacerAction(0),
    m_positionSlider(new QSlider(Qt::Horizontal, this)),
    m_positionSliderAction(0),
    m_positionLabel(new QLabel(this)),
    m_positionLabelAction(0),
    m_toolBar(new QToolBar(this)),
    m_widget(new QWidget(this)),
    m_tabWidget(new QTabWidget(m_widget)),
    m_nowPlayingMetaData(new ItemMetaData(m_widget)),
    m_layout(new QVBoxLayout(m_widget))
{
    setWindowTitle("MusiKloud2");
    
    // Initialise status bar
    statusBar();
    
    // Add menus
    menuBar()->addMenu(m_fileMenu);
    menuBar()->addMenu(m_viewMenu);
    menuBar()->addMenu(m_playbackMenu);
    menuBar()->addMenu(m_transfersMenu);
    menuBar()->addMenu(m_editMenu);
    menuBar()->addMenu(m_helpMenu);
    
    // Setup file menu
    m_fileMenu->addAction(m_openFilesAction);
    m_fileMenu->addAction(m_openUrlAction);
    m_fileMenu->addAction(m_addFilesAction);
    m_fileMenu->addAction(m_addUrlAction);
    m_fileMenu->addAction(m_searchAction);
    m_fileMenu->addSeparator();
    m_fileMenu->addAction(m_pluginsAction);
    m_fileMenu->addAction(m_quitAction);
    
    // Setup file menu actions
    m_openFilesAction->setShortcut(tr("Ctrl+O"));
    m_openUrlAction->setShortcut(tr("Ctrl+U"));
    m_addFilesAction->setShortcut(tr("Ctrl+Shift+O"));
    m_addUrlAction->setShortcut(tr("Ctrl+Shift+U"));
    m_searchAction->setShortcut(tr("Ctrl+Y"));
    m_pluginsAction->setShortcut(tr("Ctrl+L"));
    m_quitAction->setShortcut(tr("Ctrl+Q"));
    
    // Setup view menu
    m_viewMenu->addAction(m_showPlaybackQueueAction);
    m_viewMenu->addAction(m_showTransfersAction);
    m_viewMenu->addSeparator();
    m_viewMenu->addAction(m_reloadAction);
    m_viewMenu->addAction(m_closeAction);
    
    // Setup view menu actions
    m_reloadAction->setEnabled(false);
    m_closeAction->setShortcut(tr("Ctrl+W"));
    m_closeAction->setEnabled(false);
    
    // Setup playback menu
    m_playbackMenu->addAction(m_playPauseAction);
    m_playbackMenu->addAction(m_stopAction);
    m_playbackMenu->addAction(m_previousAction);
    m_playbackMenu->addAction(m_nextAction);
    m_playbackMenu->addSeparator();
    m_playbackMenu->addAction(m_repeatAction);
    m_playbackMenu->addAction(m_shuffleAction);
    m_playbackMenu->addAction(m_stopAfterCurrentAction);
    m_playbackMenu->addSeparator();
    m_playbackMenu->addAction(m_clearAction);
    
    // Setup playback menu actions
    m_playPauseAction->setShortcut(tr("Ctrl+Return"));
    m_stopAction->setShortcut(tr("Ctrl+."));
    m_previousAction->setShortcut(tr("Alt+Up"));
    m_nextAction->setShortcut(tr("Alt+Down"));
    m_repeatAction->setCheckable(true);
    m_repeatAction->setShortcut(tr("Ctrl+R"));
    m_repeatAction->setToolTip(tr("Toggle repeat playback mode"));
    m_shuffleAction->setCheckable(true);
    m_shuffleAction->setShortcut(tr("Ctrl+S"));
    m_shuffleAction->setToolTip(tr("Toggle shuffle playback mode"));
    m_stopAfterCurrentAction->setCheckable(true);
    m_clearAction->setShortcut(tr("Ctrl+Shift+X"));
    
    // Setup transfers menu
    m_transfersMenu->addAction(m_startTransfersAction);
    m_transfersMenu->addAction(m_pauseTransfersAction);
    
    // Setup edit menu
    m_editMenu->addAction(m_settingsAction);
    
    // Setup edit menu actions
    m_settingsAction->setShortcut(tr("Ctrl+P"));
    
    // Setup help menu
    m_helpMenu->addAction(m_aboutAction);

    // Setup toolbar
    m_toolBar->setObjectName("mainToolBar");
    m_toolBar->setWindowTitle(tr("Main toolbar"));
    m_toolBar->setMovable(false);
    m_toolBar->setAllowedAreas(Qt::TopToolBarArea);
    m_toolBar->addAction(m_openFilesAction);
    m_toolBar->addAction(m_addFilesAction);
    m_toolBar->addAction(m_searchAction);
    m_toolBar->addAction(m_previousAction);
    m_toolBar->addAction(m_nextAction);
    m_toolBar->addAction(m_playPauseAction);
    m_toolBar->addAction(m_stopAction);
    m_positionSpacerAction = m_toolBar->addWidget(m_positionSpacer);
    m_positionSliderAction = m_toolBar->addWidget(m_positionSlider);
    m_positionLabelAction = m_toolBar->addWidget(m_positionLabel);
    m_toolBar->addAction(m_repeatAction);
    m_toolBar->addAction(m_shuffleAction);
    addToolBar(Qt::TopToolBarArea, m_toolBar);
    
    // Setup position spacer, slider and label
    m_positionSpacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_positionSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    m_positionSliderAction->setVisible(false);
    m_positionLabel->setFixedWidth(m_positionLabel->fontMetrics().width("000:00 / 000:00"));
    m_positionLabel->setAlignment(Qt::AlignCenter);
    m_positionLabelAction->setVisible(false);
    
    // Setup tab widget
    m_tabWidget->setTabsClosable(true);
    m_tabWidget->tabBar()->setSelectionBehaviorOnRemove(QTabBar::SelectLeftTab);
    m_tabWidget->tabBar()->setExpanding(false);
    
    // Setup now playing metadata
    m_nowPlayingMetaData->setStyleSheet("font-weight: bold");
    m_nowPlayingMetaData->setThumbnailSize(QSize(96, 96));
    m_nowPlayingMetaData->hide();
    
    // Setup layout
    m_layout->addWidget(m_tabWidget);
    m_layout->addWidget(m_nowPlayingMetaData);
    m_layout->setContentsMargins(0, 0, 0, 0);
    setCentralWidget(m_widget);
    
    // Restore window geometry/state
    restoreGeometry(Settings::mainWindowGeometry());
    restoreState(Settings::mainWindowState());
    
    // Connect signals and slots
    connect(AudioPlayer::instance(), SIGNAL(durationChanged(qint64)), this, SLOT(onPlayerDurationChanged(qint64)));
    connect(AudioPlayer::instance(), SIGNAL(metaDataChanged()), this, SLOT(updateNowPlayingMetaData()));
    connect(AudioPlayer::instance(), SIGNAL(positionChanged(qint64)), this, SLOT(onPlayerPositionChanged(qint64)));
    connect(AudioPlayer::instance(), SIGNAL(seekableChanged(bool)), this, SLOT(onPlayerSeekableChanged(bool)));
    connect(AudioPlayer::instance(), SIGNAL(statusChanged(AudioPlayer::Status)),
            this, SLOT(onPlayerStatusChanged(AudioPlayer::Status)));
    connect(m_openFilesAction, SIGNAL(triggered()), this, SLOT(openFiles()));
    connect(m_openUrlAction, SIGNAL(triggered()), this, SLOT(openUrl()));
    connect(m_addFilesAction, SIGNAL(triggered()), this, SLOT(addFiles()));
    connect(m_addUrlAction, SIGNAL(triggered()), this, SLOT(addUrl()));
    connect(m_searchAction, SIGNAL(triggered()), this, SLOT(search()));
    connect(m_pluginsAction, SIGNAL(triggered()), this, SLOT(loadPlugins()));
    connect(m_quitAction, SIGNAL(triggered()), this, SLOT(close()));
    connect(m_showPlaybackQueueAction, SIGNAL(triggered()), this, SLOT(showPlaybackQueue()));
    connect(m_showTransfersAction, SIGNAL(triggered()), this, SLOT(showTransfers()));
    connect(m_reloadAction, SIGNAL(triggered()), this, SLOT(reloadCurrentTab()));
    connect(m_closeAction, SIGNAL(triggered()), this, SLOT(closeCurrentTab()));
    connect(m_playPauseAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(togglePlaying()));
    connect(m_stopAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(stop()));
    connect(m_previousAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(previous()));
    connect(m_nextAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(next()));
    connect(m_repeatAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setRepeatEnabled(bool)));
    connect(m_shuffleAction, SIGNAL(triggered(bool)), AudioPlayer::instance(), SLOT(setShuffleEnabled(bool)));
    connect(m_stopAfterCurrentAction, SIGNAL(triggered(bool)),
            AudioPlayer::instance(), SLOT(setStopAfterCurrentTrack(bool)));
    connect(m_clearAction, SIGNAL(triggered()), AudioPlayer::instance(), SLOT(clearQueue()));
    connect(m_startTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(start()));
    connect(m_pauseTransfersAction, SIGNAL(triggered()), Transfers::instance(), SLOT(pause()));
    connect(m_settingsAction, SIGNAL(triggered()), this, SLOT(showSettingsDialog()));
    connect(m_aboutAction, SIGNAL(triggered()), this, SLOT(showAboutDialog()));
    connect(m_positionSlider, SIGNAL(sliderReleased()), this, SLOT(updatePlayerPosition()));
    connect(m_positionSlider, SIGNAL(valueChanged(int)), this, SLOT(onSliderValueChanged(int)));
    connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(onTabStatusChanged()));
    connect(m_tabWidget, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
}