Added countdown label
[someplayer] / src / playerform.cpp
index cfe5b1e..9120ee3 100644 (file)
@@ -46,7 +46,6 @@ inline void __fill_list(QStandardItemModel *_model, Playlist playlist) {
                time.setHMS(0, meta.length()/60, meta.length() % 60);
                QString t = meta.title()+"#_#"+meta.artist()+"#_#"+meta.album()+"#_#"+time.toString("mm:ss");
                _model->setItem(i, 1, new QStandardItem(t));
-               _model->setItem(i, 0, new QStandardItem(""));
        }
 }
 
@@ -82,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);
@@ -113,7 +106,6 @@ PlayerForm::PlayerForm(Library* lib, QWidget *parent) :
        connect(ui->libraryButton, SIGNAL(clicked()), this, SLOT(_library()));
        connect(ui->viewButton, SIGNAL(clicked()), this, SLOT(_toggle_view()));
        connect(ui->playlistView, SIGNAL(activated(QModelIndex)), this, SLOT(_process_click(QModelIndex)));
-       connect(ui->playlistView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(_process_dbl_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()));
@@ -123,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()));
@@ -134,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()));
@@ -146,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);
@@ -197,8 +189,6 @@ void PlayerForm::_process_click(QModelIndex index) {
        } else {
                _custom_context_menu_requested(ui->playlistView->rect().center());
        }
-//     ui->playlistView->hide();
-//     ui->playlistView->show();
 }
 
 void PlayerForm::_track_changed(Track track) {
@@ -314,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();
@@ -330,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();
@@ -348,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();
 }
@@ -404,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() {
@@ -448,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"));
@@ -499,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"));
@@ -525,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"));
@@ -534,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 {
@@ -576,9 +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::_process_dbl_click(QModelIndex) {
-       _custom_context_menu_requested(ui->playlistView->rect().center());
+void PlayerForm::showCountdown(QString text) {
+       ui->countdownWidget->show();
+       ui->timeLabel->setText(text);
+}
+
+void PlayerForm::hideCountdown() {
+       ui->countdownWidget->hide();
 }