nodes: use different colors from config based on category
This commit is contained in:
@@ -83,6 +83,16 @@ void Config::SetDefaults()
|
||||
config_map_["DropWithoutSequenceBehavior"] = TimelineWidget::kDWSAsk;
|
||||
config_map_["Loop"] = false;
|
||||
|
||||
config_map_["NodeCatColor0"] = QVariant::fromValue(Color(0.25, 0.25, 0.65));
|
||||
config_map_["NodeCatColor1"] = QVariant::fromValue(Color(0.6, 0.6, 0.85));
|
||||
config_map_["NodeCatColor2"] = QVariant::fromValue(Color(0.75, 0.75, 0.45));
|
||||
config_map_["NodeCatColor3"] = QVariant::fromValue(Color(0.25, 0.5, 0.25));
|
||||
config_map_["NodeCatColor4"] = QVariant::fromValue(Color(0.25, 0.65, 0.25));
|
||||
config_map_["NodeCatColor5"] = QVariant::fromValue(Color(0.35, 0.35, 0.35));
|
||||
config_map_["NodeCatColor6"] = QVariant::fromValue(Color(0.45, 0.45, 0.45));
|
||||
config_map_["NodeCatColor7"] = QVariant::fromValue(Color(0.7, 0.3, 0.7));
|
||||
config_map_["NodeCatColor8"] = QVariant::fromValue(Color(0.85, 0.65, 0.4));
|
||||
|
||||
config_map_["AudioOutput"] = QString();
|
||||
config_map_["AudioInput"] = QString();
|
||||
|
||||
|
||||
@@ -207,6 +207,11 @@ QColor Color::toQColor() const
|
||||
return c;
|
||||
}
|
||||
|
||||
float Color::GetRoughLuminance() const
|
||||
{
|
||||
return (2*red()+blue()+3*green())/6.0f;
|
||||
}
|
||||
|
||||
const Color &Color::operator+=(const Color &rhs)
|
||||
{
|
||||
for (int i=0;i<kRGBAChannels;i++) {
|
||||
|
||||
@@ -86,6 +86,10 @@ public:
|
||||
|
||||
QColor toQColor() const;
|
||||
|
||||
// Suuuuper rough luminance value mostly used for UI (determining whether to overlay with black
|
||||
// or white text)
|
||||
float GetRoughLuminance() const;
|
||||
|
||||
// Assignment math operators
|
||||
const Color& operator+=(const Color& rhs);
|
||||
const Color& operator-=(const Color& rhs);
|
||||
|
||||
@@ -77,9 +77,7 @@ void ColorSwatchWidget::SelectedColorChangedEvent(const Color &, bool)
|
||||
|
||||
Qt::GlobalColor ColorSwatchWidget::GetUISelectorColor() const
|
||||
{
|
||||
float rough_color_luma = (GetSelectedColor().red()+GetSelectedColor().red()+GetSelectedColor().blue()+GetSelectedColor().green()+GetSelectedColor().green()+GetSelectedColor().green())/6;
|
||||
|
||||
if (rough_color_luma > 0.66) {
|
||||
if (GetSelectedColor().GetRoughLuminance() > 0.66) {
|
||||
return Qt::black;
|
||||
} else {
|
||||
return Qt::white;
|
||||
|
||||
@@ -28,6 +28,7 @@
|
||||
|
||||
#include "common/flipmodifiers.h"
|
||||
#include "common/qtutils.h"
|
||||
#include "config/config.h"
|
||||
#include "core.h"
|
||||
#include "nodeview.h"
|
||||
#include "nodeviewscene.h"
|
||||
@@ -260,8 +261,11 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
// Draw the titlebar
|
||||
if (!hide_titlebar_ && node_) {
|
||||
|
||||
Color node_color = Config::Current()[QStringLiteral("NodeCatColor%1")
|
||||
.arg(node_->Category().first())].value<Color>();
|
||||
|
||||
painter->setPen(Qt::black);
|
||||
painter->setBrush(css_proxy_.TitleBarColor());
|
||||
painter->setBrush(node_color.toQColor());
|
||||
|
||||
painter->drawRect(title_bar_rect_);
|
||||
|
||||
@@ -293,6 +297,12 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
}
|
||||
}
|
||||
|
||||
if (node_color.GetRoughLuminance() > 0.66) {
|
||||
painter->setPen(Qt::black);
|
||||
} else {
|
||||
painter->setPen(Qt::white);
|
||||
}
|
||||
|
||||
// Draw the text in a rect (the rect is sized around text already in the constructor)
|
||||
painter->drawText(title_bar_rect_,
|
||||
Qt::AlignCenter,
|
||||
@@ -307,7 +317,7 @@ void NodeViewItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *opti
|
||||
if (option->state & QStyle::State_Selected) {
|
||||
border_pen.setColor(app_pal.color(QPalette::Highlight));
|
||||
} else {
|
||||
border_pen.setColor(css_proxy_.BorderColor());
|
||||
border_pen.setColor(Qt::black);
|
||||
}
|
||||
|
||||
painter->setPen(border_pen);
|
||||
|
||||
@@ -130,13 +130,6 @@ private:
|
||||
*/
|
||||
QList<NodeInput*> node_inputs_;
|
||||
|
||||
/**
|
||||
* @brief A QWidget that can receive CSS properties that NodeViewItem can use
|
||||
*
|
||||
* \see NodeViewItemWidget
|
||||
*/
|
||||
NodeViewItemWidget css_proxy_;
|
||||
|
||||
/**
|
||||
* @brief Rectangle of the Node's title bar (equal to rect() when collapsed)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user