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 
27 namespace Markers
28 {
29 
30 class Marker
31 {
32 public:
33  QString text;
34  int start {-1};
35  int end {-1};
36  QColor color;
37 };
38 
39 }
40 
41 class MarkersModel : public QAbstractItemModel
42 {
43  Q_OBJECT
44  Q_PROPERTY(QStringList recentColors READ recentColors NOTIFY recentColorsChanged)
45 
46 public:
47 
48  enum Roles {
49  TextRole = Qt::UserRole + 1,
50  StartRole,
51  EndRole,
52  ColorRole,
53  };
54 
55  explicit MarkersModel(QObject* parent = 0);
56  virtual ~MarkersModel();
57 
58  void load(Mlt::Producer* producer);
59  Markers::Marker getMarker(int markerIndex);
60  int uniqueKey() const;
61  int markerIndexForPosition(int position);
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();
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 
78 signals:
79  void rangesChanged();
80  void modified();
81  void recentColorsChanged();
82 
83 public 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 
91 protected:
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 
101 private:
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