]> git.sesse.net Git - nageru/commitdiff
Mark play progress with background color in the play list.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 26 Sep 2018 23:09:09 +0000 (01:09 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Wed, 26 Sep 2018 23:09:09 +0000 (01:09 +0200)
clip_list.cpp
clip_list.h
mainwindow.cpp

index 75f4a9f46b6be66e0f72523528600262aab20350..69a87aee64ef2e3a66b5665c89b0a65f41c5bb80 100644 (file)
@@ -129,6 +129,23 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const {
                        return Qt::AlignLeft + Qt::AlignVCenter;
                }
        }
+       if (role == Qt::BackgroundRole) {
+               if (Column(column) == Column::PLAYING) {
+                       if (row == currently_playing_index) {
+                               // This only really works well for the first column, for whatever odd Qt reason.
+                               QLinearGradient grad(QPointF(0, 0), QPointF(1, 0));
+                               grad.setCoordinateMode(grad.QGradient::ObjectBoundingMode);
+                               grad.setColorAt(0.0f, QColor::fromRgbF(0.0f, 0.0f, 1.0f, 0.2f));
+                               grad.setColorAt(play_progress, QColor::fromRgbF(0.0f, 0.0f, 1.0f, 0.2f));
+                               grad.setColorAt(play_progress + 0.01f, QColor::fromRgbF(0.0f, 0.0f, 1.0f, 0.0f));
+                               return QBrush(grad);
+                       } else {
+                               return QVariant();
+                       }
+               } else {
+                       return QVariant();
+               }
+       }
 
        if (role != Qt::DisplayRole && role != Qt::EditRole)
                return QVariant();
@@ -353,16 +370,21 @@ void PlayList::emit_data_changed(size_t row)
        emit dataChanged(index(row, 0), index(row, int(Column::NUM_COLUMNS)));
 }
 
-void PlayList::set_currently_playing(int index)
+void PlayList::set_currently_playing(int index, double progress)
 {
        int old_index = currently_playing_index;
+       int column = int(Column::PLAYING);
        if (index != old_index) {
                currently_playing_index = index;
+               play_progress = progress;
                if (old_index != -1) {
-                       emit_data_changed(old_index);
+                       emit dataChanged(this->index(old_index, column), this->index(old_index, column));
                }
                if (index != -1) {
-                       emit_data_changed(index);
+                       emit dataChanged(this->index(index, column), this->index(index, column));
                }
+       } else if (index != -1 && fabs(progress - play_progress) > 1e-3) {
+               play_progress = progress;
+               emit dataChanged(this->index(index, column), this->index(index, column));
        }
 }
index db3a479dd723a4c717493a22a898f6da1660272b..2d37eab4fda0959e23e004f78cdd4120523f6188 100644 (file)
@@ -120,7 +120,7 @@ public:
        ClipProxy mutable_back() { return mutable_clip(size() - 1); }
        const Clip *back() const { return clip(size() - 1); }
 
-       void set_currently_playing(int index);  // -1 = none.
+       void set_currently_playing(int index, double progress);  // -1 = none.
        int get_currently_playing() const { return currently_playing_index; }
 
        void emit_data_changed(size_t row) override;
@@ -128,6 +128,7 @@ public:
 private:
        std::vector<Clip> clips;
        int currently_playing_index = -1;
+       double play_progress = 0.0;
 };
 
 #endif  // !defined (_CLIP_LIST_H)
index 656ff1e3467d9ddea16ff83987cca9430033e256..1b7a71f8dcef5207b515883da66bf21324ab6de8 100644 (file)
@@ -261,7 +261,7 @@ void MainWindow::play_clicked()
 
        const Clip &clip = *playlist_clips->clip(row);
        live_player->play_clip(clip, clip.stream_idx);
-       playlist_clips->set_currently_playing(row);
+       playlist_clips->set_currently_playing(row, 0.0f);
        playlist_selection_changed();
 }
 
@@ -272,15 +272,17 @@ void MainWindow::live_player_clip_done()
                ++row;
                const Clip &clip = *playlist_clips->clip(row);
                live_player->play_clip(clip, clip.stream_idx);
-               playlist_clips->set_currently_playing(row);
+               playlist_clips->set_currently_playing(row, 0.0f);
        } else {
-               playlist_clips->set_currently_playing(-1);
+               playlist_clips->set_currently_playing(-1, 0.0f);
                ui->live_label->setText("Current output (paused)");
        }
 }
 
 void MainWindow::live_player_clip_progress(double played_this_clip, double total_length)
 {
+       playlist_clips->set_currently_playing(playlist_clips->get_currently_playing(), played_this_clip / total_length);
+
        double remaining = total_length - played_this_clip;
        for (int row = playlist_clips->get_currently_playing() + 1; row < int(playlist_clips->size()); ++row) {
                const Clip clip = *playlist_clips->clip(row);