CuteLogger
Fast and simple logging solution for Qt based applications
markersmodel.h
1/*
2 * Copyright (c) 2021-2023 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#include <QAbstractItemModel>
23#include <QColor>
24#include <QString>
25
26namespace Markers {
27
28class Marker
29{
30public:
31 QString text;
32 int start{-1};
33 int end{-1};
34 QColor color;
35};
36
37} // namespace Markers
38
39class MarkersModel : public QAbstractItemModel
40{
41 Q_OBJECT
42 Q_PROPERTY(QStringList recentColors READ recentColors NOTIFY recentColorsChanged)
43
44public:
45 enum Roles {
46 TextRole = Qt::UserRole + 1,
47 StartRole,
48 EndRole,
49 ColorRole,
50 };
51
52 explicit MarkersModel(QObject *parent = 0);
53 virtual ~MarkersModel();
54
55 void load(Mlt::Producer *producer);
56 Markers::Marker getMarker(int markerIndex);
57 int uniqueKey() const;
58 int markerIndexForPosition(int position);
59 int markerIndexForRange(int start, int end);
60 int rangeMarkerIndexForPosition(int position);
61 Q_INVOKABLE int nextMarkerPosition(int position);
62 Q_INVOKABLE int prevMarkerPosition(int position);
63 QModelIndex modelIndexForRow(int row);
64 QMap<int, QString> ranges();
65 QStringList recentColors();
66 QList<Markers::Marker> getMarkers() const;
67 QList<QColor> allColors() const;
68
69 // These should only be called by the marker commands
70 void doRemove(int markerIndex);
71 void doInsert(int markerIndex, const Markers::Marker &marker);
72 void doAppend(const Markers::Marker &marker);
73 void doUpdate(int markerIndex, const Markers::Marker &marker);
74 void doClear();
75 void doReplace(QList<Markers::Marker> &markers);
76 void doShift(int shiftPosition, int shiftAmount);
77
78signals:
79 void rangesChanged();
80 void modified();
81 void recentColorsChanged();
82
83public slots:
84 void remove(int markerIndex);
85 void append(const Markers::Marker &marker);
86 void update(int markerIndex, const Markers::Marker &marker);
87 void move(int markerIndex, int start, int end);
88 void setColor(int markerIndex, const QColor &color);
89 void clear();
90
91protected:
92 // Implement QAbstractItemModel
93 int rowCount(const QModelIndex &parent) const;
94 int columnCount(const QModelIndex &parent) const;
95 QVariant data(const QModelIndex &index, int role) const;
96 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
97 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const;
98 QModelIndex parent(const QModelIndex &index) const;
99 QHash<int, QByteArray> roleNames() const;
100
101private:
102 int markerCount() const;
103 int keyIndex(int key) const;
104 Mlt::Properties *getMarkerProperties(int markerIndex);
105 void updateRecentColors(const QColor &color);
106
107 Mlt::Producer *m_producer;
108 QList<int> m_keys;
109 QMap<QRgb, QString> m_recentColors;
110};
111
112#endif // MARKERSMODEL_H