Use QSignalMapper instead of GoToPage*() functions (not all calls converted yet)
authorunc0rr
Sat, 11 Dec 2010 23:28:52 +0300
changeset 4509 816a0bff5019
parent 4508 2a14477d1d15
child 4510 ce9b8206e681
Use QSignalMapper instead of GoToPage*() functions (not all calls converted yet)
QTfrontend/hwform.cpp
QTfrontend/hwform.h
--- a/QTfrontend/hwform.cpp	Sat Dec 11 21:27:43 2010 +0300
+++ b/QTfrontend/hwform.cpp	Sat Dec 11 23:28:52 2010 +0300
@@ -35,6 +35,7 @@
 #include <QDataWidgetMapper>
 #include <QTableView>
 #include <QCryptographicHash>
+#include <QSignalMapper>
 
 #include "hwform.h"
 #include "game.h"
@@ -108,13 +109,22 @@
     UpdateCampaignPage(0);
     UpdateWeapons();
 
+    pageSwitchMapper = new QSignalMapper(this);
+    connect(pageSwitchMapper, SIGNAL(mapped(int)), this, SLOT(GoToPage(int)));
+
     connect(config, SIGNAL(frontendFullscreen(bool)), this, SLOT(onFrontendFullscreen(bool)));
     onFrontendFullscreen(config->isFrontendFullscreen());
 
-    connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), this, SLOT(GoToSinglePlayer()));
-    connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), this, SLOT(GoToSetup()));
+    connect(ui.pageMain->BtnSinglePlayer, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageMain->BtnSinglePlayer, ID_PAGE_SINGLEPLAYER);
+
+    connect(ui.pageMain->BtnSetup, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageMain->BtnSetup, ID_PAGE_SETUP);
+    
     connect(ui.pageMain->BtnNet, SIGNAL(clicked()), this, SLOT(GoToNetType()));
-    connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), this, SLOT(GoToInfo()));
+    connect(ui.pageMain->BtnInfo, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageMain->BtnInfo, ID_PAGE_INFO);
+
     connect(ui.pageMain->BtnExit, SIGNAL(pressed()), this, SLOT(btnExitPressed()));
     connect(ui.pageMain->BtnExit, SIGNAL(clicked()), this, SLOT(btnExitClicked()));
 
@@ -179,8 +189,12 @@
     connect(ui.pageGameStats->BtnBack, SIGNAL(clicked()), this, SLOT(GoBack()));
 
     connect(ui.pageSinglePlayer->BtnSimpleGamePage, SIGNAL(clicked()), this, SLOT(SimpleGame()));
-    connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), this, SLOT(GoToTraining()));
-    connect(ui.pageSinglePlayer->BtnCampaignPage, SIGNAL(clicked()), this, SLOT(GoToCampaign()));
+    connect(ui.pageSinglePlayer->BtnTrainPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnTrainPage, ID_PAGE_TRAINING);
+    
+    connect(ui.pageSinglePlayer->BtnCampaignPage, SIGNAL(clicked()), pageSwitchMapper, SLOT(map()));
+    pageSwitchMapper->setMapping(ui.pageSinglePlayer->BtnCampaignPage, ID_PAGE_CAMPAIGN);
+
     connect(ui.pageSinglePlayer->BtnMultiplayer, SIGNAL(clicked()), this, SLOT(GoToMultiplayer()));
     connect(ui.pageSinglePlayer->BtnLoad, SIGNAL(clicked()), this, SLOT(GoToSaves()));
     connect(ui.pageSinglePlayer->BtnDemos, SIGNAL(clicked()), this, SLOT(GoToDemos()));
@@ -211,6 +225,7 @@
     connect(ui.pageNetType->BtnOfficialServer, SIGNAL(clicked()), this, SLOT(NetConnectOfficialServer()));
 
 
