Move color to TimelineMarker and make sure all instances of a marker update on color change

This commit is contained in:
Thomas Wilshaw
2021-10-22 22:15:50 +01:00
parent 562b0e3a7f
commit 575ce39696
5 changed files with 29 additions and 3 deletions
+14 -1
View File
@@ -27,7 +27,8 @@ namespace olive {
TimelineMarker::TimelineMarker(const TimeRange &time, const QString &name, QObject *parent) :
QObject(parent),
time_(time),
name_(name)
name_(name),
color_(7) // FIXME: set via config
{
}
@@ -53,6 +54,18 @@ void TimelineMarker::set_name(const QString &name)
emit NameChanged(name_);
}
int TimelineMarker::color()
{
return color_;
}
void TimelineMarker::set_color(int c)
{
color_ = c;
emit ColorChanged(color_);
}
void TimelineMarkerList::Save(QXmlStreamWriter *writer) const
{
foreach (TimelineMarker* marker, markers_) {
+7
View File
@@ -41,16 +41,23 @@ public:
const QString& name() const;
void set_name(const QString& name);
int color();
void set_color(int c);
signals:
void TimeChanged(const TimeRange& time);
void NameChanged(const QString& name);
void ColorChanged(int c);
private:
TimeRange time_;
QString name_;
int color_;
};
class TimelineMarkerList : public QObject
+1 -1
View File
@@ -78,7 +78,7 @@ void Marker::ShowContextMenu() {
// Color menu
ColorLabelMenu color_coding_menu;
connect(&color_coding_menu, &ColorLabelMenu::ColorSelected, this, &Marker::SetColor);
connect(&color_coding_menu, &ColorLabelMenu::ColorSelected, this, &Marker::ColorChanged);
m.addMenu(&color_coding_menu);
m.exec(QCursor::pos());
+4 -1
View File
@@ -34,6 +34,9 @@ class Marker : public QWidget {
public:
Marker(QWidget* parent = nullptr);
public slots:
void SetColor(int c);
protected:
void paintEvent(QPaintEvent* event) override;
//virtual void mouseReleaseEvent(QMouseEvent* event) override;
@@ -42,6 +45,7 @@ class Marker : public QWidget {
signals:
//void MouseClicked();
//void MouseDoubleClicked();
void ColorChanged(int c);
private:
@@ -49,7 +53,6 @@ class Marker : public QWidget {
private slots:
void ShowContextMenu();
void SetColor(int c);
};
} // namespace olive
+3
View File
@@ -143,6 +143,9 @@ void SeekableWidget::addMarker(TimelineMarker* marker)
Marker *marker_widget = new Marker(this);
marker_map_.insert(marker, marker_widget);
connect(marker_widget, &Marker::ColorChanged, marker, &TimelineMarker::set_color);
connect(marker, &TimelineMarker::ColorChanged, marker_widget, &Marker::SetColor);
marker_widget->move(TimeToScreen(marker->time().in()), 20);
marker_widget->show();
}