CuteLogger
Fast and simple logging solution for Qt based applications
markersmodel.h
1/*
2 * Copyright (c) 2021 Meltytech, LLC
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef MARKERSMODEL_H
19#define MARKERSMODEL_H
20
21#include <MltProducer.h>
22
23#include <QAbstractItemModel>
24#include <QColor>
25#include <QString>
26
27namespace Markers {
28
29class Marker
30{
31public:
32 QString text;
33 int start {-1};
34 int end {-1};
35 QColor color;
36};
37
38}
39
40class MarkersModel : public QAbstractItemModel
41{
42 Q_OBJECT
43 Q_PROPERTY(QStringList recentColors READ recentColors NOTIFY recentColorsChanged)
44
45public:
46
47 enum Roles {
48 TextRole = Qt::UserRole + 1,
49 StartRole,
50 EndRole,
51 ColorRole,
52 };
53
54 explicit MarkersModel(QObject *parent = 0);
55 virtual ~MarkersModel();
56
57 void load(Mlt::Producer *producer);
58 Markers::Marker getMarker(int markerIndex);
59 int uniqueKey() const;
60 int markerIndexForPosition(int position);
61 int markerIndexForRange(int start, int end);
62 Q_INVOKABLE int nextMarkerPosition(int position);
63 Q_INVOKABLE int prevMarkerPosition(int position);
64 QModelIndex modelIndexForRow(int row);
65 QMap<int, QString> ranges();
66 QStringList recentColors();
67 QList<Markers::Marker> getMarkers() const;
68 QList<QColor> allColors() const;
69
70 // These should only be called by the marker commands
71 void doRemove(int markerIndex);
72 void doInsert(int markerIndex, const Markers::Marker &marker);
73 void doAppend(const Markers::Marker &marker);
74 void doUpdate(int markerIndex, const Markers::Marker &marker);
75 void doClear();
76 void doReplace(QList<Markers::Marker> &markers);
77 void doShift(int shiftPosition, int shiftAmount);
78
79signals:
80 void rangesChanged();
81 void modified();
82 void recentColorsChanged();
83
84public slots:
85 void remove(int markerIndex);
86 void append(const Markers::Marker &marker);
87 void update(int markerIndex, const Markers::Marker &marker);
88 void move(int markerIndex, int start, int end);
89 void setColor(int markerIndex, const QColor &color);
90 void clear();
91
92protected:
93 // Implement QAbstractItemModel
94 int rowCount(const QModelIndex &parent) const;
95 int columnCount(const QModelIndex &parent) const;
96 QVariant data(const QModelIndex &index, int role) const;
97 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
98 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
99 QModelIndex parent(const QModelIndex &index) const;
100 QHash<int, QByteArray> roleNames() const;
101
102private:
103 int markerCount() const;
104 int keyIndex(int key) const;
105 Mlt::Properties *getMarkerProperties(int markerIndex);
106 void updateRecentColors(const QColor &color);
107
108 Mlt::Producer *m_producer;
109 QList<int> m_keys;
110 QMap<QRgb, QString> m_recentColors;
111};
112
113#endif // MARKERSMODEL_H