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}
0 commit comments