curveview: color code keyframe tracks when more than one is present
This commit is contained in:
@@ -92,9 +92,9 @@ void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
painter->drawLines(lines);
|
||||
|
||||
// Draw keyframe lines
|
||||
painter->setPen(QPen(palette().text().color(), qMax(1, fontMetrics().height() / 4)));
|
||||
|
||||
for (int j=0;j<track_count_;j++) {
|
||||
painter->setPen(QPen(GetKeyframeColor(j), qMax(1, fontMetrics().height() / 4)));
|
||||
QList<NodeKeyframe*> keys = GetKeyframesSortedByTime(j);
|
||||
|
||||
if (!keys.isEmpty()) {
|
||||
@@ -290,6 +290,17 @@ void CurveView::CreateBezierControlPoints(KeyframeViewItem* item)
|
||||
connect(bezier_out_pt, &QObject::destroyed, this, &CurveView::BezierControlPointDestroyed, Qt::DirectConnection);
|
||||
}
|
||||
|
||||
QColor CurveView::GetKeyframeColor(int track) const
|
||||
{
|
||||
if (track_count_) {
|
||||
QColor c;
|
||||
c.setHsvF(static_cast<double>(track) / static_cast<double>(track_count_), 0.5, 1.0);
|
||||
return c;
|
||||
}
|
||||
|
||||
return palette().text().color();
|
||||
}
|
||||
|
||||
void CurveView::KeyframeValueChanged()
|
||||
{
|
||||
NodeKeyframe* key = static_cast<NodeKeyframe*>(sender());
|
||||
@@ -338,6 +349,7 @@ void CurveView::AddKeyframe(NodeKeyframePtr key)
|
||||
{
|
||||
KeyframeViewItem* item = AddKeyframeInternal(key);
|
||||
SetItemYFromKeyframeValue(key.get(), item);
|
||||
item->SetOverrideBrush(GetKeyframeColor(key->track()));
|
||||
|
||||
connect(key.get(), &NodeKeyframe::ValueChanged, this, &CurveView::KeyframeValueChanged);
|
||||
connect(key.get(), &NodeKeyframe::TypeChanged, this, &CurveView::KeyframeTypeChanged);
|
||||
|
||||
@@ -44,6 +44,8 @@ private:
|
||||
|
||||
void CreateBezierControlPoints(KeyframeViewItem *item);
|
||||
|
||||
QColor GetKeyframeColor(int track) const;
|
||||
|
||||
int text_padding_;
|
||||
|
||||
int minimum_grid_space_;
|
||||
|
||||
@@ -12,7 +12,8 @@ KeyframeViewItem::KeyframeViewItem(NodeKeyframePtr key, QGraphicsItem *parent) :
|
||||
QGraphicsRectItem(parent),
|
||||
key_(key),
|
||||
scale_(1.0),
|
||||
vert_center_(0)
|
||||
vert_center_(0),
|
||||
use_custom_brush_(false)
|
||||
{
|
||||
setFlag(QGraphicsItem::ItemIsSelectable);
|
||||
|
||||
@@ -24,6 +25,8 @@ KeyframeViewItem::KeyframeViewItem(NodeKeyframePtr key, QGraphicsItem *parent) :
|
||||
setRect(-half_sz, -half_sz, keyframe_size, keyframe_size);
|
||||
|
||||
UpdatePos();
|
||||
|
||||
// Set default brush
|
||||
}
|
||||
|
||||
void KeyframeViewItem::SetOverrideY(qreal vertical_center)
|
||||
@@ -38,6 +41,12 @@ void KeyframeViewItem::SetScale(double scale)
|
||||
UpdatePos();
|
||||
}
|
||||
|
||||
void KeyframeViewItem::SetOverrideBrush(const QBrush &b)
|
||||
{
|
||||
use_custom_brush_ = true;
|
||||
setBrush(b);
|
||||
}
|
||||
|
||||
NodeKeyframePtr KeyframeViewItem::key() const
|
||||
{
|
||||
return key_;
|
||||
@@ -51,6 +60,8 @@ void KeyframeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *
|
||||
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
painter->setBrush(widget->palette().highlight());
|
||||
} else if (use_custom_brush_) {
|
||||
painter->setBrush(brush());
|
||||
} else {
|
||||
painter->setBrush(widget->palette().text());
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ public:
|
||||
|
||||
void SetScale(double scale);
|
||||
|
||||
void SetOverrideBrush(const QBrush& b);
|
||||
|
||||
NodeKeyframePtr key() const;
|
||||
|
||||
protected:
|
||||
@@ -30,6 +32,8 @@ private:
|
||||
|
||||
qreal vert_center_;
|
||||
|
||||
bool use_custom_brush_;
|
||||
|
||||
private slots:
|
||||
void UpdatePos();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user