Skip to content

Commit a0a8021

Browse files
Rename class and fix Qt's bug with border rendering
1 parent b0daf22 commit a0a8021

File tree

8 files changed

+194
-109
lines changed

8 files changed

+194
-109
lines changed
Lines changed: 47 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616

1717
#include "ImageManager.hpp"
1818
#include "WindowManager.hpp"
19-
#include "HotkeysMainWindow.hpp"
19+
#include "SettingsWindow.hpp"
20+
#include "EditorWindow.hpp"
2021

21-
HotkeysMainWindow::HotkeysMainWindow(QWidget* parent)
22+
EditorWindow::EditorWindow(QWidget* parent)
2223
: QMainWindow(parent)
2324
, pFactionsButtonsGroup{new QButtonGroup{this}}
2425
, pEntitiesTreeWidget{new QTreeWidget}
@@ -39,7 +40,7 @@ HotkeysMainWindow::HotkeysMainWindow(QWidget* parent)
3940
// Set icon size
4041
pEntitiesTreeWidget->setIconSize(QSize{PROGRAM_CONSTANTS->ICON_MIN_HEIGHT, PROGRAM_CONSTANTS->ICON_MIN_HEIGHT});
4142

42-
connect(pEntitiesTreeWidget, &QTreeWidget::itemSelectionChanged, this, &HotkeysMainWindow::SetHotkeysPanels);
43+
connect(pEntitiesTreeWidget, &QTreeWidget::itemSelectionChanged, this, &EditorWindow::SetHotkeysPanels);
4344

4445
QBoxLayout* ltFactions = nullptr;
4546
int factonsCount = factionVector.size();
@@ -64,7 +65,8 @@ HotkeysMainWindow::HotkeysMainWindow(QWidget* parent)
6465
QPushButton* factionButton = new QPushButton{currFaction.GetDisplayName()};
6566

6667
auto shortName = currFaction.GetShortName();
67-
if (PROGRAM_CONSTANTS->USA_SHORT_NAMES.contains(shortName)) ;
68+
if (PROGRAM_CONSTANTS->USA_SHORT_NAMES.contains(shortName))
69+
factionButton->setProperty("faction", "USA");
6870

6971
if (PROGRAM_CONSTANTS->PRC_SHORT_NAMES.contains(shortName))
7072
factionButton->setProperty("faction", "PRC");
@@ -161,7 +163,7 @@ HotkeysMainWindow::HotkeysMainWindow(QWidget* parent)
161163
if (firstFactionButton != nullptr) firstFactionButton->click();
162164
}
163165

164-
void HotkeysMainWindow::ConfigureMenu()
166+
void EditorWindow::ConfigureMenu()
165167
{
166168
QMenu* mnFileOptions = new QMenu(tr("File"));
167169
QAction* actOpen = new QAction(tr("Open"));
@@ -174,9 +176,9 @@ void HotkeysMainWindow::ConfigureMenu()
174176
mnFileOptions->addAction(actSpecial);
175177
menuBar()->addMenu(mnFileOptions);
176178

177-
connect(actOpen, &QAction::triggered, this, &HotkeysMainWindow::ActOpen_Triggered);
178-
connect(actSave, &QAction::triggered, this, &HotkeysMainWindow::ActSave_Triggered);
179-
connect(actSaveAs, &QAction::triggered, this, &HotkeysMainWindow::ActSaveAs_Triggered);
179+
connect(actOpen, &QAction::triggered, this, &EditorWindow::ActOpen_Triggered);
180+
connect(actSave, &QAction::triggered, this, &EditorWindow::ActSave_Triggered);
181+
connect(actSaveAs, &QAction::triggered, this, &EditorWindow::ActSaveAs_Triggered);
180182

181183
QMenu* mnViewOptions = new QMenu(tr("View"));
182184
QMenu* mnStatusBarChecbox = new QMenu(tr("Status Bar"));
@@ -186,15 +188,15 @@ void HotkeysMainWindow::ConfigureMenu()
186188
menuBar()->addMenu(mnViewOptions);
187189

188190
QAction* actSettings = new QAction(tr("Settings"));
189-
connect(actSettings, &QAction::triggered, this, &HotkeysMainWindow::ActLanguage_Triggered);
191+
connect(actSettings, &QAction::triggered, this, &EditorWindow::ActSettings_Triggered);
190192
menuBar()->addAction(actSettings);
191193

192194
QAction* actAbout = new QAction(tr("About"));
193-
connect(actAbout, &QAction::triggered, this, &HotkeysMainWindow::ActAbout_Triggered);
195+
connect(actAbout, &QAction::triggered, this, &EditorWindow::ActAbout_Triggered);
194196
menuBar()->addAction(actAbout);
195197
}
196198

