From 7c359469ba868d97bf317dc748b0e9f5a7828e67 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 25 Feb 2023 18:21:16 +0100 Subject: [PATCH] Gui: use Color::asPackedRGB() --- src/Gui/DlgEditorImp.cpp | 61 +++++++++++----------- src/Gui/PrefWidgets.cpp | 7 ++- src/Gui/PythonConsole.cpp | 5 +- src/Gui/ReportView.cpp | 3 +- src/Gui/TextEdit.cpp | 5 +- src/Mod/Mesh/Gui/ViewProviderCurvature.cpp | 1 + src/Mod/Spreadsheet/App/Cell.cpp | 1 + 7 files changed, 44 insertions(+), 39 deletions(-) diff --git a/src/Gui/DlgEditorImp.cpp b/src/Gui/DlgEditorImp.cpp index eaea382cfd..ebb8688101 100644 --- a/src/Gui/DlgEditorImp.cpp +++ b/src/Gui/DlgEditorImp.cpp @@ -30,6 +30,7 @@ #include "ui_DlgEditor.h" #include "PythonEditor.h" #include "Tools.h" +#include using namespace Gui; @@ -96,63 +97,63 @@ DlgSettingsEditorImp::DlgSettingsEditorImp( QWidget* parent ) d = new DlgSettingsEditorP(); QColor col; col = qApp->palette().windowText().color(); - unsigned int lText = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + unsigned int lText = App::Color::asPackedRGB(col); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Text")), lText)); - col = Qt::cyan; - unsigned int lBookmarks = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lBookmarks = App::Color::asPackedRGB(QColor(Qt::cyan)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Bookmark")), lBookmarks)); - col = Qt::red; - unsigned int lBreakpnts = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lBreakpnts = App::Color::asPackedRGB(QColor(Qt::red)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Breakpoint")), lBreakpnts)); - col = Qt::blue; - unsigned int lKeywords = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lKeywords = App::Color::asPackedRGB(QColor(Qt::blue)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Keyword")), lKeywords)); - col.setRgb(0, 170, 0); - unsigned int lComments = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lComments = App::Color::asPackedRGB(QColor(0, 170, 0)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Comment")), lComments)); - col.setRgb(160, 160, 164); - unsigned int lBlockCom = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lBlockCom = App::Color::asPackedRGB(QColor(160, 160, 164)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Block comment")), lBlockCom)); - col = Qt::blue; - unsigned int lNumbers = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lNumbers = App::Color::asPackedRGB(QColor(Qt::blue)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Number")), lNumbers)); - col = Qt::red; - unsigned int lStrings = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lStrings = App::Color::asPackedRGB(QColor(Qt::red)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("String")), lStrings)); - col = Qt::red; - unsigned int lCharacter = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lCharacter = App::Color::asPackedRGB(QColor(Qt::red)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Character")), lCharacter)); - col.setRgb(255, 170, 0); - unsigned int lClass = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lClass = App::Color::asPackedRGB(QColor(255, 170, 0)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Class name")), lClass)); - col.setRgb(255, 170, 0); - unsigned int lDefine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lDefine = App::Color::asPackedRGB(QColor(255, 170, 0)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Define name")), lDefine)); - col.setRgb(160, 160, 164); - unsigned int lOperat = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lOperat = App::Color::asPackedRGB(QColor(160, 160, 164)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Operator")), lOperat)); - col.setRgb(170, 170, 127); - unsigned int lPyOutput = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lPyOutput = App::Color::asPackedRGB(QColor(170, 170, 127)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Python output")), lPyOutput)); - col = Qt::red; - unsigned int lPyError = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lPyError = App::Color::asPackedRGB(QColor(Qt::red)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Python error")), lPyError)); - col.setRgb(224, 224, 224); - unsigned int lCLine = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + + unsigned int lCLine = App::Color::asPackedRGB(QColor(224, 224, 224)); d->colormap.push_back(QPair (QString::fromLatin1(QT_TR_NOOP("Current line highlight")), lCLine)); @@ -190,7 +191,7 @@ void DlgSettingsEditorImp::on_displayItems_currentItemChanged(QTreeWidgetItem *i void DlgSettingsEditorImp::on_colorButton_changed() { QColor col = ui->colorButton->color(); - unsigned int lcol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8); + unsigned int lcol = App::Color::asPackedRGB(col); int index = ui->displayItems->indexOfTopLevelItem(ui->displayItems->currentItem()); d->colormap[index].second = lcol; diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index 0c06e9ea82..0917495208 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -30,6 +30,7 @@ #include #include +#include #include "PrefWidgets.h" @@ -555,9 +556,7 @@ void PrefColorButton::restorePreferences() if (!m_Restored) m_Default = color(); - const QColor &col = m_Default; - - unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | col.alpha(); + unsigned int icol = App::Color::asPackedRGBA(m_Default); unsigned long lcol = static_cast(icol); lcol = getWindowParameter()->GetUnsigned( entryName(), lcol ); @@ -581,7 +580,7 @@ void PrefColorButton::savePreferences() QColor col = color(); // (r,g,b,a) with a = 255 (opaque) - unsigned int icol = (col.red() << 24) | (col.green() << 16) | (col.blue() << 8) | col.alpha(); + unsigned int icol = App::Color::asPackedRGBA(col); unsigned long lcol = static_cast(icol); getWindowParameter()->SetUnsigned( entryName(), lcol ); } diff --git a/src/Gui/PythonConsole.cpp b/src/Gui/PythonConsole.cpp index a5007f60b6..dd553cedd3 100644 --- a/src/Gui/PythonConsole.cpp +++ b/src/Gui/PythonConsole.cpp @@ -36,6 +36,7 @@ #endif #include +#include #include "PythonConsole.h" #include "PythonConsolePy.h" @@ -528,7 +529,7 @@ void PythonConsole::OnChange(Base::Subject &rCaller, const char* sR QMap::Iterator it = d->colormap.find(QString::fromLatin1(sReason)); if (it != d->colormap.end()) { QColor color = it.value(); - unsigned int col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8); + unsigned int col = App::Color::asPackedRGB(color); auto value = static_cast(col); value = rGrp.GetUnsigned(sReason, value); col = static_cast(value); @@ -960,7 +961,7 @@ void PythonConsole::changeEvent(QEvent *e) else if (e->type() == QEvent::StyleChange) { QPalette pal = qApp->palette(); QColor color = pal.windowText().color(); - unsigned int text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8); + unsigned int text = App::Color::asPackedRGB(color); auto value = static_cast(text); // if this parameter is not already set use the style's window text color value = getWindowParameter()->GetUnsigned("Text", value); diff --git a/src/Gui/ReportView.cpp b/src/Gui/ReportView.cpp index e518cad362..dff29ef9a9 100644 --- a/src/Gui/ReportView.cpp +++ b/src/Gui/ReportView.cpp @@ -32,6 +32,7 @@ #endif #include +#include #include "ReportView.h" #include "Application.h" @@ -528,7 +529,7 @@ void ReportOutput::changeEvent(QEvent *ev) if (ev->type() == QEvent::StyleChange) { QPalette pal = qApp->palette(); QColor color = pal.windowText().color(); - unsigned int text = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8); + unsigned int text = App::Color::asPackedRGB(color); auto value = static_cast(text); // if this parameter is not already set use the style's window text color value = getWindowParameter()->GetUnsigned("colorText", value); diff --git a/src/Gui/TextEdit.cpp b/src/Gui/TextEdit.cpp index d57b820def..46e1803383 100644 --- a/src/Gui/TextEdit.cpp +++ b/src/Gui/TextEdit.cpp @@ -35,6 +35,7 @@ #include "TextEdit.h" #include "SyntaxHighlighter.h" #include "Tools.h" +#include using namespace Gui; @@ -291,7 +292,7 @@ void TextEditor::highlightCurrentLine() if (!isReadOnly()) { QTextEdit::ExtraSelection selection; QColor lineColor = d->colormap[QLatin1String("Current line highlight")]; - unsigned int col = (lineColor.red() << 24) | (lineColor.green() << 16) | (lineColor.blue() << 8); + unsigned int col = App::Color::asPackedRGB(lineColor); ParameterGrp::handle hPrefGrp = getWindowParameter(); auto value = static_cast(col); value = hPrefGrp->GetUnsigned( "Current line highlight", value); @@ -456,7 +457,7 @@ void TextEditor::OnChange(Base::Subject &rCaller,const char* sReaso QMap::Iterator it = d->colormap.find(QString::fromLatin1(sReason)); if (it != d->colormap.end()) { QColor color = it.value(); - unsigned int col = (color.red() << 24) | (color.green() << 16) | (color.blue() << 8); + unsigned int col = App::Color::asPackedRGB(color); auto value = static_cast(col); value = hPrefGrp->GetUnsigned(sReason, value); col = static_cast(value); diff --git a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp index 3a835f3a41..699db3c801 100644 --- a/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp +++ b/src/Mod/Mesh/Gui/ViewProviderCurvature.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include # include # include # include diff --git a/src/Mod/Spreadsheet/App/Cell.cpp b/src/Mod/Spreadsheet/App/Cell.cpp index 9b6701ff5f..3c4075533b 100644 --- a/src/Mod/Spreadsheet/App/Cell.cpp +++ b/src/Mod/Spreadsheet/App/Cell.cpp @@ -23,6 +23,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include # include # include # include