Skip to content

Commit

Permalink
Try to add SettingsWindow into HotkeysMainWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
MahBoiDeveloper committed Mar 6, 2025
1 parent 1ac9c99 commit c46d09b
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 102 deletions.
100 changes: 20 additions & 80 deletions src/GUI/HotkeysMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ HotkeysMainWindow::HotkeysMainWindow(QWidget* parent)
btnEmptyButton->setProperty("key", "null");
btnEmptyButton->setFixedWidth(PROGRAM_CONSTANTS->EMPTY_KEY_WIDTH);

pKeyboardFirstLine = CreateKeysOnKeyboard("QWERTYUIOP");
pKeyboardFirstLine = CreateKeysOnKeyboard("QWERTYUIOP");
pKeyboardSecondLine = CreateKeysOnKeyboard("ASDFGHJKL");
pKeyboardThirdLine = CreateKeysOnKeyboard("ZXCVBNM");
pKeyboardThirdLine = CreateKeysOnKeyboard("ZXCVBNM");

pKeyboardThirdLine->addWidget(btnEmptyButton);

Expand Down Expand Up @@ -184,17 +184,14 @@ void HotkeysMainWindow::ConfigureMenu()
mnStatusBarChecbox->addAction(tr("Disable"));
mnViewOptions->addMenu(mnStatusBarChecbox);
menuBar()->addMenu(mnViewOptions);

QMenu* mnSettingsOptions = new QMenu(tr("Settings"));
menuBar()->addMenu(mnSettingsOptions);

QAction* actLanguage = new QAction(tr("Language"));
connect(actLanguage, &QAction::triggered, this, &HotkeysMainWindow::ActLanguage_Triggered);
mnSettingsOptions->addAction(actLanguage);

QAction* actSettings = new QAction(tr("Settings"));
connect(actSettings, &QAction::triggered, this, &HotkeysMainWindow::ActLanguage_Triggered);
menuBar()->addAction(actSettings);

QAction* actAbout = new QAction(tr("About"));
connect(actAbout, &QAction::triggered, this, &HotkeysMainWindow::ActAbout_Triggered);
mnSettingsOptions->addAction(actAbout);
menuBar()->addAction(actAbout);
}

void HotkeysMainWindow::SetGameObjectList(const QString& factionShortName)
Expand Down Expand Up @@ -479,91 +476,34 @@ void HotkeysMainWindow::ActAbout_Triggered()
~Qt::WindowContextHelpButtonHint |
Qt::MSWindowsFixedSizeDialogHint);

connect(pAboutDialog, &QDialog::finished, this, [this]()
{
pAboutDialog->deleteLater();
pAboutDialog = nullptr;
});

QVBoxLayout* ltMainBlock = new QVBoxLayout();
ltMainBlock->addLayout(lblContent);

pAboutDialog->setLayout(ltMainBlock);
pAboutDialog->show();
pAboutDialog->raise();
pAboutDialog->activateWindow();

connect(pAboutDialog, &QDialog::finished, this, [this]()
{
pAboutDialog->deleteLater();
pAboutDialog = nullptr;
});
}

void HotkeysMainWindow::ActLanguage_Triggered()
{
// if dialog already exists
if (pWindowToChangeLanguage != nullptr)
if (pSettingsWindow != nullptr)
{
pWindowToChangeLanguage->activateWindow();
pSettingsWindow->show();
return;
}

Languages currLang = PROGRAM_CONSTANTS->pSettingsFile->GetLanguage();
Languages actLang = Languages::English;

pWindowToChangeLanguage = new QDialog{this};
pWindowToChangeLanguage->setWindowTitle(tr("Lanugage"));
pWindowToChangeLanguage->setObjectName("WindowToChangeLanguage");
pWindowToChangeLanguage->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
// pWindowToChangeLanguage->setFixedSize(LANGUAGE_CHANGE_SIZE);
pWindowToChangeLanguage->setWindowFlags(pWindowToChangeLanguage->windowFlags() &
~Qt::WindowContextHelpButtonHint |
Qt::MSWindowsFixedSizeDialogHint);

QHBoxLayout* ltLanguageAndCombobox = new QHBoxLayout();
QLabel* lblLanguage = new QLabel(tr("LANGUAGE"));
QComboBox* cmbLangList = new QComboBox();

for (int i = 0; i < static_cast<int>(Languages::Count); ++i)
cmbLangList->addItem(Unsorted::GetLanguageFullName(static_cast<Languages>(i)));

cmbLangList->setCurrentIndex(static_cast<int>(currLang));

ltLanguageAndCombobox->addWidget(lblLanguage);
ltLanguageAndCombobox->addWidget(cmbLangList);

QHBoxLayout* ltOkAndCancel = new QHBoxLayout();
QPushButton* btnOk = new QPushButton(tr("OK"));
QPushButton* btnCancel = new QPushButton(tr("Cancel"));
ltOkAndCancel->addWidget(btnOk);
ltOkAndCancel->addWidget(btnCancel);

QVBoxLayout* ltMainBlock = new QVBoxLayout();
ltMainBlock->addLayout(ltLanguageAndCombobox);
ltMainBlock->addLayout(ltOkAndCancel);

pWindowToChangeLanguage->setLayout(ltMainBlock);
pWindowToChangeLanguage->show();
pWindowToChangeLanguage->raise();
pWindowToChangeLanguage->activateWindow();

// TODO: Make it work. Need to recreate HotkeysMainWindow through WindowManager
connect(cmbLangList, QOverload<int>::of(&QComboBox::activated), this, &HotkeysMainWindow::languageChanged);

connect(pWindowToChangeLanguage, &QDialog::finished, this, [this]()
{
pWindowToChangeLanguage->deleteLater();
pWindowToChangeLanguage = nullptr;
});

connect(btnCancel, &QPushButton::clicked, this, [this]()
{
pWindowToChangeLanguage->deleteLater();
pWindowToChangeLanguage = nullptr;
});

// TODO: Make there emit signal to WindowsManager and
// show 2nd window to ask to apply new language and reset unsaved changes.
connect(btnOk, &QPushButton::clicked, this, [this]()
{
pWindowToChangeLanguage->deleteLater();
pWindowToChangeLanguage = nullptr;
});
pSettingsWindow = new SettingsWindow();
pSettingsWindow->setObjectName(nameof(pSettingsWindow));
pSettingsWindow->setWindowTitle(tr("Settings"));
pSettingsWindow->setWindowModality(Qt::WindowModality::ApplicationModal);
pSettingsWindow->show();
}