197-
void HotkeysMainWindow::SetGameObjectList(const QString& factionShortName)
199+
void EditorWindow::SetGameObjectList(const QString& factionShortName)
198200
{
199201
pEntitiesTreeWidget->clear();
200202

@@ -247,7 +249,7 @@ void HotkeysMainWindow::SetGameObjectList(const QString& factionShortName)
247249
pEntitiesTreeWidget->setCurrentItem(firstEntity);
248250
}
249251

250-
void HotkeysMainWindow::SetHotkeysPanels()
252+
void EditorWindow::SetHotkeysPanels()
251253
{
252254
// Skip if there are no selected items
253255
if (pEntitiesTreeWidget->selectedItems().isEmpty()) return;
@@ -329,12 +331,12 @@ void HotkeysMainWindow::SetHotkeysPanels()
329331
pHotkeysPanelsWidget->setMinimumSize(pHotkeysPanelsWidget->sizeHint());
330332
pHotkeysArea->setWidget(pHotkeysPanelsWidget);
331333

332-
connect(pHotkeysPanelsWidget, &QTabWidget::currentChanged, this, &HotkeysMainWindow::KeyboardWindow_Update);
334+
connect(pHotkeysPanelsWidget, &QTabWidget::currentChanged, this, &EditorWindow::KeyboardWindow_Update);
333335

334336
emit pHotkeysPanelsWidget->currentChanged(0);
335337
}
336338

337-
void HotkeysMainWindow::HighlightCurrentKeys()
339+
void EditorWindow::HighlightCurrentKeys()
338340
{
339341
// Skip if no widgets
340342
if (vHotkeyWidgets.isEmpty()) return;
@@ -360,7 +362,7 @@ void HotkeysMainWindow::HighlightCurrentKeys()
360362
}
361363
}
362364

363-
void HotkeysMainWindow::KeyboardWindow_Nullify()
365+
void EditorWindow::KeyboardWindow_Nullify()
364366
{
365367
for (QChar& qc : QString("QWERTYUIOPASDFGHJKLZXCVBNM"))
366368
{
@@ -372,7 +374,7 @@ void HotkeysMainWindow::KeyboardWindow_Nullify()
372374
}
373375
}
374376

375-
void HotkeysMainWindow::KeyboardWindow_Update(int id)
377+
void EditorWindow::KeyboardWindow_Update(int id)
376378
{
377379
KeyboardWindow_Nullify();
378380
auto currTab = pHotkeysPanelsWidget->findChild<QWidget*>(QString("Layout ") + QString::number(id + 1), Qt::FindChildrenRecursively);
@@ -400,13 +402,13 @@ void HotkeysMainWindow::KeyboardWindow_Update(int id)
400402
}
401403
}
402404

403-
void HotkeysMainWindow::SetFactions()
405+
void EditorWindow::SetFactions()
404406
{
405407
for(const auto& elem : TECH_TREE_SOURCE.Query("$.TechTree").toArray())
406408
factionVector.push_back(Faction{elem.toObject()});
407409
}
408410

409-
const Faction& HotkeysMainWindow::GetFactionRef(const QString& name)
411+
const Faction& EditorWindow::GetFactionRef(const QString& name)
410412
{
411413
int tmp = 0;
412414

@@ -424,7 +426,7 @@ const Faction& HotkeysMainWindow::GetFactionRef(const QString& name)
424426
return factionVector.at(tmp);
425427
}
426428

