Skip to content

Commit a13a70b

Browse files
Refactoring LaunchWidget
1 parent 7e7f45a commit a13a70b

10 files changed

+157
-131
lines changed

src/GUI/BaseConfigurationDialog.cpp

-19
This file was deleted.

src/GUI/BaseConfigurationDialog.hpp

-22
This file was deleted.

src/GUI/CreationDialog.cpp

+28-18
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,57 @@
11
#include <QDialogButtonBox>
22
#include <QRadioButton>
33
#include <QPushButton>
4+
#include <QButtonGroup>
45
#include <QVBoxLayout>
56
#include <QPixmap>
7+
#include <QCheckBox>
68

79
#include "../Registry.hpp"
810
#include "CreationDialog.hpp"
911

10-
CreationDialog::CreationDialog(QWidget* parent) : BaseConfigurationDialog(parent)
12+
CreationDialog::CreationDialog(QWidget* parent) : QDialog(parent)
1113
{
14+
QDialogButtonBox* btnbxOkAndCancel = new QDialogButtonBox();
15+
btnbxOkAndCancel->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
16+
btnbxOkAndCancel->button(QDialogButtonBox::Ok)->setText(tr("START"));
17+
btnbxOkAndCancel->button(QDialogButtonBox::Cancel)->setText(tr("BACK"));
18+
connect(btnbxOkAndCancel, &QDialogButtonBox::rejected, this, [=, this] { emit btnBackClicked(); });
19+
connect(btnbxOkAndCancel, &QDialogButtonBox::accepted, this, [=, this] { emit btnStartClicked(); });
20+
1221
// configure game buttons
13-
QRadioButton* generalsButton = new QRadioButton(
22+
QRadioButton* rbxGenerals = new QRadioButton(
1423
QString::fromStdString(Registry::ToString(Registry::Games::Generals)));
15-
generalsButton->setDisabled(true);
24+
rbxGenerals->setDisabled(true);
25+
QFont rbxGeneralsFont = rbxGenerals->font();
26+
rbxGeneralsFont.setStrikeOut(true);
27+
rbxGenerals->setFont(rbxGeneralsFont);
1628

17-
QRadioButton* zeroHourButton = new QRadioButton(
29+
QRadioButton* rbxZeroHour = new QRadioButton(
1830
QString::fromStdString(Registry::ToString(Registry::Games::GeneralsZeroHour)));
1931

20-
buttonsGroup.setExclusive(true);
21-
zeroHourButton->setChecked(true);
22-
buttonsGroup.addButton(generalsButton);
23-
buttonsGroup.addButton(zeroHourButton);
32+
QButtonGroup* btngRadioboxes = new QButtonGroup();
33+
34+
btngRadioboxes->setExclusive(true);
35+
rbxZeroHour->setChecked(true);
36+
btngRadioboxes->addButton(rbxGenerals);
37+
btngRadioboxes->addButton(rbxZeroHour);
2438
QVBoxLayout* ltChoiseGame = new QVBoxLayout();
25-
ltChoiseGame->addWidget(generalsButton);
26-
ltChoiseGame->addWidget(zeroHourButton);
39+
ltChoiseGame->addWidget(rbxGenerals);
40+
ltChoiseGame->addWidget(rbxZeroHour);
2741

2842
// configure save option
29-
saveToGameBox.setText(tr("Save hotkeys dirrectly to the game."));
43+
QCheckBox* chkSaveToGame = new QCheckBox();
44+
chkSaveToGame->setText(tr("Save hotkeys dirrectly to the game."));
3045

3146
// configure dialog view
3247
QVBoxLayout* ltMainBlock = new QVBoxLayout();
3348
ltMainBlock->setAlignment(Qt::Alignment::enum_type::AlignCenter);
3449
ltMainBlock->addStretch(5);
3550
ltMainBlock->addLayout(ltChoiseGame);
3651
ltMainBlock->addStretch(2);
37-
ltMainBlock->addWidget(&saveToGameBox);
52+
ltMainBlock->addWidget(chkSaveToGame);
3853
ltMainBlock->addStretch(5);
39-
ltMainBlock->addWidget(&dialogButtons, 0, Qt::AlignCenter);
54+
ltMainBlock->addWidget(btnbxOkAndCancel, 0, Qt::AlignCenter);
4055
ltMainBlock->addStretch(1);
4156
setLayout(ltMainBlock);
4257
}
43-
44-
QVariant CreationDialog::CreateConfigurationData()
45-
{
46-
return QVariant("Creator widget data.");
47-
}

src/GUI/CreationDialog.hpp

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
#pragma once
2-
#include <QCheckBox>
3-
#include "BaseConfigurationDialog.hpp"
2+
#include <QDialog>
43

5-
class CreationDialog : public BaseConfigurationDialog
4+
class CreationDialog : public QDialog
65
{
76
Q_OBJECT
8-
private: // Data
9-
QCheckBox saveToGameBox;
10-
11-
public: // Method
7+
public: // Methods
128
CreationDialog(QWidget* parent = nullptr);
13-
QVariant CreateConfigurationData() override;
9+
signals:
10+
void btnBackClicked();
11+
void btnStartClicked();
1412
};

src/GUI/GreetingWidget.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@ GreetingWidget::GreetingWidget(QWidget* parent) : QWidget(parent)
2121
QVBoxLayout* ltLanguages = nullptr;
2222
QVBoxLayout* ltMain = nullptr;
2323

24-
// Makes greeting window unresizeable and equal to the size of the background file
25-
setFixedSize(795, 440);
26-
2724
// Add "New Project" and "Load Project" buttons to the window
2825
btnNewProject = new QPushButton(tr("NEW") + '\n' + tr("PROJECT"));
2926
btnNewProject->setFixedSize(PROGRAM_CONSTANTS->START_BUTTON_SIZE);

src/GUI/LaunchWidget.cpp

+50-22
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77

88
LaunchWidget::LaunchWidget(QWidget* parent) : QStackedWidget(parent)
99
{
10-
// MainLaunchWidget settings
10+
// Makes window unresizeable and equal to the size of the background
1111
setFixedSize(795, 440);
1212
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
1313
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint &
1414
~Qt::WindowMinimizeButtonHint);
15-
16-
pGreetingWidget = new GreetingWidget(this);
17-
addWidget(pGreetingWidget);
15+
16+
AddWidgets();
17+
setCurrentWidget(pGreetingWidget);
1818
AttachConnections();
1919
}
2020

@@ -25,6 +25,15 @@ void LaunchWidget::AttachConnections()
2525

2626
connect(pGreetingWidget, &GreetingWidget::pressed,
2727
this, &LaunchWidget::BtnNewProjectOrBtnLoadProject_Clicked);
28+
29+
connect(pLoadDialog, &LoadDialog::btnBackClicked,
30+
this, &LaunchWidget::BtnBack_Clicked);
31+
32+
connect(pCreationDialog, &CreationDialog::btnBackClicked,
33+
this, &LaunchWidget::BtnBack_Clicked);
34+
35+
connect(pCreationDialog, &CreationDialog::btnStartClicked,
36+
this, &LaunchWidget::CreationDialog_AcceptConfiguration);
2837
}
2938