QHBoxLayout* HotkeysMainWindow::CreateKeysOnKeyboard(const QString& str)
Expand Down
7 changes: 4 additions & 3 deletions src/GUI/HotkeysMainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QHBoxLayout>

#include "../Parsers/JSONFile.hpp"
#include "SettingsWindow.hpp"
#include "ActionHotkeyWidget.hpp"
#include "Faction.hpp"

Expand All @@ -27,9 +28,9 @@ class HotkeysMainWindow final : public QMainWindow
QScrollArea* pKeyboardWindow = nullptr;

// Renewable widgets
QTabWidget* pHotkeysPanelsWidget = nullptr;
QDialog* pAboutDialog = nullptr;
QDialog* pWindowToChangeLanguage = nullptr;
QTabWidget* pHotkeysPanelsWidget = nullptr;
QDialog* pAboutDialog = nullptr;
SettingsWindow* pSettingsWindow = nullptr;

QVector<QSet<ActionHotkeyWidget*>> vHotkeyWidgets;

Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Theme/Styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ QComboBox::down-arrow { image: url(Resources/Theme/ScrollArrowDown.webp); }
QComboBox::up-arrow { image: url(Resources/Theme/ScrollArrowUp.webp); }

/* Start widget style setting */
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow, SettingsWindow#pSettingsWindow
{
border-image: url(Resources/Theme/StartMenuBackground.webp) 0 0 0 0 stretch stretch;
background-color: black;
Expand Down
32 changes: 14 additions & 18 deletions src/GUI/Translations/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,69 +119,65 @@
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="188"/>
<location filename="../HotkeysMainWindow.cpp" line="504"/>
<source>Settings</source>
<translation>Настройки</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="191"/>
<source>Language</source>
<translation>Язык</translation>
<translation type="vanished">Язык</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="195"/>
<location filename="../HotkeysMainWindow.cpp" line="476"/>
<location filename="../HotkeysMainWindow.cpp" line="192"/>
<location filename="../HotkeysMainWindow.cpp" line="473"/>
<source>About</source>
<translation>О программе</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="326"/>
<location filename="../HotkeysMainWindow.cpp" line="323"/>
<source>Layout %1</source>
<translation>Раскладка %1</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="456"/>
<location filename="../HotkeysMainWindow.cpp" line="453"/>
<source>Authors: </source>
<translation>Авторы: </translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="457"/>
<location filename="../HotkeysMainWindow.cpp" line="454"/>
<source>Version: </source>
<translation>Версия: </translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="458"/>
<location filename="../HotkeysMainWindow.cpp" line="455"/>
<source>Program licensed with </source>
<translation>Программа лицензирована под </translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="459"/>
<location filename="../HotkeysMainWindow.cpp" line="456"/>
<source>GitHub repository:</source>
<translation>Репозиторий на GitHub:</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="461"/>
<location filename="../HotkeysMainWindow.cpp" line="458"/>
<source>Support development:</source>
<translation>Поддержать разработку:</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="510"/>
<source>Lanugage</source>
<translation>Язык</translation>
<translation type="vanished">Язык</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="519"/>
<source>LANGUAGE</source>
<translation>ЯЗЫК</translation>
<translation type="vanished">ЯЗЫК</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="531"/>
<source>OK</source>
<translation>Ок</translation>
<translation type="vanished">Ок</translation>
</message>
<message>
<location filename="../HotkeysMainWindow.cpp" line="532"/>
<source>Cancel</source>
<translation>Отмена</translation>
<translation type="vanished">Отмена</translation>
</message>
<message>
<source>Program licensed by GNU GPL v3</source>
Expand Down

0 comments on commit c46d09b

Please sign in to comment.