427-
void HotkeysMainWindow::SetActionHotkey(const QString& fctShortName, const QString& goName, const QString& actName, const QString& hk)
429+
void EditorWindow::SetActionHotkey(const QString& fctShortName, const QString& goName, const QString& actName, const QString& hk)
428430
{
429431
for(Faction& fct : factionVector)
430432
{
@@ -436,7 +438,7 @@ void HotkeysMainWindow::SetActionHotkey(const QString& fctShortName, const QStri
436438
}
437439
}
438440

439-
void HotkeysMainWindow::ActAbout_Triggered()
441+
void EditorWindow::ActAbout_Triggered()
440442
{
441443
// if dialog already exists
442444
if (pAboutDialog != nullptr)
@@ -480,33 +482,44 @@ void HotkeysMainWindow::ActAbout_Triggered()
480482
ltMainBlock->addLayout(lblContent);
481483

482484
pAboutDialog->setLayout(ltMainBlock);
485+
pAboutDialog->setWindowModality(Qt::WindowModality::ApplicationModal);
483486
pAboutDialog->show();
484-
pAboutDialog->raise();
485487
pAboutDialog->activateWindow();
486-
488+
487489
connect(pAboutDialog, &QDialog::finished, this, [this]()
488490
{
489491
pAboutDialog->deleteLater();
490492
pAboutDialog = nullptr;
491493
});
492494
}
493495

494-
void HotkeysMainWindow::ActLanguage_Triggered()
496+
void EditorWindow::ActSettings_Triggered()
495497
{
496-
if (pSettingsWindow != nullptr)
498+
if (pSettingsWindow == nullptr)
497499
{
498-
pSettingsWindow->show();
499-
return;
500+
// Read this thread:
501+
// https://forum.qt.io/topic/146107/can-t-show-the-border-of-the-class-inheriting-qwidget-class
502+
// to understand why QWidget's inherited class has been wrapped into another native QWidget
503+
504+
auto sw = new SettingsWindow();
505+
auto lt = new QVBoxLayout();
506+
lt->addWidget(sw);
507+
508+
pSettingsWindow = new QWidget();
509+
pSettingsWindow->setObjectName(nameof(pSettingsWindow));
510+
pSettingsWindow->setWindowTitle(tr("Settings"));
511+
pSettingsWindow->setFixedSize(PROGRAM_CONSTANTS->SET_UP_WINDOW_SIZE);
512+
pSettingsWindow->setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
513+
pSettingsWindow->setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint
514+
& ~Qt::WindowMinimizeButtonHint);
515+
pSettingsWindow->setWindowModality(Qt::WindowModality::ApplicationModal);
516+
pSettingsWindow->setLayout(lt);
500517
}
501518

502-
pSettingsWindow = new SettingsWindow();
503-
pSettingsWindow->setObjectName(nameof(pSettingsWindow));
504-
pSettingsWindow->setWindowTitle(tr("Settings"));
505-
pSettingsWindow->setWindowModality(Qt::WindowModality::ApplicationModal);
506519
pSettingsWindow->show();
507520
}
508521

509-
QHBoxLayout* HotkeysMainWindow::CreateKeysOnKeyboard(const QString& str)
522+
QHBoxLayout* EditorWindow::CreateKeysOnKeyboard(const QString& str)
510523
{
511524
QHBoxLayout* pKeys = new QHBoxLayout();
512525
for (const auto& ch : str)
@@ -520,17 +533,17 @@ QHBoxLayout* HotkeysMainWindow::CreateKeysOnKeyboard(const QString& str)
520533
return pKeys;
521534
}
522535

523-
void HotkeysMainWindow::ActSave_Triggered()
536+
void EditorWindow::ActSave_Triggered()
524537
{
525538
LOGMSG("Saving changes to .csf file...");
526539
CSF_PARSER->Save();
527540
LOGMSG("Changes has been saved");
528541
}
529542

530-
void HotkeysMainWindow::ActSaveAs_Triggered()
543+
void EditorWindow::ActSaveAs_Triggered()
531544
{
532545
}
533546

534-
void HotkeysMainWindow::ActOpen_Triggered()
547+
void EditorWindow::ActOpen_Triggered()
535548
{
536549
}
Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@
66
#include <QHBoxLayout>
77

88
#include "../Parsers/JSONFile.hpp"
9-
#include "SettingsWindow.hpp"
109
#include "ActionHotkeyWidget.hpp"
1110
#include "Faction.hpp"
1211

