Gui: use Color::asPackedRGB<QColor>()

This commit is contained in:
wmayer
2023-02-25 18:21:16 +01:00
committed by wwmayer
parent 41e6c17605
commit 7c359469ba
7 changed files with 44 additions and 39 deletions

View File

@@ -30,6 +30,7 @@
#include "ui_DlgEditor.h"
#include "PythonEditor.h"
#include "Tools.h"
#include <App/Color.h>
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<QColor>(col);
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::cyan));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::red));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::blue));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(0, 170, 0));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(160, 160, 164));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::blue));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::red));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::red));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(255, 170, 0));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(255, 170, 0));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(160, 160, 164));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(170, 170, 127));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(Qt::red));
d->colormap.push_back(QPair<QString, unsigned int>
(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>(QColor(224, 224, 224));
d->colormap.push_back(QPair<QString, unsigned int>
(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<QColor>(col);
int index = ui->displayItems->indexOfTopLevelItem(ui->displayItems->currentItem());
d->colormap[index].second = lcol;

View File

@@ -30,6 +30,7 @@
#include <Base/Console.h>
#include <Base/Tools.h>
#include <App/Color.h>
#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<QColor>(m_Default);
unsigned long lcol = static_cast<unsigned long>(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<QColor>(col);
unsigned long lcol = static_cast<unsigned long>(icol);
getWindowParameter()->SetUnsigned( entryName(), lcol );
}

View File

@@ -36,6 +36,7 @@
#endif
#include <Base/Interpreter.h>
#include <App/Color.h>
#include "PythonConsole.h"
#include "PythonConsolePy.h"
@@ -528,7 +529,7 @@ void PythonConsole::OnChange(Base::Subject<const char*> &rCaller, const char* sR
QMap<QString, QColor>::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<QColor>(color);
auto value = static_cast<unsigned long>(col);
value = rGrp.GetUnsigned(sReason, value);
col = static_cast<unsigned int>(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<QColor>(color);
auto value = static_cast<unsigned long>(text);
// if this parameter is not already set use the style's window text color
value = getWindowParameter()->GetUnsigned("Text", value);

View File

@@ -32,6 +32,7 @@
#endif
#include <Base/Interpreter.h>
#include <App/Color.h>
#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<QColor>(color);
auto value = static_cast<unsigned long>(text);
// if this parameter is not already set use the style's window text color
value = getWindowParameter()->GetUnsigned("colorText", value);

View File

@@ -35,6 +35,7 @@
#include "TextEdit.h"
#include "SyntaxHighlighter.h"
#include "Tools.h"
#include <App/Color.h>
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<QColor>(lineColor);
ParameterGrp::handle hPrefGrp = getWindowParameter();
auto value = static_cast<unsigned long>(col);
value = hPrefGrp->GetUnsigned( "Current line highlight", value);
@@ -456,7 +457,7 @@ void TextEditor::OnChange(Base::Subject<const char*> &rCaller,const char* sReaso
QMap<QString, QColor>::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<QColor>(color);
auto value = static_cast<unsigned long>(col);
value = hPrefGrp->GetUnsigned(sReason, value);
col = static_cast<unsigned int>(value);

View File

@@ -23,6 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <algorithm>
# include <iomanip>
# include <ios>
# include <sstream>
# include <QCursor>

View File

@@ -23,6 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <iomanip>
# include <sstream>
# include <QLocale>
# include <boost/tokenizer.hpp>