67 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap())); |
67 connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomMap())); |
68 |
68 |
69 chooseMap = new QComboBox(mapWidget); |
69 chooseMap = new QComboBox(mapWidget); |
70 chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
70 chooseMap->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); |
71 m_mapModel = DataManager::instance().mapModel(); |
71 m_mapModel = DataManager::instance().mapModel(); |
|
72 chooseMap->setEditable(false); |
72 chooseMap->setModel(m_mapModel); |
73 chooseMap->setModel(m_mapModel); |
73 |
74 |
74 // update model views after model changes (to e.g. re-adjust separators) |
75 // update model views after model changes (to e.g. re-adjust separators) |
75 connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews())); |
76 connect(&DataManager::instance(), SIGNAL(updated()), this, SLOT(updateModelViews())); |
76 |
77 |
208 hhLimit = newHHLimit; |
208 hhLimit = newHHLimit; |
209 } |
209 } |
210 |
210 |
211 void HWMapContainer::mapChanged(int index) |
211 void HWMapContainer::mapChanged(int index) |
212 { |
212 { |
213 m_mapInfo = MapModel::mapInfoFromData(chooseMap->itemData(chooseMap->currentIndex())); |
213 Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>()); |
|
214 m_mapInfo = chooseMap->itemData(chooseMap->currentIndex(), Qt::UserRole + 1).value<MapModel::MapInfo>(); |
214 |
215 |
215 switch(m_mapInfo.type) |
216 switch(m_mapInfo.type) |
216 { |
217 { |
217 case MapModel::GeneratedMap: |
218 case MapModel::GeneratedMap: |
218 mapgen = MAPGEN_REGULAR; |
219 mapgen = MAPGEN_REGULAR; |
220 gbThemes->show(); |
221 gbThemes->show(); |
221 lblFilter->show(); |
222 lblFilter->show(); |
222 cbTemplateFilter->show(); |
223 cbTemplateFilter->show(); |
223 maze_size_label->hide(); |
224 maze_size_label->hide(); |
224 cbMazeSize->hide(); |
225 cbMazeSize->hide(); |
225 emit mapChanged("+rnd+"); |
|
226 emit themeChanged(m_mapInfo.theme); |
|
227 break; |
226 break; |
228 case MapModel::GeneratedMaze: |
227 case MapModel::GeneratedMaze: |
229 mapgen = MAPGEN_MAZE; |
228 mapgen = MAPGEN_MAZE; |
230 updatePreview(); |
229 updatePreview(); |
231 gbThemes->show(); |
230 gbThemes->show(); |
232 lblFilter->hide(); |
231 lblFilter->hide(); |
233 cbTemplateFilter->hide(); |
232 cbTemplateFilter->hide(); |
234 maze_size_label->show(); |
233 maze_size_label->show(); |
235 cbMazeSize->show(); |
234 cbMazeSize->show(); |
236 emit mapChanged("+maze+"); |
|
237 emit themeChanged(m_mapInfo.theme); |
|
238 break; |
235 break; |
239 case MapModel::HandDrawnMap: |
236 case MapModel::HandDrawnMap: |
240 mapgen = MAPGEN_DRAWN; |
237 mapgen = MAPGEN_DRAWN; |
241 updatePreview(); |
238 updatePreview(); |
242 gbThemes->show(); |
239 gbThemes->show(); |
243 lblFilter->hide(); |
240 lblFilter->hide(); |
244 cbTemplateFilter->hide(); |
241 cbTemplateFilter->hide(); |
245 maze_size_label->hide(); |
242 maze_size_label->hide(); |
246 cbMazeSize->hide(); |
243 cbMazeSize->hide(); |
247 emit mapChanged("+drawn+"); |
|
248 emit themeChanged(m_mapInfo.theme); |
|
249 break; |
244 break; |
250 default: |
245 default: |
251 mapgen = MAPGEN_MAP; |
246 mapgen = MAPGEN_MAP; |
252 updatePreview(); |
247 updatePreview(); |
253 gbThemes->hide(); |
248 gbThemes->hide(); |
254 lblFilter->hide(); |
249 lblFilter->hide(); |
255 cbTemplateFilter->hide(); |
250 cbTemplateFilter->hide(); |
256 maze_size_label->hide(); |
251 maze_size_label->hide(); |
257 cbMazeSize->hide(); |
252 cbMazeSize->hide(); |
258 emit mapChanged(m_mapInfo.name); |
253 } |
259 } |
254 |
260 |
255 if (m_mapInfo.theme.isEmpty()) |
|
256 emit themeChanged(lvThemes->currentIndex().data().toString()); |
|
257 emit mapChanged(m_mapInfo.name); |
261 emit mapgenChanged(mapgen); |
258 emit mapgenChanged(mapgen); |
262 } |
259 } |
263 |
260 |
264 // Should this add text to identify map size? |
261 // Should this add text to identify map size? |
265 void HWMapContainer::addInfoToPreview(QPixmap image) |
262 void HWMapContainer::addInfoToPreview(QPixmap image) |
301 ); |
298 ); |
302 } |
299 } |
303 |
300 |
304 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &) |
301 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &) |
305 { |
302 { |
306 QString theme = current.data().toString(); |
303 m_mapInfo.theme = current.data().toString(); |
307 QList<QVariant> mapInfo; |
|
308 mapInfo.push_back(QString("+rnd+")); |
|
309 mapInfo.push_back(theme); |
|
310 mapInfo.push_back(18); |
|
311 mapInfo.push_back(false); |
|
312 chooseMap->setItemData(0, mapInfo); |
|
313 mapInfo[0] = QString("+maze+"); |
|
314 chooseMap->setItemData(1, mapInfo); |
|
315 mapInfo[0] = QString("+drawn+"); |
|
316 chooseMap->setItemData(2, mapInfo); |
|
317 |
304 |
318 gbThemes->setIcon(qVariantValue<QIcon>(current.data(Qt::UserRole))); |
305 gbThemes->setIcon(qVariantValue<QIcon>(current.data(Qt::UserRole))); |
319 emit themeChanged(theme); |
306 emit themeChanged(m_mapInfo.theme); |
320 } |
307 } |
321 |
308 |
322 QString HWMapContainer::getCurrentSeed() const |
309 QString HWMapContainer::getCurrentSeed() const |
323 { |
310 { |
324 return m_seed; |
311 return m_seed; |
325 } |
312 } |
326 |
313 |
327 QString HWMapContainer::getCurrentMap() const |
314 QString HWMapContainer::getCurrentMap() const |
328 { |
315 { |
|
316 if(chooseMap->currentIndex() < MAPGEN_MAP) return QString(); |
329 return(m_mapInfo.name); |
317 return(m_mapInfo.name); |
330 } |
318 } |
331 |
319 |
332 QString HWMapContainer::getCurrentTheme() const |
320 QString HWMapContainer::getCurrentTheme() const |
333 { |
321 { |
382 void HWMapContainer::intSetMap(const QString & map) |
370 void HWMapContainer::intSetMap(const QString & map) |
383 { |
371 { |
384 int id = 0; |
372 int id = 0; |
385 for(int i = 0; i < chooseMap->count(); i++) |
373 for(int i = 0; i < chooseMap->count(); i++) |
386 { |
374 { |
387 MapModel::MapInfo mapInfo = MapModel::mapInfoFromData(chooseMap->itemData(i)); |
375 // skip separators |
388 |
376 if (chooseMap->itemData(i, Qt::AccessibleDescriptionRole) == QLatin1String("separator")) |
389 if (mapInfo.name == map) |
377 continue; |
|
378 Q_ASSERT(chooseMap->itemData(i, Qt::UserRole + 1).canConvert<MapModel::MapInfo>()); |
|
379 MapModel::MapInfo mapInfo = chooseMap->itemData(i, Qt::UserRole + 1).value<MapModel::MapInfo>(); |
|
380 |
|
381 if (mapInfo.name == map) |
390 { |
382 { |
391 id = i; |
383 id = i; |
392 break; |
384 break; |
393 } |
385 } |
394 } |
386 } |
574 case MapModel::HandDrawnMap: |
566 case MapModel::HandDrawnMap: |
575 askForGeneratedPreview(); |
567 askForGeneratedPreview(); |
576 break; |
568 break; |
577 default: |
569 default: |
578 QPixmap mapImage; |
570 QPixmap mapImage; |
579 QFile tmpfile; |
571 bool success = mapImage.load( |
580 tmpfile.setFileName(cfgdir->absolutePath() + "/Data/Maps/" + m_mapInfo.name + "/preview.png"); |
572 DataManager::instance().findFileForRead( |
581 if (!tmpfile.exists()) tmpfile.setFileName(datadir->absolutePath() + "/Maps/" + m_mapInfo.name + "/preview.png"); |
573 "Maps/" + m_mapInfo.name + "/preview.png") |
582 if(!mapImage.load(QFileInfo(tmpfile).absoluteFilePath())) |
574 ); |
|
575 |
|
576 if(!success) |
583 { |
577 { |
584 imageButt->setIcon(QIcon()); |
578 imageButt->setIcon(QIcon()); |
585 return; |
579 return; |
586 } |
580 } |
587 |
581 |
604 |
598 |
605 void HWMapContainer::updateModelViews() |
599 void HWMapContainer::updateModelViews() |
606 { |
600 { |
607 numMissions = m_mapModel->missionCount(); |
601 numMissions = m_mapModel->missionCount(); |
608 |
602 |
609 intSetMap(m_mapInfo.name); |
603 if (!m_mapInfo.name.isEmpty()) |
610 |
604 intSetMap(m_mapInfo.name); |
611 /* |
605 } |
612 int nGenMaps = m_mapModel->generatorCount(); |
|
613 |
|
614 // insert double separator after random maps/mazes/etc |
|
615 chooseMap->insertSeparator(nGenMaps); |
|
616 chooseMap->insertSeparator(nGenMaps); |
|
617 |
|
618 // separator between missions and regular maps |
|
619 chooseMap->insertSeparator(nGenMaps + m_mapModel->missionCount()); |
|
620 */ |
|
621 } |
|