curvewidget: share color between view and tree
This commit is contained in:
@@ -75,11 +75,6 @@ void CurveView::ConnectInput(NodeInput *input, int element, int track)
|
||||
this->AddKeyframe(key);
|
||||
}
|
||||
|
||||
if (!keyframe_colors_.contains(ref)) {
|
||||
// Generate a random color for this input
|
||||
keyframe_colors_.insert(ref, QColor::fromHsv(std::rand()%360, std::rand()%255, 255));
|
||||
}
|
||||
|
||||
// Append to the list
|
||||
connected_inputs_.append(ref);
|
||||
}
|
||||
@@ -130,6 +125,19 @@ void CurveView::ZoomToFitInput(NodeInput *input, int element, int track)
|
||||
ZoomToFitInternal(keys);
|
||||
}
|
||||
|
||||
void CurveView::SetKeyframeTrackColor(const NodeInput::KeyframeTrackReference &ref, const QColor &color)
|
||||
{
|
||||
// Insert color into hashmap
|
||||
keyframe_colors_.insert(ref, color);
|
||||
|
||||
// Update all keyframes
|
||||
for (auto it=item_map().cbegin(); it!=item_map().cend(); it++) {
|
||||
if (it.key()->parent() == ref.input && it.key()->element() == ref.element && it.key()->track() == ref.track) {
|
||||
it.value()->SetOverrideBrush(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CurveView::drawBackground(QPainter *painter, const QRectF &rect)
|
||||
{
|
||||
if (timebase().isNull()) {
|
||||
@@ -341,17 +349,17 @@ void CurveView::ZoomToFitInternal(const QList<NodeKeyframe *> &keys)
|
||||
double min_val = DBL_MAX;
|
||||
double max_val = DBL_MIN;
|
||||
|
||||
for (auto i=item_map().constBegin(); i!=item_map().constEnd(); i++) {
|
||||
rational transformed_time = GetAdjustedTime(i.key()->parent()->parent(),
|
||||
foreach (NodeKeyframe* key, keys) {
|
||||
rational transformed_time = GetAdjustedTime(key->parent()->parent(),
|
||||
GetTimeTarget(),
|
||||
i.key()->time(),
|
||||
key->time(),
|
||||
false);
|
||||
|
||||
min_time = qMin(transformed_time, min_time);
|
||||
max_time = qMax(transformed_time, max_time);
|
||||
|
||||
min_val = qMin(i.key()->value().toDouble(), min_val);
|
||||
max_val = qMax(i.key()->value().toDouble(), max_val);
|
||||
min_val = qMin(key->value().toDouble(), min_val);
|
||||
max_val = qMax(key->value().toDouble(), max_val);
|
||||
}
|
||||
|
||||
double time_range = max_time.toDouble() - min_time.toDouble();
|
||||
@@ -361,8 +369,10 @@ void CurveView::ZoomToFitInternal(const QList<NodeKeyframe *> &keys)
|
||||
emit ScaleChanged(new_x_scale);
|
||||
SetYScale(new_y_scale);
|
||||
|
||||
horizontalScrollBar()->setValue(TimeToScene(min_time) - CalculatePaddingFromDimensionScale(this->width()));
|
||||
verticalScrollBar()->setValue(GetItemYFromKeyframeValue(max_val) - CalculatePaddingFromDimensionScale(this->height()));
|
||||
QMetaObject::invokeMethod(horizontalScrollBar(), "setValue", Qt::QueuedConnection,
|
||||
Q_ARG(int, TimeToScene(min_time) - CalculatePaddingFromDimensionScale(this->width())));
|
||||
QMetaObject::invokeMethod(verticalScrollBar(), "setValue", Qt::QueuedConnection,
|
||||
Q_ARG(int, GetItemYFromKeyframeValue(max_val) - CalculatePaddingFromDimensionScale(this->height())));
|
||||
}
|
||||
|
||||
qreal CurveView::GetItemYFromKeyframeValue(NodeKeyframe *key)
|
||||
|
||||
@@ -46,6 +46,8 @@ public:
|
||||
|
||||
void ZoomToFitInput(NodeInput* input, int element, int track);
|
||||
|
||||
void SetKeyframeTrackColor(const NodeInput::KeyframeTrackReference& ref, const QColor& color);
|
||||
|
||||
public slots:
|
||||
void AddKeyframe(NodeKeyframe* key);
|
||||
|
||||
|
||||
@@ -229,6 +229,23 @@ void CurveWidget::ConnectInput(NodeInput *input, bool connect)
|
||||
bool multiple_tracks = track_count > 1;
|
||||
|
||||
for (int i=-1; i<input->ArraySize(); i++) {
|
||||
if (!input->IsKeyframable()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Generate a random color for this input
|
||||
for (int j=0; j<input->GetKeyframeTracks(i).size(); j++) {
|
||||
NodeInput::KeyframeTrackReference ref = {input, i, j};
|
||||
|
||||
if (!keyframe_colors_.contains(ref)) {
|
||||
QColor c = QColor::fromHsv(std::rand()%360, std::rand()%255, 255);
|
||||
|
||||
keyframe_colors_.insert(ref, c);
|
||||
tree_view_->SetKeyframeTrackColor(ref, c);
|
||||
view_->SetKeyframeTrackColor(ref, c);
|
||||
}
|
||||
}
|
||||
|
||||
if (tree_view_->IsInputEnabled(input, i, multiple_tracks ? -1 : 0)) {
|
||||
if (multiple_tracks) {
|
||||
for (int j=0; j<track_count; j++) {
|
||||
|
||||
@@ -83,6 +83,8 @@ private:
|
||||
|
||||
void ConnectInput(NodeInput* input, bool connect);
|
||||
|
||||
QHash<NodeInput::KeyframeTrackReference, QColor> keyframe_colors_;
|
||||
|
||||
NodeTreeView* tree_view_;
|
||||
|
||||
QPushButton* linear_button_;
|
||||
|
||||
@@ -23,11 +23,24 @@ bool NodeTreeView::IsInputEnabled(NodeInput *i, int element, int track) const
|
||||
return !disabled_inputs_.contains({i, element, track});
|
||||
}
|
||||
|
||||
void NodeTreeView::SetKeyframeTrackColor(const NodeInput::KeyframeTrackReference &ref, const QColor &color)
|
||||
{
|
||||
// Insert into hashmap
|
||||
keyframe_colors_.insert(ref, color);
|
||||
|
||||
// If we currently have an item for this, set it
|
||||
QTreeWidgetItem* item = item_map_.value(ref);
|
||||
if (item) {
|
||||
item->setForeground(0, color);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeTreeView::SetNodes(const QVector<Node *> &nodes)
|
||||
{
|
||||
nodes_ = nodes;
|
||||
|
||||
this->clear();
|
||||
item_map_.clear();
|
||||
|
||||
foreach (Node* n, nodes_) {
|
||||
QTreeWidgetItem* node_item = new QTreeWidgetItem();
|
||||
@@ -41,24 +54,30 @@ void NodeTreeView::SetNodes(const QVector<Node *> &nodes)
|
||||
continue;
|
||||
}
|
||||
|
||||
int type_track_count = NodeValue::get_number_of_keyframe_tracks(input->GetDataType());
|
||||
bool type_has_multiple_tracks = (type_track_count > 1);
|
||||
QTreeWidgetItem* input_item = nullptr;
|
||||
|
||||
QTreeWidgetItem* input_item = CreateItem(node_item, input, -1, type_has_multiple_tracks ? -1 : 0);
|
||||
for (int i=-1; i<input->ArraySize(); i++) {
|
||||
const QVector<NodeKeyframeTrack>& key_tracks = input->GetKeyframeTracks(i);
|
||||
|
||||
if (input->IsArray()) {
|
||||
for (int i=0; i<input->ArraySize(); i++) {
|
||||
QTreeWidgetItem* element_item = CreateItem(input_item, input, i, type_has_multiple_tracks ? -1 : 0);
|
||||
int this_element_track;
|
||||
|
||||
if (type_has_multiple_tracks && show_keyframe_tracks_as_rows_) {
|
||||
for (int j=0; j<type_track_count; j++) {
|
||||
CreateItem(element_item, input, i, j);
|
||||
}
|
||||
}
|
||||
if (show_keyframe_tracks_as_rows_ && (key_tracks.size() == 1 || (i == -1 && input->IsArray()))) {
|
||||
this_element_track = 0;
|
||||
} else {
|
||||
this_element_track = -1;
|
||||
}
|
||||
} else if (type_has_multiple_tracks && show_keyframe_tracks_as_rows_) {
|
||||
for (int j=0; j<type_track_count; j++) {
|
||||
CreateItem(input_item, input, -1, j);
|
||||
|
||||
QTreeWidgetItem* element_item;
|
||||
|
||||
if (input_item) {
|
||||
element_item = CreateItem(input_item, input, i, this_element_track);
|
||||
} else {
|
||||
input_item = CreateItem(node_item, input, i, this_element_track);
|
||||
element_item = input_item;
|
||||
}
|
||||
|
||||
if (show_keyframe_tracks_as_rows_ && key_tracks.size() > 1 && (!input->IsArray() || i >= 0)) {
|
||||
CreateItemsForTracks(element_item, input, i, key_tracks.size());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,9 +171,24 @@ QTreeWidgetItem* NodeTreeView::CreateItem(QTreeWidgetItem *parent, NodeInput *in
|
||||
input_item->setData(0, kItemElement, element);
|
||||
input_item->setData(0, kItemTrack, track);
|
||||
|
||||
NodeInput::KeyframeTrackReference ref = {input, element, track};
|
||||
|
||||
if (keyframe_colors_.contains(ref)) {
|
||||
input_item->setForeground(0, keyframe_colors_.value(ref));
|
||||
}
|
||||
|
||||
item_map_.insert(ref, input_item);
|
||||
|
||||
return input_item;
|
||||
}
|
||||
|
||||
void NodeTreeView::CreateItemsForTracks(QTreeWidgetItem *parent, NodeInput *input, int element, int track_count)
|
||||
{
|
||||
for (int j=0; j<track_count; j++) {
|
||||
CreateItem(parent, input, element, j);
|
||||
}
|
||||
}
|
||||
|
||||
void NodeTreeView::ItemCheckStateChanged(QTreeWidgetItem *item, int column)
|
||||
{
|
||||
Q_UNUSED(column)
|
||||
|
||||
@@ -17,6 +17,8 @@ public:
|
||||
|
||||
bool IsInputEnabled(NodeInput* i, int element, int track) const;
|
||||
|
||||
void SetKeyframeTrackColor(const NodeInput::KeyframeTrackReference& ref, const QColor& color);
|
||||
|
||||
void SetOnlyShowKeyframable(bool e)
|
||||
{
|
||||
only_show_keyframable_ = e;
|
||||
@@ -51,6 +53,8 @@ private:
|
||||
|
||||
QTreeWidgetItem *CreateItem(QTreeWidgetItem* parent, NodeInput* input, int element, int track);
|
||||
|
||||
void CreateItemsForTracks(QTreeWidgetItem* parent, NodeInput* input, int element, int track_count);
|
||||
|
||||
enum ItemType {
|
||||
kItemTypeNode,
|
||||
kItemTypeInput
|
||||
@@ -67,10 +71,14 @@ private:
|
||||
|
||||
QVector<NodeInput::KeyframeTrackReference> disabled_inputs_;
|
||||
|
||||
QHash<NodeInput::KeyframeTrackReference, QTreeWidgetItem*> item_map_;
|
||||
|
||||
bool only_show_keyframable_;
|
||||
|
||||
bool show_keyframe_tracks_as_rows_;
|
||||
|
||||
QHash<NodeInput::KeyframeTrackReference, QColor> keyframe_colors_;
|
||||
|
||||
private slots:
|
||||
void ItemCheckStateChanged(QTreeWidgetItem* item, int column);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user