3039
void LaunchWidget::DetachConnections()
@@ -34,48 +43,67 @@ void LaunchWidget::DetachConnections()
3443

3544
disconnect(pGreetingWidget, &GreetingWidget::pressed,
3645
this, &LaunchWidget::BtnNewProjectOrBtnLoadProject_Clicked);
46+
47+
disconnect(pLoadDialog, &LoadDialog::btnBackClicked,
48+
this, &LaunchWidget::BtnBack_Clicked);
49+
50+
disconnect(pCreationDialog, &CreationDialog::btnBackClicked,
51+
this, &LaunchWidget::BtnBack_Clicked);
52+
53+
disconnect(pCreationDialog, &CreationDialog::btnStartClicked,
54+
this, &LaunchWidget::CreationDialog_AcceptConfiguration);
55+
}
56+
57+
void LaunchWidget::AddWidgets()
58+
{
59+
pGreetingWidget = new GreetingWidget(this);
60+
pCreationDialog = new CreationDialog(pGreetingWidget);
61+
pLoadDialog = new LoadDialog(pGreetingWidget);
62+
63+
pGreetingWidget->setFixedSize(size());
64+
pCreationDialog->setFixedSize(size());
65+
pLoadDialog->setFixedSize(size());
66+
67+
addWidget(pGreetingWidget);
68+
addWidget(pCreationDialog);
69+
addWidget(pLoadDialog);
3770
}
3871

