Skip to content

Commit 7e7f45a

Browse files
Move constants to the ProgramConstants class
1 parent 537a4e1 commit 7e7f45a

14 files changed

+122
-111
lines changed

src/Convert.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace Convert
2828
{
2929
QString lowerLocale = locale.toLower();
3030

31-
for(auto it = LANGUAGES_STRINGS.cbegin(); it != LANGUAGES_STRINGS.cend(); ++it)
31+
for(auto it = PROGRAM_CONSTANTS->LANGUAGES_STRINGS.cbegin(); it != PROGRAM_CONSTANTS->LANGUAGES_STRINGS.cend(); ++it)
3232
if (Unsorted::GetLanguageShortName(it.key()) == lowerLocale)
3333
return it.key();
3434

src/GUI/ActionHotkeyWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void ActionHotkeyWidget::keyPressEvent(QKeyEvent* event)
8181
}
8282
else
8383
{
84-
if (!KEYBOARD_KEYS.contains(key))
84+
if (!(PROGRAM_CONSTANTS->KEYBOARD_KEYS.contains(key)))
8585
btnHotkey.setText(tr("It isn't character key!"));
8686
else
8787
btnHotkey.setText(tr("This key isn't allowed!"));

src/GUI/Faction.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ QMap<Faction::GameObject, GameObjectTypes> Faction::ParseJsonObject(const QJsonO
5151
QMap<GameObject, GameObjectTypes> tmpMap;
5252

5353
// Circle for each element in {"Buildings", "Infantry", "Vehicles", "Aircrafts"} map
54-
for(const QString& qstrObjectsArray : ENTITIES_STRINGS)
54+
for(const QString& qstrObjectsArray : PROGRAM_CONSTANTS->ENTITIES_STRINGS)
5555
{
5656
QJsonArray currArr = obj[qstrObjectsArray].toArray();
5757

@@ -78,7 +78,7 @@ QMap<Faction::GameObject, GameObjectTypes> Faction::ParseJsonObject(const QJsonO
7878
_layouts.push_back(_layout);
7979
}
8080

81-
tmpMap.insert(Faction::GameObject{_name, _ingameName, _layouts}, ENTITIES_STRINGS.key(qstrObjectsArray));
81+
tmpMap.insert(Faction::GameObject{_name, _ingameName, _layouts}, PROGRAM_CONSTANTS->ENTITIES_STRINGS.key(qstrObjectsArray));
8282
}
8383
}
8484

src/GUI/GreetingWidget.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ GreetingWidget::GreetingWidget(QWidget* parent) : QWidget(parent)
2626

2727
// Add "New Project" and "Load Project" buttons to the window
2828
btnNewProject = new QPushButton(tr("NEW") + '\n' + tr("PROJECT"));
29-
btnNewProject->setFixedSize(START_BUTTON_SIZE);
29+
btnNewProject->setFixedSize(PROGRAM_CONSTANTS->START_BUTTON_SIZE);
3030
connect(btnNewProject, &QPushButton::clicked, this, [this](bool)
3131
{
3232
emit pressed(GreetingWidget::StandartButtons::NewProject);
3333
});
3434

3535
btnLoadProject = new QPushButton(tr("LOAD") + '\n' + tr("PROJECT"));
36-
btnLoadProject->setFixedSize(START_BUTTON_SIZE);
36+
btnLoadProject->setFixedSize(PROGRAM_CONSTANTS->START_BUTTON_SIZE);
3737
connect(btnLoadProject, &QPushButton::clicked, this, [this](bool)
3838
{
3939
emit pressed(GreetingWidget::StandartButtons::LoadProject);
@@ -45,10 +45,9 @@ GreetingWidget::GreetingWidget(QWidget* parent) : QWidget(parent)
4545
for (int i = 0; i < static_cast<int>(Languages::Count); ++i)
4646
cmbLangList->addItem(Unsorted::GetLanguageFullName(static_cast<Languages>(i)));
4747
cmbLangList->setCurrentIndex(static_cast<int>(WINDOW_MANAGER->GetLanguage()));
48-
cmbLangList->setCurrentText(LANGUAGES_STRINGS.value(WINDOW_MANAGER->GetLanguage()).second);
48+
cmbLangList->setCurrentText(PROGRAM_CONSTANTS->LANGUAGES_STRINGS.value(WINDOW_MANAGER->GetLanguage()).second);
4949
connect(cmbLangList, QOverload<int>::of(&QComboBox::activated), this, &GreetingWidget::languageChanged);
5050

51-
5251
ltLanguages = new QVBoxLayout();
5352
ltLanguages->addStretch(1);
5453
ltLanguages->setSpacing(10);

src/GUI/HotkeysMainWindow.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
3636
// Enable smooth scrolling
3737
pEntitiesTreeWidget->setVerticalScrollMode(QTreeWidget::ScrollMode::ScrollPerPixel);
3838
// Set icon size
39-
pEntitiesTreeWidget->setIconSize(QSize{ICON_MIN_HEIGHT, ICON_MIN_HEIGHT});
39+
pEntitiesTreeWidget->setIconSize(QSize{PROGRAM_CONSTANTS->ICON_MIN_HEIGHT, PROGRAM_CONSTANTS->ICON_MIN_HEIGHT});
4040

4141
connect(pEntitiesTreeWidget, &QTreeWidget::itemSelectionChanged, this, &HotkeysMainWindow::SetHotkeysPanels);
4242

@@ -56,16 +56,16 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
5656
for (int i = 0; i < 4; ++i)
5757
{
5858
const Faction currFaction = factionVector.at(sectionIndex + i);
59-
59+
6060
QPushButton* factionButton = new QPushButton{currFaction.GetDisplayName()};
61-
61+
6262
auto shortName = currFaction.GetShortName();
63-
if (vUSAShorNames.contains(shortName)) ;
63+
if (PROGRAM_CONSTANTS->USA_SHORT_NAMES.contains(shortName)) ;
6464

65-
if (vPRCShorNames.contains(shortName))
65+
if (PROGRAM_CONSTANTS->PRC_SHORT_NAMES.contains(shortName))
6666
factionButton->setProperty("faction", "PRC");
67-
68-
if (vGLAShorNames.contains(shortName))
67+
68+
if (PROGRAM_CONSTANTS->GLA_SHORT_NAMES.contains(shortName))
6969
factionButton->setProperty("faction", "GLA");
7070

7171
connect(factionButton, &QPushButton::pressed, this, [=, this]()
@@ -74,7 +74,7 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
7474
});
7575

7676
pFactionsButtonsGroup->addButton(factionButton);
77-
77+
7878
if (i == 0) // main faction
7979
ltCurrentFaction->addWidget(factionButton);
8080
else // subfactions
@@ -117,7 +117,7 @@ HotkeysMainWindow::HotkeysMainWindow(const QVariant& configuration, QWidget* par
117117

118118
QPushButton* btnEmptyButton= new QPushButton();
119119
btnEmptyButton->setProperty("key", "null");
120-
btnEmptyButton->setFixedWidth(EMPTY_KEY_WIDTH);
120+
btnEmptyButton->setFixedWidth(PROGRAM_CONSTANTS->EMPTY_KEY_WIDTH);
121121

122122
pKeyboardFirstLine = CreateKeysOnKeyboard("QWERTYUIOP");
123123
pKeyboardSecondLine = CreateKeysOnKeyboard("ASDFGHJKL");
@@ -201,15 +201,15 @@ void HotkeysMainWindow::SetGameObjectList(const QString& factionShortName)
201201
if(goMap.isEmpty()) return;
202202

203203
// Create sections for all faction entities types
204-
for(const auto& objectType : ENTITIES_STRINGS.keys())
204+
for(const auto& objectType : PROGRAM_CONSTANTS->ENTITIES_STRINGS.keys())
205205
{
206206
// Create new section of tree list
207207
QTreeWidgetItem* newTopEntityItem = new QTreeWidgetItem();
208-
newTopEntityItem->setText(0, QCoreApplication::translate("QObject", ENTITIES_STRINGS.value(objectType).toUtf8().constData()));
208+
newTopEntityItem->setText(0, QCoreApplication::translate("QObject", PROGRAM_CONSTANTS->ENTITIES_STRINGS.value(objectType).toUtf8().constData()));
209209

210210
// Decorate
211211
newTopEntityItem->setIcon(0, ImageManager::GetGameObjectTypePixmap(objectType)
212-
.scaledToHeight(ICON_SCALING_HEIGHT, Qt::SmoothTransformation));
212+
.scaledToHeight(PROGRAM_CONSTANTS->ICON_SCALING_HEIGHT, Qt::SmoothTransformation));
213213

214214
// If there no objects by type - then skip
215215
if (goMap.keys(objectType).isEmpty()) continue;
@@ -566,7 +566,7 @@ QHBoxLayout* HotkeysMainWindow::CreateKeysOnKeyboard(const QString& str)
566566
auto tmp = new QPushButton(ch);
567567
tmp->setProperty("key", ch);
568568
tmp->setObjectName(ch);
569-
tmp->setFixedWidth(KEYBOARD_KEY_WIDTH);
569+
tmp->setFixedWidth(PROGRAM_CONSTANTS->KEYBOARD_KEY_WIDTH);
570570
pKeys->addWidget(tmp);
571571
}
572572
return pKeys;

src/GUI/HotkeysMainWindow.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class HotkeysMainWindow final : public QMainWindow
1414
Q_OBJECT
1515

1616
private: // Data
17-
JSONFile TECH_TREE_SOURCE{TECH_TREE_PATH};
17+
JSONFile TECH_TREE_SOURCE{PROGRAM_CONSTANTS->TECH_TREE_PATH};
1818

1919
QVector<Faction> factionVector;
2020

src/GUI/ImageManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ QImage ImageManager::DecodeWebpIcon(const QString& iconName)
1313
if (it != ImagesCache.constEnd()) return it.value();
1414

1515
// Find
16-
const QFileInfo targetIconFile = FindIconFile(ICONS_FOLDER, iconName);
16+
const QFileInfo targetIconFile = FindIconFile(PROGRAM_CONSTANTS->ICONS_FOLDER, iconName);
1717

1818
if (targetIconFile.exists())
1919
{
@@ -30,13 +30,13 @@ QImage ImageManager::DecodeWebpIcon(const QString& iconName)
3030
}
3131
}
3232

33-
QImage ImageManager::DecodeMissingWebpIcon() { return DecodeWebpIconPath(MISSING_ICON_PATH); }
34-
QImage ImageManager::DecodeEditorWebpIcon() { return DecodeWebpIconPath(EDITOR_ICON_PATH); }
35-
QImage ImageManager::DecodeBigEditorWebpIcon() { return DecodeWebpIconPath(EDITOR_BIG_ICON_PATH); }
33+
QImage ImageManager::DecodeMissingWebpIcon() { return DecodeWebpIconPath(PROGRAM_CONSTANTS->MISSING_ICON_PATH); }
34+
QImage ImageManager::DecodeEditorWebpIcon() { return DecodeWebpIconPath(PROGRAM_CONSTANTS->EDITOR_ICON_PATH); }
35+
QImage ImageManager::DecodeBigEditorWebpIcon() { return DecodeWebpIconPath(PROGRAM_CONSTANTS->EDITOR_BIG_ICON_PATH); }
3636

3737
QPixmap ImageManager::GetGameObjectTypePixmap(GameObjectTypes entityType)
3838
{
39-
return QPixmap{QT_ICONS_FOLDER + "/" + ENTITIES_STRINGS.value(entityType) + ".webp"};
39+
return QPixmap{PROGRAM_CONSTANTS->QT_ICONS_FOLDER + "/" + PROGRAM_CONSTANTS->ENTITIES_STRINGS.value(entityType) + ".webp"};
4040
}
4141

4242
QFileInfo ImageManager::FindIconFile(const QString& pathToIconsDir, const QString& fileBaseName)

src/GUI/Translations/ru.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,22 +288,22 @@
288288
<context>
289289
<name>QObject</name>
290290
<message>
291-
<location filename="../../ProgramConstants.hpp" line="50"/>
291+
<location filename="../../ProgramConstants.hpp" line="79"/>
292292
<source>Buildings</source>
293293
<translation>Здания</translation>
294294
</message>
295295
<message>
296-
<location filename="../../ProgramConstants.hpp" line="51"/>
296+
<location filename="../../ProgramConstants.hpp" line="80"/>
297297
<source>Infantry</source>
298298
<translation>Пехота</translation>
299299
</message>
300300
<message>
301-
<location filename="../../ProgramConstants.hpp" line="52"/>
301+
<location filename="../../ProgramConstants.hpp" line="81"/>
302302
<source>Vehicles</source>
303303
<translation>Техника</translation>
304304
</message>
305305
<message>
306-
<location filename="../../ProgramConstants.hpp" line="53"/>
306+
<location filename="../../ProgramConstants.hpp" line="82"/>
307307
<source>Aircrafts</source>
308308
<translation>Авиация</translation>
309309
</message>

src/GUI/WindowManager.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,21 @@
33

44
#include "../Logger.hpp"
55
#include "../Unsorted.hpp"
6+
#include "../Convert.hpp"
7+
#include "../Registry.hpp"
68

79
#include "ImageManager.hpp"
810
#include "WindowManager.hpp"
911

1012
WindowManager::WindowManager()
1113
{
14+
Language = Convert::ToLangEnum(Registry::GetCurrentUserLanguage());
15+
SetTranslator(Language);
16+
1217
qApp->setWindowIcon(QIcon(QPixmap::fromImage(ImageManager::DecodeEditorWebpIcon())));
1318

14-
LOGMSG("Loading \"" + STYLES_SHEET + "\"...");
15-
QFile css{STYLES_SHEET};
19+
LOGMSG("Loading \"" + PROGRAM_CONSTANTS->STYLES_SHEET + "\"...");
20+
QFile css{PROGRAM_CONSTANTS->STYLES_SHEET};
1621
if (css.open(QIODevice::ReadOnly))
1722
{
1823
qApp->setStyleSheet(css.readAll());
@@ -33,7 +38,7 @@ WindowManager::WindowManager()
3338
void WindowManager::LaunchWidget_AcceptConfiguration(const QVariant& cfg)
3439
{
3540
// 2nd init protection
36-
if (bEditorInitialized) return;
41+
if (pHotkeysEditor != nullptr) return;
3742

3843
LOGMSG("Loading editor window...");
3944
pHotkeysEditor = std::make_unique<HotkeysMainWindow>(cfg);
@@ -54,7 +59,7 @@ void WindowManager::SetTranslator(Languages lngType)
5459

5560
Language = lngType;
5661
pAppTranslator = new QTranslator();
57-
pAppTranslator->load(lngShortName, TRANSLATIONS_FOLDER);
62+
pAppTranslator->load(lngShortName, PROGRAM_CONSTANTS->TRANSLATIONS_FOLDER);
5863
qApp->installTranslator(pAppTranslator);
5964
}
6065

src/GUI/WindowManager.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
#include <QTranslator>
44

55
#include "../ProgramConstants.hpp"
6-
#include "../Convert.hpp"
7-
#include "../Registry.hpp"
86

97
#include "LaunchWidget.hpp"
108
#include "HotkeysMainWindow.hpp"
@@ -17,7 +15,7 @@ class WindowManager final
1715
std::unique_ptr<LaunchWidget> pLaunchWidget = nullptr;
1816
std::unique_ptr<HotkeysMainWindow> pHotkeysEditor = nullptr;
1917
inline static QTranslator* pAppTranslator = nullptr;
20-
inline static Languages Language = Languages::English; // Convert::ToLangEnum(Registry::GetCurrentUserLanguage());
18+
inline static Languages Language = Languages::English;
2119
QString strWindowName = "C&C: Generals Zero Hour Hotkey Editor";
2220
bool bEditorInitialized = false;
2321
public:

0 commit comments

Comments
 (0)