From 9d2fc71efc3d656e670042cb7c9fa59679433486 Mon Sep 17 00:00:00 2001 From: itsmattkc Date: Tue, 16 Jul 2019 01:49:58 -0400 Subject: [PATCH] removed magic colors from node items and moved to css --- app/ui/style/olive-dark/style.css | 4 ++ app/ui/style/olive-light/style.css | 4 ++ app/widget/nodeview/nodeviewedge.cpp | 10 +++-- app/widget/nodeview/nodeviewedge.h | 3 ++ app/widget/nodeview/nodeviewitem.cpp | 62 ++++++++++++++-------------- app/widget/nodeview/nodeviewitem.h | 19 ++++++--- 6 files changed, 62 insertions(+), 40 deletions(-) diff --git a/app/ui/style/olive-dark/style.css b/app/ui/style/olive-dark/style.css index fd9ee55a2..91b56c833 100644 --- a/app/ui/style/olive-dark/style.css +++ b/app/ui/style/olive-dark/style.css @@ -67,3 +67,7 @@ QTreeView, QListView, QLineEdit, QMenu, QProgressBar, QPushButton::checked, Node /* Dark */ background: #191919; } + +NodeViewItemWidgetProxy { + qproperty-titlebarColor: #4040a0; +} diff --git a/app/ui/style/olive-light/style.css b/app/ui/style/olive-light/style.css index 9ea4c9ec3..ae3e81385 100644 --- a/app/ui/style/olive-light/style.css +++ b/app/ui/style/olive-light/style.css @@ -67,3 +67,7 @@ QTreeView, QListView, QLineEdit, QMenu, QProgressBar, QPushButton::checked, Node /* Dark */ background: #ffffff; } + +NodeViewItemWidgetProxy { + qproperty-titlebarColor: #a0a0ff; +} diff --git a/app/widget/nodeview/nodeviewedge.cpp b/app/widget/nodeview/nodeviewedge.cpp index 87cb9e1f9..8b3bba487 100644 --- a/app/widget/nodeview/nodeviewedge.cpp +++ b/app/widget/nodeview/nodeviewedge.cpp @@ -30,9 +30,6 @@ NodeViewEdge::NodeViewEdge(QGraphicsItem *parent) : QGraphicsLineItem(parent), edge_(nullptr) { - // FIXME: This should probably be set to the text color in order to work on light themes - setPen(QPen(Qt::white, 2)); - // Ensures this UI object is drawn behind other objects setZValue(-1); } @@ -71,6 +68,13 @@ void NodeViewEdge::Adjust() )); } +void NodeViewEdge::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +{ + setPen(QPen(widget->palette().color(QPalette::Text), 2)); + + QGraphicsLineItem::paint(painter, option, widget); +} + qreal NodeViewEdge::CalculateEdgeYPoint(NodeViewItem *item, int param_index, NodeViewItem *opposing) { if (item->IsExpanded()) { diff --git a/app/widget/nodeview/nodeviewedge.h b/app/widget/nodeview/nodeviewedge.h index 8f78017bc..b626ae988 100644 --- a/app/widget/nodeview/nodeviewedge.h +++ b/app/widget/nodeview/nodeviewedge.h @@ -35,6 +35,9 @@ public: void Adjust(); +protected: + virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override; + private: qreal CalculateEdgeYPoint(NodeViewItem* item, int param_index, NodeViewItem* opposing); diff --git a/app/widget/nodeview/nodeviewitem.cpp b/app/widget/nodeview/nodeviewitem.cpp index 378c0c328..b7dba5902 100644 --- a/app/widget/nodeview/nodeviewitem.cpp +++ b/app/widget/nodeview/nodeviewitem.cpp @@ -25,7 +25,9 @@ #include #include +#include "core.h" #include "ui/icons/icons.h" +#include "window/mainwindow/mainwindow.h" const int kNodeViewItemBorderWidth = 2; const int kNodeViewItemWidth = 250; @@ -50,19 +52,6 @@ NodeViewItem::NodeViewItem(QGraphicsItem *parent) : // Set default node connector size node_connector_size_ = font_metrics.height() / 3; - - // FIXME: Magic "number"/magic "color" - allow this to be editable by the user - SetColor(QColor(48, 48, 192)); -} - -void NodeViewItem::SetColor(const QColor &color) -{ - color_ = color; - - // Create a light gradient based on this color - UpdateGradient(); - - update(); } void NodeViewItem::SetNode(Node *n) @@ -148,27 +137,28 @@ QPointF NodeViewItem::GetParameterTextPoint(int index) } } -void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) +void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { + // HACK for getting the main QWidget palette color (the `widget`'s palette uses the NodeView color instead which we + // don't want here) + QPalette app_pal = olive::core.main_window()->palette(); + // Set up border, which will change color if selected // FIXME: Color not configurable? QPen border_pen(Qt::black, kNodeViewItemBorderWidth); - // FIXME: The text is always drawn white assuming the color will be dark - the intention is to provide preset - // colors that will always be dark for the user to choose, so this value can stay white. - QPen text_pen(Qt::white); + QPen text_pen(app_pal.color(QPalette::Text)); - // FIXME: Same as text_pen - QBrush connector_brush(Qt::white); - - // FIXME: Same as above - QBrush content_brush(QColor("#353535")); + QBrush connector_brush(app_pal.color(QPalette::Text)); painter->setPen(border_pen); if (expanded_ && node_ != nullptr) { + + + painter->setBrush(app_pal.window()); + // Draw background rect - painter->setBrush(content_brush); painter->drawRect(rect()); // Set pen to draw text @@ -178,7 +168,6 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti // Store the text points which will steadily increase sa we loop - // Loop through all the parameters QList node_params = node_->parameters(); for (int i=0;isetBrush(brush()); + painter->setBrush(obj_proxy_.TitleBarColor()); painter->drawRect(title_bar_rect_); // If selected, draw selection outline if (option->state & QStyle::State_Selected) { QPen pen = painter->pen(); - pen.setColor(widget->palette().highlight().color()); + pen.setColor(app_pal.color(QPalette::Highlight)); painter->setPen(pen); painter->setBrush(Qt::transparent); @@ -251,6 +240,9 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti void NodeViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) { + // We override standard mouse behavior in some cases. In these cases, we don't want the standard "move" and "release" + // events to trigger if we haven't already triggered the "press" event. We use this variable to determine whether + // base class behavior is valid here. standard_click_ = false; // Don't initiate a drag if we clicked the expand hitbox @@ -268,6 +260,7 @@ void NodeViewItem::mousePressEvent(QGraphicsSceneMouseEvent *event) } } + // We aren't using any override behaviors, switch back to standard click behavior standard_click_ = true; QGraphicsRectItem::mousePressEvent(event); } @@ -291,11 +284,16 @@ void NodeViewItem::mouseReleaseEvent(QGraphicsSceneMouseEvent *event) } } -void NodeViewItem::UpdateGradient() +NodeViewItemWidgetProxy::NodeViewItemWidgetProxy() { - /*QLinearGradient grad(QPointF(0, rect().top()), QPointF(0, rect().bottom())); - grad.setColorAt(0, color_.lighter(175)); - grad.setColorAt(1, color_); - setBrush(grad);*/ - setBrush(color_); +} + +QColor NodeViewItemWidgetProxy::TitleBarColor() +{ + return title_bar_color_; +} + +void NodeViewItemWidgetProxy::SetTitleBarColor(QColor color) +{ + title_bar_color_ = color; } diff --git a/app/widget/nodeview/nodeviewitem.h b/app/widget/nodeview/nodeviewitem.h index b5a1fd3d4..46db61c90 100644 --- a/app/widget/nodeview/nodeviewitem.h +++ b/app/widget/nodeview/nodeviewitem.h @@ -24,16 +24,27 @@ #include #include #include +#include #include "node/node.h" +class NodeViewItemWidgetProxy : public QWidget { + Q_OBJECT + Q_PROPERTY(QColor titlebarColor READ TitleBarColor WRITE SetTitleBarColor DESIGNABLE true) +public: + NodeViewItemWidgetProxy(); + + QColor TitleBarColor(); + void SetTitleBarColor(QColor color); +private: + QColor title_bar_color_; +}; + class NodeViewItem : public QGraphicsRectItem { public: NodeViewItem(QGraphicsItem* parent = nullptr); - void SetColor(const QColor& color); - void SetNode(Node* n); Node* node(); @@ -52,13 +63,11 @@ protected: virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) override; private: - void UpdateGradient(); - QRectF expand_hitbox_; Node* node_; - QColor color_; + NodeViewItemWidgetProxy obj_proxy_; QRectF title_bar_rect_;