13-
class HotkeysMainWindow final : public QMainWindow
12+
class EditorWindow final : public QMainWindow
1413
{
1514
Q_OBJECT
1615

@@ -28,19 +27,19 @@ class HotkeysMainWindow final : public QMainWindow
2827
QScrollArea* pKeyboardWindow = nullptr;
2928

3029
// Renewable widgets
31-
QTabWidget* pHotkeysPanelsWidget = nullptr;
32-
QDialog* pAboutDialog = nullptr;
33-
SettingsWindow* pSettingsWindow = nullptr;
30+
QTabWidget* pHotkeysPanelsWidget = nullptr;
31+
QDialog* pAboutDialog = nullptr;
32+
QWidget* pSettingsWindow = nullptr;
3433

3534
QVector<QSet<ActionHotkeyWidget*>> vHotkeyWidgets;
3635

3736
public: // Methods
38-
HotkeysMainWindow(QWidget* parent = nullptr);
37+
EditorWindow(QWidget* parent = nullptr);
3938

4039
private:
4140
/// @brief Read data from TechTree.json and parse it to game objects.
4241
void SetFactions();
43-
/// @brief Return faction from HotkeysMainWindow::factionVector vector.
42+
/// @brief Return faction from EditorWindow::factionVector vector.
4443
const Faction& GetFactionRef(const QString& name);
4544
/// @brief Set context menu bar functions and logics.
4645
void ConfigureMenu();
@@ -62,7 +61,7 @@ class HotkeysMainWindow final : public QMainWindow
6261
private slots:
6362
void KeyboardWindow_Update(int id = 0);
6463
void ActAbout_Triggered();
65-
void ActLanguage_Triggered();
64+
void ActSettings_Triggered();
6665
void ActSave_Triggered();
6766
void ActSaveAs_Triggered();
6867
void ActOpen_Triggered();

src/GUI/SetUpWindowsWrapper.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SetUpWindowsWrapper::SetUpWindowsWrapper(QWidget* parent) : QStackedWidget(parent)
1313
{
1414
// Makes window unresizeable and equal to the size of the background
15-
setFixedSize(795, 440);
15+
setFixedSize(PROGRAM_CONSTANTS->SET_UP_WINDOW_SIZE);
1616
setWindowFlags(windowFlags() | Qt::MSWindowsFixedSizeDialogHint);
1717
setWindowFlags(windowFlags() & ~Qt::WindowMaximizeButtonHint &
1818
~Qt::WindowMinimizeButtonHint);

src/GUI/Theme/Styles.css

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,21 @@ QPushButton#btnOk
104104
padding-left: 10px;
105105
}
106106

107-
/* Start widget style setting */
108-
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow, SettingsWindow
107+
/* Start widgets and SettingsWindow style settings */
108+
LoadFromTheFileWindow, SetUpWindowsWrapper, LoadFromTheGameWindow, SettingsWindow, QWidget#pSettingsWindow
109109
{
110110
border-image: url(Resources/Theme/StartMenuBackground.webp) 0 0 0 0 stretch stretch;
111111
background-color: black;
112112
}
113113

114114
/* Main editor window style settings */
115-
HotkeysMainWindow
115+
EditorWindow
116116
{
117117
border-image: url(Resources/Theme/EditorBackground.webp) 0 0 0 0 stretch stretch;
118118
background-color: black;
119119
}
120120

121-
HotkeysMainWindow QPushButton
121+
EditorWindow QPushButton
122122
{
123123
font-family: Calibri;
124124
font-weight: bold;
@@ -133,11 +133,9 @@ HotkeysMainWindow QPushButton
133133
border-radius: 3px;
134134
}
135135

136-
HotkeysMainWindow QPushButton:hover { background-color: #3543e7; color: #baff0c; }
137-
HotkeysMainWindow QPushButton:pressed { background-color: #3543e7; color: white; }
138-
HotkeysMainWindow QPushButton:pressed:hover { background-color: #3543e7; color: #baff0c; }
139-
140-
/* QPushButton[faction="USA"] */ /* Already defined as basic non-property */
136+
EditorWindow QPushButton:hover { background-color: #3543e7; color: #baff0c; }
137+
EditorWindow QPushButton:pressed { background-color: #3543e7; color: white; }
138+
EditorWindow QPushButton:pressed:hover { background-color: #3543e7; color: #baff0c; }
141139

142140
QPushButton[faction="GLA"] { background-color: #185a22; border-color: #b1ffbf; }
143141
QPushButton[faction="GLA"]:pressed { background-color: #427b32; /*color: black;*/ }
@@ -149,14 +147,17 @@ QPushButton[faction="PRC"]:hover { background-color: #e74135; color: #ba
149147
QPushButton[faction="PRC"]:pressed { background-color: #e74135; color: white; }
150148
QPushButton[faction="PRC"]:pressed:hover { background-color: #e74135; color: #baff0c; }
151149

152-
HotkeysMainWindow QTreeWidget, HotkeysMainWindow QTabWidget, HotkeysMainWindow QScrollArea
150+
/* QPushButton[faction="USA"] already defined as basic non-property */
151+
/* If you want to change -- copy and edit styles down below */
152+
153+
EditorWindow QTreeWidget, EditorWindow QTabWidget, EditorWindow QScrollArea
153154
{
154155
background: rgba(0, 0, 0, 0.7);
155156
border-radius: 3px;
156157
border-width: 1px;
157158
border-style: outset;
158159
border-color: white;
159-
160+
160161
color: white;
161162
}
162163

@@ -210,7 +211,7 @@ QTabBar::tab:selected
210211
border-right-width: 1px;
211212
border-right-style: outset;
212213
border-right-color: white;
213-
214+
214215
background: #3543e7;
215216
}
216217

@@ -256,7 +257,7 @@ QDialog QLabel#left { margin: 0px 0px 0px 60px; }
256257
QDialog QLabel#right { margin: 30px 40px 30px 0px; }
257258

258259
/* Maybe will be useful in future */
259-
/* HotkeysMainWindow QMenu
260+
/* EditorWindow QMenu
260261
{
261262
background: rgba(0, 0, 0, 0);
262263
color: white;

0 commit comments

Comments
 (0)