]> git.sesse.net Git - nageru/blobdiff - clip_list.cpp
Upgrade Qt Creator.
[nageru] / clip_list.cpp
index cdf97807e3213a35e7a149fb4a3dbc9adbfd5d21..75f4a9f46b6be66e0f72523528600262aab20350 100644 (file)
@@ -5,14 +5,14 @@
 #include <vector>
 
 #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)) {
@@ -131,7 +130,7 @@ QVariant PlayList::data(const QModelIndex &parent, int role) const {
                }
        }
 
-       if (role != Qt::DisplayRole)
+       if (role != Qt::DisplayRole && role != Qt::EditRole)
                return QVariant();
 
        switch (Column(column)) {
@@ -229,6 +228,24 @@ Qt::ItemFlags ClipList::flags(const QModelIndex &index) const
        }
 }
 
+Qt::ItemFlags PlayList::flags(const QModelIndex &index) const
+{
+       if (!index.isValid())
+               return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+       const int row = index.row(), column = index.column();
+       if (size_t(row) >= clips.size())
+               return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+
+       switch (Column(column)) {
+       case Column::DESCRIPTION:
+       case Column::CAMERA:
+               return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
+               return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
+       default:
+               return Qt::ItemIsEnabled | Qt::ItemIsSelectable;
+       }
+}
+
 bool ClipList::setData(const QModelIndex &index, const QVariant &value, int role)
 {
        if (!index.isValid() || role != Qt::EditRole) {
@@ -254,6 +271,36 @@ bool ClipList::setData(const QModelIndex &index, const QVariant &value, int role
        }
 }
 
+bool PlayList::setData(const QModelIndex &index, const QVariant &value, int role)
+{
+       if (!index.isValid() || role != Qt::EditRole) {
+               return false;
+       }
+
+       const int row = index.row(), column = index.column();
+       if (size_t(row) >= clips.size())
+               return false;
+
+       switch (Column(column)) {
+       case Column::DESCRIPTION:
+               clips[row].descriptions[clips[row].stream_idx] = value.toString().toStdString();
+               emit_data_changed(row);
+               return true;
+       case Column::CAMERA: {
+               bool ok;
+               int camera_idx = value.toInt(&ok);
+               if (!ok || camera_idx < 1 || camera_idx > NUM_CAMERAS) {
+                       return false;
+               }
+               clips[row].stream_idx = camera_idx - 1;
+               emit_data_changed(row);
+               return true;
+       }
+       default:
+               return false;
+       }
+}
+
 void ClipList::add_clip(const Clip &clip)
 {
        beginInsertRows(QModelIndex(), clips.size(), clips.size());
@@ -268,6 +315,34 @@ void PlayList::add_clip(const Clip &clip)
        endInsertRows();
 }
 
+void PlayList::duplicate_clips(size_t first, size_t last)
+{
+       beginInsertRows(QModelIndex(), first, last);
+       clips.insert(clips.begin() + first, clips.begin() + first, clips.begin() + last + 1);
+       endInsertRows();
+}
+
+void PlayList::erase_clips(size_t first, size_t last)
+{
+       beginRemoveRows(QModelIndex(), first, last);
+       clips.erase(clips.begin() + first, clips.begin() + last + 1);
+       endRemoveRows();
+}
+
+void PlayList::move_clips(size_t first, size_t last, int delta)
+{
+       if (delta == -1) {
+               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);
+               first = clips.size() - first - 1;
+               last = clips.size() - last - 1;
+               rotate(clips.rbegin() + last - 1, clips.rbegin() + last, clips.rbegin() + first + 1);
+       }
+       endMoveRows();
+}
+
 void ClipList::emit_data_changed(size_t row)
 {
        emit dataChanged(index(row, 0), index(row, int(Column::NUM_COLUMNS)));