Added countdown label
[someplayer] / src / playerform.cpp
index fe08eae..9120ee3 100644 (file)
@@ -39,12 +39,13 @@ inline void __fill_list(QStandardItemModel *_model, Playlist playlist) {
        QList<Track> tracks = playlist.tracks();
        int count = tracks.count();
        _model->setRowCount(count);
+       _model->setColumnCount(2);
        QTime time;
        for (int i = 0; i < count; i++) {
                TrackMetadata meta = tracks.at(i).metadata();
                time.setHMS(0, meta.length()/60, meta.length() % 60);
                QString t = meta.title()+"#_#"+meta.artist()+"#_#"+meta.album()+"#_#"+time.toString("mm:ss");
-               _model->setItem(i, 0, new QStandardItem(t));
+               _model->setItem(i, 1, new QStandardItem(t));
        }
 }
 
@@ -80,12 +81,6 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        _fscreen_button->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
        _fscreen_button->hide();
 
-       ui->volumeSlider->setMinimum(0);
-       ui->volumeSlider->setMaximum(100);
-       ui->volumeSlider->setValue(config.getValue("playback/volume").toInt());
-       _player->setVolume(ui->volumeSlider->value());
-       ui->volumeSlider->hide();
-       ui->seekSlider->setEnabled(false);
        ui->progressLayout->removeItem(ui->seekSpacer);
        _tools_widget = new ToolsWidget(this);
        ui->toolsLayout->insertWidget(0, _tools_widget);
@@ -103,13 +98,14 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        _track_renderer = new TrackRenderer(this);
        _track_renderer->setActiveRow(-1);
        _track_renderer->setSearchRow(-1);
+       ui->playlistView->setItemDelegateForColumn(1, _track_renderer);
        ui->playlistView->setItemDelegateForColumn(0, _track_renderer);
 
        _tag_resolver = new TagResolver(this);
 
        connect(ui->libraryButton, SIGNAL(clicked()), this, SLOT(_library()));
        connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(_toggle_view()));
-       connect(ui->playlistView, SIGNAL(clicked(QModelIndex)), this, SLOT(_process_click(QModelIndex)));
+       connect(ui->playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(_process_click(QModelIndex)));
        connect(ui->playpauseButton, SIGNAL(clicked()), _player, SLOT(toggle()));
        connect(ui->nextButton, SIGNAL(clicked()), _player, SLOT(next()));
        connect(ui->stopButton, SIGNAL(clicked()), _player, SLOT(stop()));
@@ -119,7 +115,6 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(ui->randomButton, SIGNAL(clicked()), this, SLOT(_toggle_random()));
        connect(ui->repeatButton, SIGNAL(clicked()), this, SLOT(_toggle_repeat()));
        connect(ui->seekSlider, SIGNAL(sliderMoved(int)), _player, SLOT(seek(int)));
-       connect(ui->volumeSlider, SIGNAL(sliderMoved(int)), _player, SLOT(setVolume(int)));
        connect(ui->playlistView, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(_custom_context_menu_requested(QPoint)));
        connect(clear_playlist, SIGNAL(triggered()), this, SIGNAL(clearPlaylist()));
        connect(delete_action, SIGNAL(triggered()), this, SLOT(_delete_track()));
@@ -130,7 +125,7 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(_player, SIGNAL(stateChanged(PlayerState)), this, SLOT(_state_changed(PlayerState)));
        connect(_player, SIGNAL(trackDone(Track)), _lib, SLOT(updateTrackCount(Track)));
        connect(_tag_resolver, SIGNAL(decoded(Track)), this, SLOT(_track_decoded(Track)));
-       connect(ui->volumeButton, SIGNAL(clicked()), this, SLOT(_toggle_volume()));
+       connect(ui->dirButton, SIGNAL(clicked()), this, SLOT(_dirview()));
        connect(ui->moreButton, SIGNAL(clicked()), this, SLOT(_tools_widget_toggle()));
        connect(_tools_widget, SIGNAL(search(QString)), this, SLOT(search(QString)));
        connect(_tools_widget, SIGNAL(nextSearch()), this, SLOT(nextItem()));
