X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=clip_list.cpp;h=69a6334cd473984d1b730998464c61cc5af422cc;hb=cf158af1c2219bd9f5a9bc531fb3c1133d327b45;hp=3c9637258f60c8b002cee6b23321a318f9734972;hpb=498d1082773a5f394cb4fbd15b1084a4751f1409;p=nageru diff --git a/clip_list.cpp b/clip_list.cpp index 3c96372..69a6334 100644 --- a/clip_list.cpp +++ b/clip_list.cpp @@ -5,14 +5,14 @@ #include #include "clip_list.h" +#include "timebase.h" #include "ui_mainwindow.h" using namespace std; string pts_to_string(int64_t pts) { - // FIXME: This depends on a fixed timebase. - int64_t t = lrint((pts / 12800.0) * 1e3); // In milliseconds. + int64_t t = lrint((pts / double(TIMEBASE)) * 1e3); // In milliseconds. int ms = t % 1000; t /= 1000; int sec = t % 60; @@ -28,8 +28,7 @@ string pts_to_string(int64_t pts) string duration_to_string(int64_t pts_diff) { - // FIXME: This depends on a fixed timebase. - int64_t t = lrint((pts_diff / 12800.0) * 1e3); // In milliseconds. + int64_t t = lrint((pts_diff / double(TIMEBASE)) * 1e3); // In milliseconds. int ms = t % 1000; t /= 1000; int sec = t % 60; @@ -79,7 +78,7 @@ QVariant ClipList::data(const QModelIndex &parent, int role) const { } } - if (role != Qt::DisplayRole) + if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant(); switch (Column(column)) { @@ -130,8 +129,27 @@ 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)); + if (play_progress + 0.01f <= 1.0f) { + 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) + if (role != Qt::DisplayRole && role != Qt::EditRole) return QVariant(); switch (Column(column)) { @@ -354,16 +372,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)); } }