]> git.sesse.net Git - nageru/blobdiff - clip_list.cpp
Allow symlinked frame files. Useful for testing.
[nageru] / clip_list.cpp
index cdffba9365db3306919b9cb18cd4bc4bd76eea8f..14f083e91268984c043ac652cd74ff19b39cccc9 100644 (file)
@@ -1,13 +1,13 @@
+#include "clip_list.h"
+
 #include "mainwindow.h"
+#include "timebase.h"
+#include "ui_mainwindow.h"
 
 #include <math.h>
 #include <string>
 #include <vector>
 
-#include "clip_list.h"
-#include "timebase.h"
-#include "ui_mainwindow.h"
-
 using namespace std;
 
 string pts_to_string(int64_t pts)
@@ -40,27 +40,36 @@ string duration_to_string(int64_t pts_diff)
        return buf;
 }
 
-int ClipList::rowCount(const QModelIndex &parent) const {
-       if (parent.isValid()) return 0;
+int ClipList::rowCount(const QModelIndex &parent) const
+{
+       if (parent.isValid())
+               return 0;
        return clips.size();
 }
 
-int PlayList::rowCount(const QModelIndex &parent) const {
-       if (parent.isValid()) return 0;
+int PlayList::rowCount(const QModelIndex &parent) const
+{
+       if (parent.isValid())
+               return 0;
        return clips.size();
 }
 
-int ClipList::columnCount(const QModelIndex &parent) const {
-       if (parent.isValid()) return 0;
+int ClipList::columnCount(const QModelIndex &parent) const
+{
+       if (parent.isValid())
+               return 0;
        return int(Column::NUM_COLUMNS);
 }
 
-int PlayList::columnCount(const QModelIndex &parent) const {
-       if (parent.isValid()) return 0;
+int PlayList::columnCount(const QModelIndex &parent) const
+{
+       if (parent.isValid())
+               return 0;
        return int(Column::NUM_COLUMNS);
 }
 
-QVariant ClipList::data(const QModelIndex &parent, int role) const {
+QVariant ClipList::data(const QModelIndex &parent, int role) const
+{
        if (!parent.isValid())
                return QVariant();
        const int row = parent.row(), column = parent.column();
@@ -108,7 +117,8 @@ QVariant ClipList::data(const QModelIndex &parent, int role) const {
        }
 }
 
-QVariant PlayList::data(const QModelIndex &parent, int role) const {
+QVariant PlayList::data(const QModelIndex &parent, int role) const
+{
        if (!parent.isValid())
                return QVariant();
        const int row = parent.row(), column = parent.column();
@@ -132,7 +142,10 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const {
        }
        if (role == Qt::BackgroundRole) {
                if (Column(column) == Column::PLAYING) {
-                       if (row == currently_playing_index) {
+                       auto it = current_progress.find(row);
+                       if (it != current_progress.end()) {
+                               double play_progress = it->second;
+
                                // 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);
@@ -155,7 +168,7 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const {
 
        switch (Column(column)) {
        case Column::PLAYING:
-               return (row == currently_playing_index) ? "→" : "";
+               return current_progress.count(row) ? "→" : "";
        case Column::IN:
                return QString::fromStdString(pts_to_string(clips[row].pts_in));
        case Column::OUT:
@@ -186,7 +199,8 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const {
        }
 }
 
-QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
+QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const
+{
        if (role != Qt::DisplayRole)
                return QVariant();
        if (orientation != Qt::Horizontal)
@@ -212,7 +226,8 @@ QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role
        }
 }
 
-QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role) const {
+QVariant PlayList::headerData(int section, Qt::Orientation orientation, int role) const
+{
        if (role != Qt::DisplayRole)
                return QVariant();
        if (orientation != Qt::Horizontal)
@@ -379,7 +394,7 @@ void PlayList::move_clips(size_t first, size_t last, int delta)
                beginMoveRows(QModelIndex(), first, last, QModelIndex(), first - 1);
                rotate(clips.begin() + first - 1, clips.begin() + first, clips.begin() + last + 1);
        } else {
-               beginMoveRows(QModelIndex(), first, last, QModelIndex(), first + (last-first+1) + 1);
+               beginMoveRows(QModelIndex(), first, last, QModelIndex(), first + (last - first + 1) + 1);
                first = clips.size() - first - 1;
                last = clips.size() - last - 1;
                rotate(clips.rbegin() + last - 1, clips.rbegin() + last, clips.rbegin() + first + 1);
@@ -419,6 +434,24 @@ void PlayList::set_currently_playing(int index, double progress)
        }
 }
 
+void PlayList::set_progress(const map<size_t, double> &progress)
+{
+       const int column = int(Column::PLAYING);
+       map<size_t, double> old_progress = move(this->current_progress);
+       this->current_progress = progress;
+
+       for (auto it : old_progress) {
+               size_t index = it.first;
+               if (current_progress.count(index) == 0) {
+                       emit dataChanged(this->index(index, column), this->index(index, column));
+               }
+       }
+       for (auto it : current_progress) {
+               size_t index = it.first;
+               emit dataChanged(this->index(index, column), this->index(index, column));
+       }
+}
+
 namespace {
 
 Clip deserialize_clip(const ClipProto &clip_proto)