From 3fb943864e2f1089c24bb7a99154ff0068f8afd9 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 26 Feb 2023 12:30:13 +0100 Subject: [PATCH] Gui: use Color::fromPackedRGBA to simplify client code --- src/Gui/NaviCube.cpp | 21 ++++++++------------- src/Gui/View3DInventor.cpp | 16 ++++++---------- 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/Gui/NaviCube.cpp b/src/Gui/NaviCube.cpp index 9f856e4fa5..5f7a291b46 100644 --- a/src/Gui/NaviCube.cpp +++ b/src/Gui/NaviCube.cpp @@ -44,6 +44,7 @@ # include #endif +#include #include #include @@ -404,27 +405,22 @@ void NaviCubeImplementation::OnChange(ParameterGrp::SubjectType& rCaller, // QColor expects the form AARRGGBB therefore we must make a shift in writing to QColor unsigned long col = rGrp.GetUnsigned(reason, 255); // 255 is RRR,GGG,BBB,AAA: 0,0,0,255 - QColor textColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - m_TextColor = textColor; + m_TextColor = App::Color::fromPackedRGBA(col); } else if (strcmp(reason, "FrontColor") == 0) { unsigned long col = rGrp.GetUnsigned(reason, 3806916544); - // 3236096495 is RRR,GGG,BBB,AAA: 226,233,239,192 - QColor frontColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - m_FrontColor = frontColor; + // 3236096495 is RRR,GGG,BBB,AAA: 226,232,239,192 + m_FrontColor = App::Color::fromPackedRGBA(col); } else if (strcmp(reason, "HiliteColor") == 0) { unsigned long col = rGrp.GetUnsigned(reason, 2867003391); // 2867003391 is RRR,GGG,BBB,AAA: 170,226,255,255 - QColor hiliteColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - m_HiliteColor = hiliteColor; + m_HiliteColor = App::Color::fromPackedRGBA(col); } else if (strcmp(reason, "ButtonColor") == 0) { unsigned long col = rGrp.GetUnsigned(reason, 3806916480); - // 3806916480 is RRR,GGG,BBB,AAA: 226,233,239,128 - QColor buttonColor( - (col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - m_ButtonColor = buttonColor; + // 3806916480 is RRR,GGG,BBB,AAA: 226,232,239,128 + m_ButtonColor = App::Color::fromPackedRGBA(col); } else if (strcmp(reason, "CornerNaviCube") == 0) { m_Corner = static_cast(rGrp.GetInt(reason, 1)); @@ -444,8 +440,7 @@ void NaviCubeImplementation::OnChange(ParameterGrp::SubjectType& rCaller, else if (strcmp(reason, "BorderColor") == 0) { unsigned long col = rGrp.GetUnsigned(reason, 842150655); // 842150655 is RRR,GGG,BBB,AAA: 50,50,50,255 - QColor borderColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - m_BorderColor = borderColor; + m_BorderColor = App::Color::fromPackedRGBA(col); } else if (strcmp(reason, "FontSize") == 0) { m_CubeTextSize = rGrp.GetInt(reason, getDefaultFontSize()); diff --git a/src/Gui/View3DInventor.cpp b/src/Gui/View3DInventor.cpp index 436b6fcf1b..413218967f 100644 --- a/src/Gui/View3DInventor.cpp +++ b/src/Gui/View3DInventor.cpp @@ -51,6 +51,7 @@ # include #endif +#include #include #include #include @@ -404,31 +405,26 @@ void View3DInventor::OnChange(ParameterGrp::SubjectType &rCaller,ParameterGrp::M } else if (strcmp(Reason, "TextColor") == 0) { unsigned long col = rGrp.GetUnsigned("TextColor", 255); - QColor textColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - _viewer->getNavigationCube()->setTextColor(textColor); + _viewer->getNavigationCube()->setTextColor(App::Color::fromPackedRGBA(col)); } else if (strcmp(Reason, "FrontColor") == 0) { unsigned long col = rGrp.GetUnsigned("FrontColor", 3806916544); - QColor frontColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - _viewer->getNavigationCube()->setFrontColor(frontColor); + _viewer->getNavigationCube()->setFrontColor(App::Color::fromPackedRGBA(col)); } else if (strcmp(Reason, "HiliteColor") == 0) { unsigned long col = rGrp.GetUnsigned("HiliteColor", 2867003391); - QColor hiliteColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - _viewer->getNavigationCube()->setHiliteColor(hiliteColor); + _viewer->getNavigationCube()->setHiliteColor(App::Color::fromPackedRGBA(col)); } else if (strcmp(Reason, "ButtonColor") == 0) { unsigned long col = rGrp.GetUnsigned("ButtonColor", 3806916480); - QColor buttonColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - _viewer->getNavigationCube()->setButtonColor(buttonColor); + _viewer->getNavigationCube()->setButtonColor(App::Color::fromPackedRGBA(col)); } else if (strcmp(Reason, "BorderWidth") == 0) { _viewer->getNavigationCube()->setBorderWidth(rGrp.GetFloat("BorderWidth", 1.1)); } else if (strcmp(Reason, "BorderColor") == 0) { unsigned long col = rGrp.GetUnsigned("BorderColor", 842150655); - QColor borderColor((col >> 24) & 0xff, (col >> 16) & 0xff, (col >> 8) & 0xff, col & 0xff); - _viewer->getNavigationCube()->setBorderColor(borderColor); + _viewer->getNavigationCube()->setBorderColor(App::Color::fromPackedRGBA(col)); } else if (strcmp(Reason,"UseVBO") == 0) { _viewer->setEnabledVBO(rGrp.GetBool("UseVBO", false));