22 #include <QGridLayout> |
22 #include <QGridLayout> |
23 #include <QSpinBox> |
23 #include <QSpinBox> |
24 #include <QLabel> |
24 #include <QLabel> |
25 #include <QMessageBox> |
25 #include <QMessageBox> |
26 #include <QTableView> |
26 #include <QTableView> |
|
27 #include <QScrollBar> |
|
28 #include <QTabWidget> |
27 #include <QPushButton> |
29 #include <QPushButton> |
|
30 #include <QDebug> |
|
31 #include <QList> |
28 |
32 |
29 #include "gamecfgwidget.h" |
33 #include "gamecfgwidget.h" |
30 #include "igbox.h" |
34 #include "igbox.h" |
31 #include "DataManager.h" |
35 #include "DataManager.h" |
32 #include "hwconsts.h" |
36 #include "hwconsts.h" |
33 #include "ammoSchemeModel.h" |
37 #include "ammoSchemeModel.h" |
34 #include "proto.h" |
38 #include "proto.h" |
35 #include "GameStyleModel.h" |
39 #include "GameStyleModel.h" |
|
40 #include "themeprompt.h" |
36 |
41 |
37 GameCFGWidget::GameCFGWidget(QWidget* parent) : |
42 GameCFGWidget::GameCFGWidget(QWidget* parent) : |
38 QGroupBox(parent) |
43 QGroupBox(parent) |
39 , mainLayout(this) |
44 , mainLayout(this) |
40 , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") |
45 , seedRegexp("\\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\}") |
41 { |
46 { |
42 mainLayout.setMargin(0); |
47 mainLayout.setMargin(0); |
43 // mainLayout.setSizeConstraint(QLayout::SetMinimumSize); |
48 setMinimumHeight(310); |
44 |
49 setMaximumHeight(447); |
45 pMapContainer = new HWMapContainer(this); |
50 setMinimumWidth(470); |
46 mainLayout.addWidget(pMapContainer, 0, 0); |
51 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
47 |
52 |
48 IconedGroupBox *GBoxOptions = new IconedGroupBox(this); |
53 // Easy containers for the map/game options in either stacked or tabbed mode |
49 GBoxOptions->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); |
54 |
50 mainLayout.addWidget(GBoxOptions, 1, 0); |
55 mapContainerFree = new QWidget(); |
51 |
56 mapContainerTabbed = new QWidget(); |
52 QGridLayout *GBoxOptionsLayout = new QGridLayout(GBoxOptions); |
57 optionsContainerFree = new QWidget(); |
53 |
58 optionsContainerTabbed = new QWidget(); |
54 GBoxOptions->setTitle(tr("Game Options")); |
59 tabbed = false; |
55 GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), GBoxOptions), 1, 0); |
60 |
56 |
61 // Container for when in tabbed mode |
57 Scripts = new QComboBox(GBoxOptions); |
62 |
|
63 tabs = new QTabWidget(this); |
|
64 tabs->setFixedWidth(470); |
|
65 tabs->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
66 tabs->addTab(mapContainerTabbed, tr("Map")); |
|
67 tabs->addTab(optionsContainerTabbed, tr("Game options")); |
|
68 tabs->setObjectName("gameCfgWidgetTabs"); |
|
69 mainLayout.addWidget(tabs, 1); |
|
70 tabs->setVisible(false); |
|
71 |
|
72 // Container for when in stacked mode |
|
73 |
|
74 StackContainer = new QWidget(); |
|
75 StackContainer->setObjectName("gameStackContainer"); |
|
76 mainLayout.addWidget(StackContainer, 1); |
|
77 QVBoxLayout * stackLayout = new QVBoxLayout(StackContainer); |
|
78 |
|
79 // Map options |
|
80 |
|
81 pMapContainer = new HWMapContainer(mapContainerFree); |
|
82 stackLayout->addWidget(mapContainerFree, 0, Qt::AlignHCenter); |
|
83 pMapContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
84 pMapContainer->setFixedSize(width() - 14, 278); |
|
85 mapContainerFree->setFixedSize(pMapContainer->width(), pMapContainer->height()); |
|
86 |
|
87 // Horizontal divider |
|
88 |
|
89 QFrame * divider = new QFrame(); |
|
90 divider->setFrameShape(QFrame::HLine); |
|
91 divider->setFrameShadow(QFrame::Plain); |
|
92 stackLayout->addWidget(divider, 0, Qt::AlignBottom); |
|
93 //stackLayout->setRowMinimumHeight(1, 10); |
|
94 |
|
95 // Game options |
|
96 |
|
97 optionsContainerTabbed->setContentsMargins(0, 0, 0, 0); |
|
98 optionsContainerFree->setFixedSize(width() - 14, 140); |
|
99 stackLayout->addWidget(optionsContainerFree, 0, Qt::AlignHCenter); |
|
100 |
|
101 OptionsInnerContainer = new QWidget(optionsContainerFree); |
|
102 m_childWidgets << OptionsInnerContainer; |
|
103 OptionsInnerContainer->setFixedSize(optionsContainerFree->width(), optionsContainerFree->height()); |
|
104 OptionsInnerContainer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); |
|
105 GBoxOptionsLayout = new QGridLayout(OptionsInnerContainer); |
|
106 |
|
107 GBoxOptionsLayout->addWidget(new QLabel(QLabel::tr("Style"), this), 1, 0); |
|
108 |
|
109 Scripts = new QComboBox(this); |
58 GBoxOptionsLayout->addWidget(Scripts, 1, 1); |
110 GBoxOptionsLayout->addWidget(Scripts, 1, 1); |
59 |
111 |
60 Scripts->setModel(DataManager::instance().gameStyleModel()); |
112 Scripts->setModel(DataManager::instance().gameStyleModel()); |
61 m_curScript = Scripts->currentText(); |
113 m_curScript = Scripts->currentText(); |
62 connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int))); |
114 connect(Scripts, SIGNAL(currentIndexChanged(int)), this, SLOT(scriptChanged(int))); |
63 |
115 |
64 QWidget *SchemeWidget = new QWidget(GBoxOptions); |
116 QWidget *SchemeWidget = new QWidget(this); |
65 GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2); |
117 GBoxOptionsLayout->addWidget(SchemeWidget, 2, 0, 1, 2); |
66 |
118 |
67 QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget); |
119 QGridLayout *SchemeWidgetLayout = new QGridLayout(SchemeWidget); |
68 SchemeWidgetLayout->setMargin(0); |
120 SchemeWidgetLayout->setMargin(0); |
69 |
121 |
74 SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); |
126 SchemeWidgetLayout->addWidget(new QLabel(QLabel::tr("Scheme"), SchemeWidget), 0, 0); |
75 |
127 |
76 QPixmap pmEdit(":/res/edit.png"); |
128 QPixmap pmEdit(":/res/edit.png"); |
77 |
129 |
78 QPushButton * goToSchemePage = new QPushButton(SchemeWidget); |
130 QPushButton * goToSchemePage = new QPushButton(SchemeWidget); |
79 goToSchemePage->setToolTip(tr("Edit schemes")); |
131 goToSchemePage->setWhatsThis(tr("Edit schemes")); |
80 goToSchemePage->setIconSize(pmEdit.size()); |
132 goToSchemePage->setIconSize(pmEdit.size()); |
81 goToSchemePage->setIcon(pmEdit); |
133 goToSchemePage->setIcon(pmEdit); |
82 goToSchemePage->setMaximumWidth(pmEdit.width() + 6); |
134 goToSchemePage->setMaximumWidth(pmEdit.width() + 6); |
83 SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3); |
135 SchemeWidgetLayout->addWidget(goToSchemePage, 0, 3); |
84 connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes())); |
136 connect(goToSchemePage, SIGNAL(clicked()), this, SLOT(jumpToSchemes())); |
89 SchemeWidgetLayout->addWidget(WeaponsName, 1, 2); |
141 SchemeWidgetLayout->addWidget(WeaponsName, 1, 2); |
90 |
142 |
91 connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
143 connect(WeaponsName, SIGNAL(currentIndexChanged(int)), this, SLOT(ammoChanged(int))); |
92 |
144 |
93 QPushButton * goToWeaponPage = new QPushButton(SchemeWidget); |
145 QPushButton * goToWeaponPage = new QPushButton(SchemeWidget); |
94 goToWeaponPage->setToolTip(tr("Edit weapons")); |
146 goToWeaponPage->setWhatsThis(tr("Edit weapons")); |
95 goToWeaponPage->setIconSize(pmEdit.size()); |
147 goToWeaponPage->setIconSize(pmEdit.size()); |
96 goToWeaponPage->setIcon(pmEdit); |
148 goToWeaponPage->setIcon(pmEdit); |
97 goToWeaponPage->setMaximumWidth(pmEdit.width() + 6); |
149 goToWeaponPage->setMaximumWidth(pmEdit.width() + 6); |
98 SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3); |
150 SchemeWidgetLayout->addWidget(goToWeaponPage, 1, 3); |
99 connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons())); |
151 connect(goToWeaponPage, SIGNAL(clicked()), this, SLOT(jumpToWeapons())); |
100 |
152 |
101 bindEntries = new QCheckBox(SchemeWidget); |
153 bindEntries = new QCheckBox(SchemeWidget); |
102 bindEntries->setToolTip(tr("When this option is enabled selecting a game scheme will auto-select a weapon")); |
154 bindEntries->setWhatsThis(tr("Game scheme will auto-select a weapon")); |
103 bindEntries->setChecked(true); |
155 bindEntries->setChecked(true); |
104 bindEntries->setMaximumWidth(42); |
156 bindEntries->setMaximumWidth(42); |
105 bindEntries->setStyleSheet( "QCheckBox::indicator:checked { image: url(\":/res/lock.png\"); }" |
157 bindEntries->setStyleSheet( "QCheckBox::indicator:checked { image: url(\":/res/lock.png\"); }" |
106 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\"); }" ); |
158 "QCheckBox::indicator:unchecked { image: url(\":/res/unlock.png\"); }" ); |
107 SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter); |
159 SchemeWidgetLayout->addWidget(bindEntries, 0, 1, 0, 1, Qt::AlignVCenter); |
114 connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); |
166 connect(pMapContainer, SIGNAL(newTemplateFilter(int)), this, SLOT(templateFilterChanged(int))); |
115 connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap())); |
167 connect(pMapContainer, SIGNAL(drawMapRequested()), this, SIGNAL(goToDrawMap())); |
116 connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &))); |
168 connect(pMapContainer, SIGNAL(drawnMapChanged(const QByteArray &)), this, SLOT(onDrawnMapChanged(const QByteArray &))); |
117 |
169 |
118 connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews())); |
170 connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews())); |
|
171 } |
|
172 |
|
173 void GameCFGWidget::setTabbed(bool tabbed) |
|
174 { |
|
175 if (tabbed && !this->tabbed) |
|
176 { // Make tabbed |
|
177 tabs->setCurrentIndex(0); |
|
178 StackContainer->setVisible(false); |
|
179 tabs->setVisible(true); |
|
180 pMapContainer->setParent(mapContainerTabbed); |
|
181 OptionsInnerContainer->setParent(optionsContainerTabbed); |
|
182 pMapContainer->setVisible(true); |
|
183 setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Expanding); |
|
184 this->tabbed = true; |
|
185 } |
|
186 else if (!tabbed && this->tabbed) |
|
187 { // Make stacked |
|
188 pMapContainer->setParent(mapContainerFree); |
|
189 OptionsInnerContainer->setParent(optionsContainerFree); |
|
190 tabs->setVisible(false); |
|
191 StackContainer->setVisible(true); |
|
192 pMapContainer->setVisible(true); |
|
193 setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
|
194 this->tabbed = false; |
|
195 } |
|
196 |
|
197 // Restore scrollbar palettes, since Qt seems to forget them easily when switching parents |
|
198 QList<QScrollBar *> allSBars = findChildren<QScrollBar *>(); |
|
199 QPalette pal = palette(); |
|
200 pal.setColor(QPalette::WindowText, QColor(0xff, 0xcc, 0x00)); |
|
201 pal.setColor(QPalette::Button, QColor(0x00, 0x35, 0x1d)); |
|
202 pal.setColor(QPalette::Base, QColor(0x00, 0x35, 0x1d)); |
|
203 pal.setColor(QPalette::Window, QColor(0x00, 0x00, 0x00)); |
|
204 |
|
205 for (int i = 0; i < allSBars.size(); ++i) |
|
206 allSBars.at(i)->setPalette(pal); |
119 } |
207 } |
120 |
208 |
121 void GameCFGWidget::jumpToSchemes() |
209 void GameCFGWidget::jumpToSchemes() |
122 { |
210 { |
123 emit goToSchemes(GameSchemes->currentIndex()); |
211 emit goToSchemes(GameSchemes->currentIndex()); |