+
     ammoSchemeModel = new AmmoSchemeModel(this, cfgdir->absolutePath() + "/schemes.ini");
     ui.pageScheme->setModel(ammoSchemeModel);
     ui.pageMultiplayer->gameCFG->GameSchemes->setModel(ammoSchemeModel);
@@ -343,31 +358,6 @@
     ui.pageCampaign->CBTeam->addItems(teamslist);
 }
 
-void HWForm::GoToMain()
-{
-    GoToPage(ID_PAGE_MAIN);
-}
-
-void HWForm::GoToSinglePlayer()
-{
-    GoToPage(ID_PAGE_SINGLEPLAYER);
-}
-
-void HWForm::GoToTraining()
-{
-    GoToPage(ID_PAGE_TRAINING);
-}
-
-void HWForm::GoToCampaign()
-{
-    GoToPage(ID_PAGE_CAMPAIGN);
-}
-
-void HWForm::GoToSetup()
-{
-    GoToPage(ID_PAGE_SETUP);
-}
-
 void HWForm::GoToSelectNewWeapon()
 {
     ui.pageSelectWeapon->pWeapons->newWeaponsName();
@@ -386,11 +376,6 @@
     GoToPage(ID_PAGE_SELECTWEAPON);
 }
 
-void HWForm::GoToInfo()
-{
-    GoToPage(ID_PAGE_INFO);
-}
-
 void HWForm::GoToMultiplayer()
 {
     GoToPage(ID_PAGE_MULTIPLAYER);
@@ -520,9 +505,9 @@
     }
 }
 
-void HWForm::GoToPage(quint8 id)
+void HWForm::GoToPage(int id)
 {
-    quint8 lastid = ui.Pages->currentIndex();
+    int lastid = ui.Pages->currentIndex();
     PagesStack.push(ui.Pages->currentIndex());
     OnPageShown(id, lastid);
     ui.Pages->setCurrentIndex(id);
@@ -530,8 +515,8 @@
 
 void HWForm::GoBack()
 {
-    quint8 id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
-    quint8 curid = ui.Pages->currentIndex();
+    int id = PagesStack.isEmpty() ? ID_PAGE_MAIN : PagesStack.pop();
+    int curid = ui.Pages->currentIndex();
     ui.Pages->setCurrentIndex(id);
     OnPageShown(id, curid);
 
--- a/QTfrontend/hwform.h	Sat Dec 11 21:27:43 2010 +0300
+++ b/QTfrontend/hwform.h	Sat Dec 11 23:28:52 2010 +0300
@@ -42,6 +42,7 @@
 class QCloseEvent;
 class AmmoSchemeModel;
 class QSettings;
+class QSignalMapper;
 
 extern bool frontendEffects;
 extern QString playerHash;
@@ -59,17 +60,11 @@
     void updateXfire();
 
 private slots:
-    void GoToMain();
-    void GoToSinglePlayer();
-    void GoToSetup();
     void GoToMultiplayer();
     void GoToSaves();
     void GoToDemos();
     void GoToNet();
     void GoToNetType();
-    void GoToInfo();
-    void GoToTraining();
-    void GoToCampaign();
     void GoToSelectWeapon();
     void GoToSelectWeaponSet(int index);
     void GoToSelectNewWeapon();
@@ -78,7 +73,7 @@
     void GoToEditScheme();
     void GoToNewScheme();
     void GoToAdmin();
-    void GoToPage(quint8 id);
+    void GoToPage(int id);
     void GoBack();
     void AssociateFiles();
     void btnExitPressed();
@@ -163,9 +158,10 @@
     HWNewNet * hwnet;
     HWNamegen * namegen;
     AmmoSchemeModel * ammoSchemeModel;
-    QStack<quint8> PagesStack;
+    QStack<int> PagesStack;
     QTime eggTimer;
     BGWidget * wBackground;
+    QSignalMapper * pageSwitchMapper;
 
 #ifdef __APPLE__
         InstallController * panel;