3972
void LaunchWidget::GreetingWidget_LanguageChanged(int intLngIndex)
4073
{
41-
// Find language type by its code.
4274
Languages lngType = static_cast<Languages>(intLngIndex);
4375

44-
// Change class' translator.
4576
WINDOW_MANAGER->SetTranslator(lngType);
4677

47-
// Recreate StartWidget and update connections.
4878
DetachConnections();
49-
removeWidget(pGreetingWidget);
79+
// removeWidget(pGreetingWidget);
80+
// removeWidget(pCreationDialog);
81+
// removeWidget(pLoadDialog);
5082
pGreetingWidget->deleteLater();
83+
pCreationDialog->deleteLater();
84+
pLoadDialog->deleteLater();
5185

52-
pGreetingWidget = new GreetingWidget(this);
53-
addWidget(pGreetingWidget);
54-
setCurrentWidget(pGreetingWidget);
86+
AddWidgets();
5587
AttachConnections();
88+
setCurrentWidget(pGreetingWidget);
5689
}
5790

5891
void LaunchWidget::BtnNewProjectOrBtnLoadProject_Clicked(GreetingWidget::StandartButtons standartButton)
5992
{
60-
BaseConfigurationDialog* pConfigurationWidget = nullptr;
61-
6293
switch (standartButton)
6394
{
6495
case GreetingWidget::StandartButtons::NewProject:
65-
pConfigurationWidget = new CreationDialog();
96+
setCurrentWidget(pCreationDialog);
6697
break;
6798
case GreetingWidget::StandartButtons::LoadProject:
68-
pConfigurationWidget = new LoadDialog();
99+
setCurrentWidget(pLoadDialog);
69100
break;
70101
default:
71-
pConfigurationWidget = new CreationDialog();
102+
setCurrentWidget(pCreationDialog);
72103
break;
73104
}
74-
addWidget(pConfigurationWidget);
75-
setCurrentWidget(pConfigurationWidget); // next window (creator)
76-
77-
// if accepted -> send signal with configuration
78-
connect(pConfigurationWidget, &CreationDialog::acceptConfiguration, this, &LaunchWidget::CreationDialog_AcceptConfiguration);
79105
}
80106

81-
void LaunchWidget::CreationDialog_AcceptConfiguration(const QVariant& cfg) { WINDOW_MANAGER->LaunchWidget_AcceptConfiguration(cfg); }
107+
void LaunchWidget::BtnBack_Clicked() { setCurrentWidget(pGreetingWidget); }
108+
109+
void LaunchWidget::CreationDialog_AcceptConfiguration() { QVariant cfg; WINDOW_MANAGER->LaunchWidget_AcceptConfiguration(cfg); }

src/GUI/LaunchWidget.hpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
#pragma once
22
#include <QStackedWidget>
33
#include "GreetingWidget.hpp"
4+
#include "CreationDialog.hpp"
5+
#include "LoadDialog.hpp"
46

57
class LaunchWidget final : public QStackedWidget
68
{
79
Q_OBJECT
810
private: // Data
911
GreetingWidget* pGreetingWidget = nullptr;
12+
CreationDialog* pCreationDialog = nullptr;
13+
LoadDialog* pLoadDialog = nullptr;
1014

1115
private: // Methods
1216
/// @brief Connects slots and singals.
@@ -16,11 +20,17 @@ class LaunchWidget final : public QStackedWidget
1620
public:
1721
LaunchWidget(QWidget* parent = nullptr);
1822

23+
private:
24+
/// @brief Adds `GreetingWidget`, `CreationDialog`, `LoadDialog` to the class.
25+
void AddWidgets();
26+
1927
private slots:
28+
/// @brief Show `GreetingWidget`, if button `Back` has been clicked.
29+
void BtnBack_Clicked();
2030
/// @brief Change language by its index if language has been changed via select list.
2131
void GreetingWidget_LanguageChanged(int intLngIndex);
2232
/// @brief Open create/loader widget if start button has been clicked.
2333
void BtnNewProjectOrBtnLoadProject_Clicked(GreetingWidget::StandartButtons standartButton);
2434
/// @brief Returns checked configuration of user preferences.
25-
void CreationDialog_AcceptConfiguration(const QVariant& configuration);
35+
void CreationDialog_AcceptConfiguration();
2636
};

src/GUI/LoadDialog.cpp

+23-15
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,22 @@
22
#include <QRadioButton>
33
#include <QVBoxLayout>
44
#include <QPushButton>
5+
#include <QButtonGroup>
56
#include <QFileDialog>
67
#include <QLineEdit>
78
#include <QFontMetrics>
89

910
#include "LoadDialog.hpp"
1011

