From d23244e5582e7cbb453e23e0d4b5b1faa7605e87 Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Sun, 10 Jun 2018 12:24:20 +0200 Subject: [PATCH] Start working on a clip list. --- Makefile | 2 +- clip_list.cpp | 79 ++++++++++++++++++++++++++++++++++++++++++++++++ clip_list.h | 32 ++++++++++++++++++++ mainwindow.cpp | 16 ++++++++++ ui_mainwindow.ui | 38 +---------------------- 5 files changed, 129 insertions(+), 38 deletions(-) create mode 100644 clip_list.cpp create mode 100644 clip_list.h diff --git a/Makefile b/Makefile index 2608903..fc91d0e 100644 --- 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 index 0000000..48d8e7b --- /dev/null +++ b/clip_list.cpp @@ -0,0 +1,79 @@ +#include "mainwindow.h" + +#include "clip_list.h" +#include "ui_mainwindow.h" + +#include +#include + +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 index 0000000..adf3748 --- /dev/null +++ b/clip_list.h @@ -0,0 +1,32 @@ +#ifndef _CLIP_LIST_H +#define _CLIP_LIST_H 1 + +#include + +#include + +#include +#include + +struct Clip { + int64_t pts_in = -1, pts_out = -1; + std::vector 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 clips; +}; + +#endif // !defined (_CLIP_LIST_H) diff --git a/mainwindow.cpp b/mainwindow.cpp index 5432408..e148345 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -1,7 +1,15 @@ #include "mainwindow.h" +#include "clip_list.h" #include "ui_mainwindow.h" +#include +#include + +#include + +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); + }); } diff --git a/ui_mainwindow.ui b/ui_mainwindow.ui index 3d3f046..d55e00d 100644 --- a/ui_mainwindow.ui +++ b/ui_mainwindow.ui @@ -91,43 +91,7 @@ - - - - In - - - - - Out - - - - - Duration - - - - - Camera 1 - - - - - Camera 2 - - - - - Camera 3 - - - - - Camera 4 - - - + -- 2.39.2