@@ -142,6 +137,7 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        ui->viewButton->setIcon(QIcon(":/icons/"+_icons_theme+"/playback.png"));
        _top_gradient = ui->topWidget->styleSheet();
        _bottom_gradient = ui->bottomWidget->styleSheet();
+       ui->countdownWidget->hide();
 
        // dbus
        _dbusadaptor = new DBusAdaptop(_player);
@@ -164,6 +160,7 @@ void PlayerForm::reload(bool reread) {
                _current_playlist = _lib->getCurrentPlaylist();
                _player->setPlaylist(_current_playlist);
                __fill_list(_model, _current_playlist);
+               ui->playlistView->setColumnWidth(0, 50);
        }
 }
 
@@ -183,13 +180,15 @@ void PlayerForm::_toggle_view() {
 }
 
 void PlayerForm::_process_click(QModelIndex index) {
-       int id = index.row();
-       _player->stop();
-       _player->setTrackId(id);
-       _player->play();
-       _track_renderer->setActiveRow(id);
-       ui->playlistView->hide();
-       ui->playlistView->show();
+       if (index.column() == 1) {
+               int id = index.row();
+               _player->stop();
+               _player->setTrackId(id);
+               _player->play();
+               _track_renderer->setActiveRow(id);
+       } else {
+               _custom_context_menu_requested(ui->playlistView->rect().center());
+       }
 }
 
 void PlayerForm::_track_changed(Track track) {
@@ -305,15 +304,15 @@ void PlayerForm::search(QString pattern) {
 }
 
 void PlayerForm::nextItem() {
-       QString data = _model->index(_search_current_id, 0).data().toString();
+       QString data = _model->index(_search_current_id, 1).data().toString();
        for (int i = _search_current_id+1; i < _model->rowCount(); i++) {
-               data = _model->index(i, 0).data().toString();
+               data = _model->index(i, 1).data().toString();
                if (data.contains(_search_pattern, Qt::CaseInsensitive)) {
                        _search_current_id = i;
                        break;
                }
        }
-       QModelIndex id = _model->index(_search_current_id, 0);
+       QModelIndex id = _model->index(_search_current_id, 1);
        _track_renderer->setSearchRow(_search_current_id);
        ui->playlistView->scrollTo(id);
        ui->playlistView->hide();
@@ -321,15 +320,15 @@ void PlayerForm::nextItem() {
 }
 
 void PlayerForm::prevItem() {
-       QString data = _model->index(_search_current_id, 0).data().toString();
+       QString data = _model->index(_search_current_id, 1).data().toString();
        for (int i = _search_current_id-1; i >= 0; i--) {
-               data = _model->index(i, 0).data().toString();
+               data = _model->index(i, 1).data().toString();
                if (data.contains(_search_pattern, Qt::CaseInsensitive)) {
                        _search_current_id = i;
                        break;
                }
        }
-       QModelIndex id = _model->index(_search_current_id, 0);
+       QModelIndex id = _model->index(_search_current_id, 1);
        _track_renderer->setSearchRow(_search_current_id);
        ui->playlistView->scrollTo(id);
        ui->playlistView->hide();
@@ -339,7 +338,7 @@ void PlayerForm::prevItem() {
 void PlayerForm::cancelSearch() {
        _search_pattern = "";
        _track_renderer->setSearchRow(-1);
-       ui->playlistView->scrollTo(_model->index(_track_renderer->activeRow(), 0));
+       ui->playlistView->scrollTo(_model->index(_track_renderer->activeRow(), 1));
        ui->playlistView->hide();
        ui->playlistView->show();
 }
@@ -351,6 +350,7 @@ void PlayerForm::addFiles(QList<QString> files) {
 void PlayerForm::_track_decoded(Track track) {
        _current_playlist.addTrack(track);
        __fill_list(_model, _current_playlist);
+       ui->playlistView->setColumnWidth(0, 50);
        _lib->saveCurrentPlaylist(_current_playlist);
        _player->setPlaylist(_current_playlist);
 }
@@ -394,18 +394,8 @@ void PlayerForm::stop() {
        _player->stop();
 }
 
-void PlayerForm::_toggle_volume() {
-       if (ui->volumeSlider->isVisible()) {
-               ui->volumeSlider->hide();
-       } else {
-               ui->volumeSlider->show();
-               ui->volumeSlider->setValue(_player->volume());
-       }
-}
-
-void PlayerForm::_volume_changed() {
-       int value = ui->volumeSlider->value();
-       _player->setVolume(value);
+void PlayerForm::_dirview() {
+       emit dirView();
 }
 
 void PlayerForm::landscapeMode() {
@@ -438,7 +428,7 @@ void PlayerForm::landscapeMode() {
        ui->bhorizontalLayout->addWidget(ui->moreButton);
        ui->bhorizontalLayout->addWidget(_fscreen_button);
        ui->bhorizontalLayout->addItem(ui->chorizontalSpacer_4);
-       ui->bhorizontalLayout->addWidget(ui->volumeButton);
+       ui->bhorizontalLayout->addWidget(ui->dirButton);
 
        if (_tools_widget->isVisible()) {
                ui->moreButton->setIcon(QIcon(":/icons/"+_icons_theme+"/more.png"));
@@ -489,7 +479,7 @@ void PlayerForm::portraitMode() {
        ui->bottomWidget->layout()->addItem(ui->bhorizontalSpacer_2);
        ui->bottomWidget->layout()->addWidget(ui->repeatButton);
        ui->bottomWidget->layout()->addItem(ui->bhorizontalSpacer_3);
-       ui->bottomWidget->layout()->addWidget(ui->volumeButton);
+       ui->bottomWidget->layout()->addWidget(ui->dirButton);
 
        if (_tools_widget->isVisible()) {
                ui->moreButton->setIcon(QIcon(":/icons/"+_icons_theme+"/unmore.png"));
@@ -515,6 +505,7 @@ void PlayerForm::updateIcons() {
        Config config;
        _icons_theme = config.getValue("ui/iconstheme").toString();
        _tools_widget->updateIcons();
+       _track_renderer->updateIcons();
        ui->libraryButton->setIcon(QIcon(":/icons/"+_icons_theme+"/library.png"));
        if (_tools_widget->isVisible()) {
                ui->moreButton->setIcon(QIcon(landscape ? ":/icons/" + _icons_theme + "/unmore.png" : ":/icons/" + _icons_theme + "/more.png"));
@@ -524,7 +515,7 @@ void PlayerForm::updateIcons() {
        ui->nextButton->setIcon(QIcon(":/icons/"+_icons_theme+"/next.png"));
        ui->stopButton->setIcon(QIcon(":/icons/"+_icons_theme+"/stop.png"));
        ui->prevButton->setIcon(QIcon(":/icons/"+_icons_theme+"/prev.png"));
-       ui->volumeButton->setIcon(QIcon(":/icons/"+_icons_theme+"/volume.png"));
+       ui->dirButton->setIcon(QIcon(":/icons/"+_icons_theme+"/directory.png"));
        if (_player->state() == PLAYER_PLAYING) {
                ui->playpauseButton->setIcon(QIcon(":/icons/"+_icons_theme+"/pause.png"));
        } else {
@@ -566,5 +557,20 @@ void PlayerForm::play(Track track) {
        if (id >= 0) {
                _player->setTrackId(id);
                _player->play();
+       } else {
+               _current_playlist.addTrack(track);
+               _lib->saveCurrentPlaylist(_current_playlist);
+               reload(true);
+               _player->setTrackId(_current_playlist.tracks().count()-1);
+               _player->play();
        }
 }
+
+void PlayerForm::showCountdown(QString text) {
+       ui->countdownWidget->show();
+       ui->timeLabel->setText(text);
+}
+
+void PlayerForm::hideCountdown() {
+       ui->countdownWidget->hide();
+}