11-
LoadDialog::LoadDialog(QWidget* parent) : BaseConfigurationDialog(parent)
12+
LoadDialog::LoadDialog(QWidget* parent) : QDialog(parent)
1213
{
14+
QDialogButtonBox* btnbxOkAndCancel = new QDialogButtonBox();
15+
btnbxOkAndCancel->setStandardButtons(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
16+
btnbxOkAndCancel->button(QDialogButtonBox::Ok)->setText(tr("START"));
17+
btnbxOkAndCancel->button(QDialogButtonBox::Cancel)->setText(tr("BACK"));
18+
connect(btnbxOkAndCancel, &QDialogButtonBox::rejected, this, [=, this] { emit btnBackClicked(); });
19+
connect(btnbxOkAndCancel, &QDialogButtonBox::accepted, this, [=, this] { emit btnStartClicked(); });
20+
1321
// configure file path selection
1422
QLineEdit* pathToFileLineEdit = new QLineEdit();
1523
pathToFileLineEdit->setMaximumWidth(700);
@@ -31,41 +39,41 @@ LoadDialog::LoadDialog(QWidget* parent) : BaseConfigurationDialog(parent)
3139
connect(btnReview, &QPushButton::clicked, fileDialog, &QFileDialog::exec);
3240

3341
// configure choise buttons
34-
QRadioButton* loadFromFileButton = new QRadioButton(tr("Load project"));
35-
connect(loadFromFileButton, &QPushButton::toggled, this, [=, this](bool checked)
42+
QRadioButton* rdxLoadFromFile = new QRadioButton(tr("Load project"));
43+
connect(rdxLoadFromFile, &QPushButton::toggled, this, [=, this](bool checked)
3644
{
3745
pathToFileLineEdit->setEnabled(checked);
3846
btnReview->setEnabled(checked);
3947
});
4048

41-
QRadioButton* loadFromGameButton = new QRadioButton(tr("Load installed game hotkey map"));
42-
buttonsGroup.setExclusive(true);
43-
loadFromFileButton->setChecked(true);
44-
buttonsGroup.addButton(loadFromFileButton);
45-
buttonsGroup.addButton(loadFromGameButton);
49+
QButtonGroup* btngRadioboxes = new QButtonGroup();
50+
QRadioButton* rbxLoadFromGame = new QRadioButton(tr("Load installed game hotkey map"));
51+
btngRadioboxes->setExclusive(true);
52+
rdxLoadFromFile->setChecked(true);
53+
btngRadioboxes->addButton(rdxLoadFromFile);
54+
btngRadioboxes->addButton(rbxLoadFromGame);
4655

4756
QHBoxLayout* ltReview = new QHBoxLayout();
4857
ltReview->addWidget(pathToFileLineEdit);
4958
ltReview->addSpacing(5);
5059
ltReview->addWidget(btnReview);
51-
ltReview->setContentsMargins(loadFromFileButton->sizeHint().width() -
52-
QFontMetrics(loadFromFileButton->font()).horizontalAdvance(loadFromFileButton->text()),
60+
ltReview->setContentsMargins(rdxLoadFromFile->sizeHint().width() -
61+
QFontMetrics(rdxLoadFromFile->font()).horizontalAdvance(rdxLoadFromFile->text()),
5362
0,0,0);
5463

5564
// configure dialog view
5665
QVBoxLayout* ltMainBlock = new QVBoxLayout();
5766
ltMainBlock->setContentsMargins(80,0,80,0);
5867
ltMainBlock->setAlignment(Qt::Alignment::enum_type::AlignCenter);
5968
ltMainBlock->addStretch(5);
60-
ltMainBlock->addWidget(loadFromFileButton);
69+
ltMainBlock->addWidget(rdxLoadFromFile);
6170
ltMainBlock->addSpacing(10);
6271
ltMainBlock->addLayout(ltReview);
6372
ltMainBlock->addStretch(2);
64-
ltMainBlock->addWidget(loadFromGameButton);
73+
ltMainBlock->addWidget(rbxLoadFromGame);
6574
ltMainBlock->addStretch(5);
66-
ltMainBlock->addWidget(&dialogButtons, 0, Qt::AlignCenter);
75+
ltMainBlock->addWidget(btnbxOkAndCancel, 0, Qt::AlignCenter);
6776
ltMainBlock->addStretch(1);
77+
6878
setLayout(ltMainBlock);
6979
}
70-
71-
QVariant LoadDialog::CreateConfigurationData() { return QVariant("Loader widget data."); }

0 commit comments

Comments
 (0)