21 #include <QLabel> |
21 #include <QLabel> |
22 #include <QListWidget> |
22 #include <QListWidget> |
23 #include <QListWidgetItem> |
23 #include <QListWidgetItem> |
24 #include <QPushButton> |
24 #include <QPushButton> |
25 |
25 |
|
26 #include <QSettings> |
|
27 |
26 #include "pagetraining.h" |
28 #include "pagetraining.h" |
27 #include "hwconsts.h" |
29 #include "hwconsts.h" |
28 |
30 |
29 QLayout * PageTraining::bodyLayoutDefinition() |
31 QLayout * PageTraining::bodyLayoutDefinition() |
30 { |
32 { |
106 |
108 |
107 PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) |
109 PageTraining::PageTraining(QWidget* parent) : AbstractPage(parent) |
108 { |
110 { |
109 initPage(); |
111 initPage(); |
110 |
112 |
|
113 // preload localized descriptions/etc TODO; this is just mockup code |
|
114 m_info = new QSettings(datadir->absolutePath() + "/Locale/missions_en.txt", |
|
115 QSettings::IniFormat, this); |
|
116 |
111 // TODO -> this should be done in a tool "DataDir" class |
117 // TODO -> this should be done in a tool "DataDir" class |
112 QDir tmpdir; |
118 QDir tmpdir; |
113 tmpdir.cd(cfgdir->absolutePath()); |
119 tmpdir.cd(cfgdir->absolutePath()); |
114 tmpdir.cd("Data/Missions/Training"); |
120 tmpdir.cd("Data/Missions/Training"); |
115 QStringList missionList = scriptList(tmpdir); |
121 QStringList missionList = scriptList(tmpdir); |
125 { |
131 { |
126 if (!missionList.contains(mission)) |
132 if (!missionList.contains(mission)) |
127 missionList.append(mission); |
133 missionList.append(mission); |
128 } |
134 } |
129 |
135 |
130 // add only default scripts that have names different from detected user scripts |
136 // add default scripts that have names different from detected user scripts |
131 foreach (const QString & mission, missionList) |
137 foreach (const QString & mission, missionList) |
132 { |
138 { |
133 QListWidgetItem * item = new QListWidgetItem(mission); |
139 QListWidgetItem * item = new QListWidgetItem(mission); |
134 |
140 |
135 // replace underscores in mission name with spaces |
141 // replace underscores in mission name with spaces |
168 void PageTraining::updateInfo() |
174 void PageTraining::updateInfo() |
169 { |
175 { |
170 if (lstMissions->currentItem()) |
176 if (lstMissions->currentItem()) |
171 { |
177 { |
172 // TODO also use .pngs in userdata folder |
178 // TODO also use .pngs in userdata folder |
173 QString thumbFile = datadir->absolutePath() + "/Graphics/Missions/Training/" + lstMissions->currentItem()->data(Qt::UserRole).toString() + ".png"; |
179 QString thumbFile = datadir->absolutePath() + |
|
180 "/Graphics/Missions/Training/" + |
|
181 lstMissions->currentItem()->data(Qt::UserRole).toString() + |
|
182 ".png"; |
|
183 |
174 if (QFile::exists(thumbFile)) |
184 if (QFile::exists(thumbFile)) |
175 btnPreview->setIcon(QIcon(thumbFile)); |
185 btnPreview->setIcon(QIcon(thumbFile)); |
176 else |
186 else |
177 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
187 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
178 |
188 |
179 lblCaption->setText("<h2>" + lstMissions->currentItem()->text()+"</h2>"); |
189 QString realName = lstMissions->currentItem()->data( |
180 // TODO load mission description from file |
190 Qt::UserRole).toString(); |
181 lblDescription->setText("< Imagine Mission Description here >\n\nThank you."); |
191 |
|
192 QString caption = m_info->value(realName + ".name", |
|
193 lstMissions->currentItem()->text()).toString(); |
|
194 |
|
195 QString description = m_info->value(realName + ".desc", |
|
196 tr("No description available")).toString(); |
|
197 |
|
198 lblCaption->setText("<h2>" + caption +"</h2>"); |
|
199 lblDescription->setText(description); |
182 } |
200 } |
183 else |
201 else |
184 { |
202 { |
185 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
203 btnPreview->setIcon(QIcon(":/res/Trainings.png")); |
186 lblCaption->setText(tr("Select a mission!")); |
204 lblCaption->setText(tr("Select a mission!")); |