Gui: Prepare for clang-format (#16051)

* Gui: Prepare for clang-format

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
wwmayer
2024-09-02 17:48:55 +02:00
committed by GitHub
parent e98ffc3060
commit 977e13795a
31 changed files with 4133 additions and 3093 deletions

View File

@@ -23,7 +23,7 @@
#include "PreCompiled.h"
#ifndef _PreComp_
# include <QFontDatabase>
#include <QFontDatabase>
#endif
#include <App/Color.h>
@@ -37,14 +37,16 @@
using namespace Gui;
using namespace Gui::Dialog;
namespace Gui {
namespace Dialog {
namespace Gui
{
namespace Dialog
{
struct DlgSettingsEditorP
{
QVector<QPair<QString, unsigned int> > colormap; // Color map
QVector<QPair<QString, unsigned int>> colormap; // Color map
};
} // namespace Dialog
} // namespace Gui
} // namespace Dialog
} // namespace Gui
namespace
{
@@ -58,20 +60,24 @@ namespace
QFont getMonospaceFont()
{
QFont font(QString::fromLatin1("monospace"));
if (font.fixedPitch())
if (font.fixedPitch()) {
return font;
}
font.setStyleHint(QFont::Monospace);
if (font.fixedPitch())
if (font.fixedPitch()) {
return font;
}
font.setStyleHint(QFont::TypeWriter);
if (font.fixedPitch())
if (font.fixedPitch()) {
return font;
}
font.setFamily(QString::fromLatin1("courier"));
if (font.fixedPitch())
if (font.fixedPitch()) {
return font;
return font; // We failed, but return whatever we have anyway
}
}
return font; // We failed, but return whatever we have anyway
}
} // namespace
/* TRANSLATOR Gui::Dialog::DlgSettingsEditor */
@@ -82,12 +88,12 @@ QFont getMonospaceFont()
* The dialog will by default be modeless, unless you set 'modal' to
* true to construct a modal dialog.
*/
DlgSettingsEditor::DlgSettingsEditor( QWidget* parent )
: PreferencePage( parent )
, ui(new Ui_DlgSettingsEditor)
DlgSettingsEditor::DlgSettingsEditor(QWidget* parent)
: PreferencePage(parent)
, ui(new Ui_DlgSettingsEditor)
{
ui->setupUi(this);
ui->EnableFolding->hide(); // Switch off until we have an editor with folding
ui->EnableFolding->hide(); // Switch off until we have an editor with folding
setupConnections();
@@ -101,70 +107,71 @@ DlgSettingsEditor::DlgSettingsEditor( QWidget* parent )
QColor col;
col = qApp->palette().windowText().color();
unsigned int lText = App::Color::asPackedRGB<QColor>(col);
d->colormap.push_back(QPair<QString, unsigned int>
(QString::fromLatin1(QT_TR_NOOP("Text")), lText));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Text")), lText));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Bookmark")), lBookmarks));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Breakpoint")), lBreakpnts));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Keyword")), lKeywords));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Comment")), lComments));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Block comment")), lBlockCom));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Number")), lNumbers));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("String")), lStrings));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Character")), lCharacter));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Class name")), lClass));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Define name")), lDefine));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Operator")), lOperat));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Python output")), lPyOutput));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Python error")), lPyError));
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));
d->colormap.push_back(
QPair<QString, unsigned int>(QString::fromLatin1(QT_TR_NOOP("Current line highlight")),
lCLine));
QStringList labels; labels << tr("Items");
QStringList labels;
labels << tr("Items");
ui->displayItems->setHeaderLabels(labels);
ui->displayItems->header()->hide();
for (const auto &[textType, textColor]: d->colormap)
{
for (const auto& [textType, textColor] : d->colormap) {
auto item = new QTreeWidgetItem(ui->displayItems);
item->setText(0, tr(textType.toLatin1()));
}
@@ -182,6 +189,7 @@ DlgSettingsEditor::~DlgSettingsEditor()
void DlgSettingsEditor::setupConnections()
{
// clang-format off
connect(ui->displayItems, &QTreeWidget::currentItemChanged,
this, &DlgSettingsEditor::onDisplayItemsCurrentItemChanged);
connect(ui->colorButton, &ColorButton::changed,
@@ -197,13 +205,14 @@ void DlgSettingsEditor::setupConnections()
connect(ui->fontSize, &PrefSpinBox::textChanged,
this, &DlgSettingsEditor::onFontSizeValueChanged);
#endif
// clang-format on
}
/** Searches for the color value corresponding to \e name in current editor
* settings ColorMap and assigns it to the color button
* @see Gui::ColorButton
*/
void DlgSettingsEditor::onDisplayItemsCurrentItemChanged(QTreeWidgetItem *item)
void DlgSettingsEditor::onDisplayItemsCurrentItemChanged(QTreeWidgetItem* item)
{
int index = ui->displayItems->indexOfTopLevelItem(item);
unsigned int col = d->colormap[index].second;
@@ -218,7 +227,7 @@ void DlgSettingsEditor::onColorButtonChanged()
int index = ui->displayItems->indexOfTopLevelItem(ui->displayItems->currentItem());
d->colormap[index].second = lcol;
pythonSyntax->setColor( d->colormap[index].first, col );
pythonSyntax->setColor(d->colormap[index].first, col);
}
void DlgSettingsEditor::setEditorTabWidth(int tabWidth)
@@ -244,13 +253,12 @@ void DlgSettingsEditor::saveSettings()
// Saves the color map
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
for (const auto &[textType, textColor] : d->colormap)
{
for (const auto& [textType, textColor] : d->colormap) {
auto col = static_cast<unsigned long>(textColor);
hGrp->SetUnsigned(textType.toLatin1(), col);
}
hGrp->SetInt( "FontSize", ui->fontSize->value() );
hGrp->SetASCII( "Font", ui->fontFamily->currentText().toLatin1() );
hGrp->SetInt("FontSize", ui->fontSize->value());
hGrp->SetASCII("Font", ui->fontFamily->currentText().toLatin1());
setEditorTabWidth(ui->tabSize->value());
}
@@ -281,8 +289,7 @@ void DlgSettingsEditor::loadSettings()
// Restores the color map
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
for (auto &[textType, textColor] : d->colormap)
{
for (auto& [textType, textColor] : d->colormap) {
auto col = static_cast<unsigned long>(textColor);
col = hGrp->GetUnsigned(textType.toLatin1(), col);
textColor = static_cast<unsigned int>(col);
@@ -300,7 +307,7 @@ void DlgSettingsEditor::loadSettings()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QStringList familyNames = QFontDatabase().families(QFontDatabase::Any);
QStringList fixedFamilyNames;
for (const auto &name : familyNames) {
for (const auto& name : familyNames) {
if (QFontDatabase().isFixedPitch(name)) {
if (name.compare(QLatin1String("8514oem"), Qt::CaseInsensitive) != 0) {
fixedFamilyNames.append(name);
@@ -310,7 +317,7 @@ void DlgSettingsEditor::loadSettings()
#else
QStringList familyNames = QFontDatabase::families(QFontDatabase::Any);
QStringList fixedFamilyNames;
for (const auto &name : familyNames) {
for (const auto& name : familyNames) {
if (QFontDatabase::isFixedPitch(name)) {
if (name.compare(QLatin1String("8514oem"), Qt::CaseInsensitive) != 0) {
fixedFamilyNames.append(name);
@@ -321,8 +328,9 @@ void DlgSettingsEditor::loadSettings()
ui->fontFamily->addItems(fixedFamilyNames);
int index = fixedFamilyNames.indexOf(
QString::fromLatin1(hGrp->GetASCII("Font", defaultMonospaceFont).c_str()));
if (index < 0)
if (index < 0) {
index = 0;
}
ui->fontFamily->setCurrentIndex(index);
onFontFamilyActivated(ui->fontFamily->currentText());
ui->displayItems->setCurrentItem(ui->displayItems->topLevelItem(0));
@@ -332,31 +340,32 @@ void DlgSettingsEditor::resetSettingsToDefaults()
{
ParameterGrp::handle hGrp;
hGrp = WindowParameter::getDefaultParameter()->GetGroup("Editor");
//reset the parameters in the "Editor" group
for (const auto &[textType, textColor] : d->colormap)
{
// reset the parameters in the "Editor" group
for (const auto& [textType, textColor] : d->colormap) {
hGrp->RemoveUnsigned(textType.toLatin1());
}
//reset "FontSize" parameter
// reset "FontSize" parameter
hGrp->RemoveInt("FontSize");
//reset "Font" parameter
// reset "Font" parameter
hGrp->RemoveASCII("Font");
//finally reset all the parameters associated to Gui::Pref* widgets
// finally reset all the parameters associated to Gui::Pref* widgets
PreferencePage::resetSettingsToDefaults();
}
/**
* Sets the strings of the subwidgets using the current language.
*/
void DlgSettingsEditor::changeEvent(QEvent *e)
void DlgSettingsEditor::changeEvent(QEvent* e)
{
if (e->type() == QEvent::LanguageChange) {
int index = 0;
for (const auto &[textType, textColor]: d->colormap)
for (const auto& [textType, textColor] : d->colormap) {
ui->displayItems->topLevelItem(index++)->setText(0, tr(textType.toLatin1()));
}
ui->retranslateUi(this);
} else {
}
else {
QWidget::changeEvent(e);
}
}