Commit 0b8600c2 authored by Nicolas Carion's avatar Nicolas Carion

Support for marker colors

parent d67c52ff
......@@ -25,12 +25,15 @@
#include "core.h"
#include "doc/docundostack.hpp"
#include "doc/kdenlivedoc.h"
#include "kdenlivesettings.h"
#include "macros.hpp"
#include "project/projectmanager.h"
#include <QDebug>
#include <klocalizedstring.h>
std::array<QColor, 5> MarkerListModel::markerTypes = {Qt::red, Qt::blue, Qt::green, Qt::yellow, Qt::cyan};
MarkerListModel::MarkerListModel(const QString &clipId, std::weak_ptr<DocUndoStack> undo_stack, QObject *parent)
: QAbstractListModel(parent)
, m_undoStack(std::move(undo_stack))
......@@ -46,12 +49,14 @@ MarkerListModel::MarkerListModel(std::weak_ptr<DocUndoStack> undo_stack, QObject
{
}
void MarkerListModel::addMarker(GenTime pos, const QString &comment)
void MarkerListModel::addMarker(GenTime pos, const QString &comment, int type)
{
QWriteLocker locker(&m_lock);
if (type == -1) type = KdenliveSettings::default_marker_type();
Q_ASSERT(type >= 0 && type < markerTypes.size());
if (m_markerList.count(pos) > 0) {
// In this case we simply change the comment
QString oldComment = m_markerList[pos];
QString oldComment = m_markerList[pos].first;
Fun undo = changeComment_lambda(pos, oldComment);
Fun redo = changeComment_lambda(pos, comment);
if (redo()) {
......@@ -59,7 +64,7 @@ void MarkerListModel::addMarker(GenTime pos, const QString &comment)
}
} else {
// In this case we create one
Fun redo = addMarker_lambda(pos, comment);
Fun redo = addMarker_lambda(pos, comment, type);
Fun undo = deleteMarker_lambda(pos);
if (redo()) {
PUSH_UNDO(undo, redo, i18n("Add marker"));
......@@ -71,8 +76,9 @@ void MarkerListModel::removeMarker(GenTime pos)
{
QWriteLocker locker(&m_lock);
Q_ASSERT(m_markerList.count(pos) > 0);
QString oldComment = m_markerList[pos];
Fun undo = addMarker_lambda(pos, oldComment);
QString oldComment = m_markerList[pos].first;
int oldType = m_markerList[pos].second;
Fun undo = addMarker_lambda(pos, oldComment, oldType);
Fun redo = deleteMarker_lambda(pos);
if (redo()) {
PUSH_UNDO(undo, redo, i18n("Delete marker"));
......@@ -88,16 +94,16 @@ Fun MarkerListModel::changeComment_lambda(GenTime pos, const QString &comment)
Q_ASSERT(model->m_markerList.count(pos) > 0);
int row = static_cast<int>(std::distance(model->m_markerList.begin(), model->m_markerList.find(pos)));
emit model->dataChanged(model->index(row), model->index(row));
model->m_markerList[pos] = comment;
model->m_markerList[pos].first = comment;
return true;
};
}
Fun MarkerListModel::addMarker_lambda(GenTime pos, const QString &comment)
Fun MarkerListModel::addMarker_lambda(GenTime pos, const QString &comment, int type)
{
auto guide = m_guide;
auto clipId = m_clipId;
return [guide, clipId, pos, comment]() {
return [guide, clipId, pos, comment, type]() {
auto model = getModel(guide, clipId);
Q_ASSERT(model->m_markerList.count(pos) == 0);
// We determine the row of the newly added marker
......@@ -107,7 +113,7 @@ Fun MarkerListModel::addMarker_lambda(GenTime pos, const QString &comment)
insertionRow = static_cast<int>(std::distance(model->m_markerList.begin(), insertionIt));
}
model->beginInsertRows(QModelIndex(), insertionRow, insertionRow);
model->m_markerList[pos] = comment;
model->m_markerList[pos] = {comment, type};
model->endInsertRows();
return true;
};
......@@ -142,6 +148,7 @@ QHash<int, QByteArray> MarkerListModel::roleNames() const
roles[CommentRole] = "comment";
roles[PosRole] = "position";
roles[FrameRole] = "frame";
roles[ColorRole] = "color";
return roles;
}
......@@ -156,11 +163,13 @@ QVariant MarkerListModel::data(const QModelIndex &index, int role) const
case Qt::DisplayRole:
case Qt::EditRole:
case CommentRole:
return it->second;
return it->second.first;
case PosRole:
return it->first.seconds();
case FrameRole:
return it->first.frames(pCore->getCurrentFps());
case ColorRole:
return markerTypes[it->second.second];
}
return QVariant();
}
......
......@@ -34,7 +34,7 @@
class DocUndoStack;
/* @brief This class is the model for a list of markers.
A marker is defined by a time and a comment string.
A marker is defined by a time, a type (the color used to represent it) and a comment string.
We store them in a sorted fashion using a std::map
A marker is essentially bound to a clip. We can also define guides, that are timeline-wise markers. For that, use the constructors without clipId
......@@ -52,14 +52,21 @@ public:
/* @brief Construct a guide list (bound to the timeline) */
MarkerListModel(std::weak_ptr<DocUndoStack> undo_stack, QObject *parent = nullptr);
enum { CommentRole = Qt::UserRole + 1, PosRole, FrameRole };
enum { CommentRole = Qt::UserRole + 1, PosRole, FrameRole, ColorRole };
/* @brief Adds a marker at the given position. If there is already one, the comment will be overriden */
void addMarker(GenTime pos, const QString &comment);
/* @brief Adds a marker at the given position. If there is already one, the comment will be overriden
@param pos defines the position of the marker, relative to the clip
@param comment is the text associated with the marker
@param type is the type (color) associated with the marker. If -1 is passed, then the value is pulled from kdenlive's defaults
*/
void addMarker(GenTime pos, const QString &comment, int type = -1);
/* @brief Removes the marker at the given position. */
void removeMarker(GenTime pos);
/** This describes the available markers type and their corresponding colors */
static std::array<QColor, 5> markerTypes;
// Mandatory overloads
QVariant data(const QModelIndex &index, int role) const override;
QHash<int, QByteArray> roleNames() const override;
......@@ -70,7 +77,7 @@ protected:
Fun changeComment_lambda(GenTime pos, const QString &comment);
/** @brief Helper function that generate a lambda to add given marker */
Fun addMarker_lambda(GenTime pos, const QString &comment);
Fun addMarker_lambda(GenTime pos, const QString &comment, int type);
/** @brief Helper function that generate a lambda to remove given marker */
Fun deleteMarker_lambda(GenTime pos);
......@@ -86,7 +93,7 @@ private:
mutable QReadWriteLock m_lock; // This is a lock that ensures safety in case of concurrent access
std::map<GenTime, QString> m_markerList;
std::map<GenTime, std::pair<QString, int>> m_markerList;
public:
// this is to enable for range loops
......
......@@ -594,7 +594,7 @@ void BinController::saveDocumentProperties(const QMap<QString, QString> &props,
QLocale locale;
for (const auto &guide : *guideModel) {
QString propertyName = "kdenlive:guide." + locale.toString(guide.first.seconds());
playlistProps.set(propertyName.toUtf8().constData(), guide.second.toUtf8().constData());
playlistProps.set(propertyName.toUtf8().constData(), guide.second.first.toUtf8().constData());
}
}
......
......@@ -29,6 +29,10 @@
#include <QDebug>
#include <mlt++/MltProducer.h>
//this can be deleted
#include "gentime.h"
#include "bin/model/markerlistmodel.hpp"
ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::shared_ptr<Mlt::Producer> prod, const QString &binClipId, int id)
: MoveableItem<Mlt::Producer>(parent, id)
, m_producer(prod)
......@@ -42,6 +46,10 @@ ClipModel::ClipModel(std::weak_ptr<TimelineModel> parent, std::shared_ptr<Mlt::P
} else {
m_endlessResize = false;
}
// TODO this is for testing purposes, remove.
binClip->getMarkerModel()->addMarker(GenTime(1.), "Test1");
binClip->getMarkerModel()->addMarker(GenTime(2.), "Test2", 2);
// END OF TESTS
}
int ClipModel::construct(const std::weak_ptr<TimelineModel> &parent, const QString &binClipId, int id)
......
......@@ -233,7 +233,7 @@ Rectangle {
width: 1
height: parent.height
x: (model.frame - clipRoot.inPoint) * timeScale;
color: 'red'
color: model.color
}
Rectangle {
opacity: 0.7
......@@ -244,7 +244,7 @@ Rectangle {
anchors {
bottom: parent.verticalCenter
}
color: 'red'
color: model.color
}
Text {
id: mlabel
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment