]> git.sesse.net Git - nageru/commitdiff
Start working on a clip list.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2018 10:24:20 +0000 (12:24 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Sun, 10 Jun 2018 10:24:20 +0000 (12:24 +0200)
Makefile
clip_list.cpp [new file with mode: 0644]
clip_list.h [new file with mode: 0644]
mainwindow.cpp
ui_mainwindow.ui

index 2608903245524df9dc936e1fb7d737f8e4e81d23..fc91d0e8ce5a6bef370e735897e9b29b8ce1bb6a 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -6,7 +6,7 @@ CXXFLAGS += -std=gnu++11 -fPIC $(shell pkg-config --cflags $(PKG_MODULES)) -pthr
 LDLIBS=$(shell pkg-config --libs $(PKG_MODULES)) -pthread -lavformat -lavcodec -lavutil -lswscale
 
 # Qt objects
-OBJS_WITH_MOC = mainwindow.o jpeg_frame_view.o
+OBJS_WITH_MOC = mainwindow.o jpeg_frame_view.o clip_list.o
 OBJS += $(OBJS_WITH_MOC)
 OBJS += $(OBJS_WITH_MOC:.o=.moc.o) 
 
diff --git a/clip_list.cpp b/clip_list.cpp
new file mode 100644 (file)
index 0000000..48d8e7b
--- /dev/null
@@ -0,0 +1,79 @@
+#include "mainwindow.h"
+
+#include "clip_list.h"
+#include "ui_mainwindow.h"
+
+#include <string>
+#include <vector>
+
+using namespace std;
+
+int ClipList::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;
+       return 7;
+}
+
+QVariant ClipList::data(const QModelIndex &parent, int role) const {
+       if (!parent.isValid())
+               return QVariant();
+       if (role != Qt::DisplayRole)
+               return QVariant();
+
+       const int row = parent.row(), column = parent.column();
+       if (size_t(row) >= clips.size())
+               return QVariant();
+
+       switch (column) {
+       case 0:
+               return qlonglong(clips[row].pts_in);
+       case 1:
+               if (clips[row].pts_out >= 0) {
+                       return qlonglong(clips[row].pts_out);
+               } else {
+                       return QVariant();
+               }
+       default:
+               return QVariant();
+       }
+}
+
+QVariant ClipList::headerData(int section, Qt::Orientation orientation, int role) const {
+       if (role != Qt::DisplayRole)
+               return QVariant();
+       if (orientation != Qt::Horizontal)
+               return QVariant();
+
+       switch (section) {
+       case 0:
+               return "In";
+       case 1:
+               return "Out";
+       case 2:
+               return "Duration";
+       case 3:
+               return "Camera 1";
+       case 4:
+               return "Camera 2";
+       case 5:
+               return "Camera 3";
+       case 6:
+               return "Camera 4";
+       default:
+               return "";
+       }
+}
+
+void ClipList::add_clip(int64_t pts_in)
+{
+       Clip clip;
+       clip.pts_in = pts_in;
+
+       beginInsertRows(QModelIndex(), clips.size(), clips.size());
+       clips.push_back(clip);
+       endInsertRows();
+}
diff --git a/clip_list.h b/clip_list.h
new file mode 100644 (file)
index 0000000..adf3748
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef _CLIP_LIST_H
+#define _CLIP_LIST_H 1
+
+#include <QAbstractTableModel>
+
+#include <stdint.h>
+
+#include <vector>
+#include <string>
+
+struct Clip {
+       int64_t pts_in = -1, pts_out = -1;
+       std::vector<std::string> descriptions;  // One per camera.
+};
+
+class ClipList : public QAbstractTableModel {
+       Q_OBJECT
+
+public:
+       int rowCount(const QModelIndex &parent) const override;
+       int columnCount(const QModelIndex &parent) const override;
+       QVariant data(const QModelIndex &parent, int role) const override;
+       QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
+
+       void add_clip(int64_t pts_in);
+       size_t size() const { return clips.size(); }
+
+private:
+       std::vector<Clip> clips;
+};
+
+#endif  // !defined (_CLIP_LIST_H)
index 5432408c876820a2d17cb974d4c1164448beffc7..e14834502e216cac0ba61a9672f6a9dafbf223b0 100644 (file)
@@ -1,7 +1,15 @@
 #include "mainwindow.h"
 
+#include "clip_list.h"
 #include "ui_mainwindow.h"
 
+#include <string>
+#include <vector>
+
+#include <QShortcut>
+
+using namespace std;
+
 MainWindow *global_mainwindow = nullptr;
 
 MainWindow::MainWindow()
@@ -9,4 +17,12 @@ MainWindow::MainWindow()
 {
        global_mainwindow = this;
        ui->setupUi(this);
+
+       ClipList *clips = new ClipList;
+       ui->clip_list->setModel(clips);
+
+       QShortcut *shortcut = new QShortcut(QKeySequence(Qt::Key_Q), this);
+       connect(shortcut, &QShortcut::activated, [clips]{
+               clips->add_clip(12345);
+       });
 }
index 3d3f0461e3bf7671e8e7d9d83a0583c4ef07a057..d55e00d5fc8aa219533c1cd5d965e3c1008b46ad 100644 (file)
       <widget class="QWidget" name="verticalLayoutWidget_4">
        <layout class="QVBoxLayout" name="verticalLayout_4">
         <item>
-         <widget class="QTableWidget" name="clip_list">
-          <column>
-           <property name="text">
-            <string>In</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Out</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Duration</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Camera 1</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Camera 2</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Camera 3</string>
-           </property>
-          </column>
-          <column>
-           <property name="text">
-            <string>Camera 4</string>
-           </property>
-          </column>
-         </widget>
+         <widget class="QTableView" name="clip_list"/>
         </item>
         <item>
          <widget class="QTableWidget" name="playlist">