QTfrontend/ui/widget/mapContainer.cpp
changeset 13260 2c0779260e8a
parent 13259 e13777374583
child 13261 01ac67500f50
equal deleted inserted replaced
13259:e13777374583 13260:2c0779260e8a
   335     staticMapChanged(m_staticMapModel->index(0, 0));
   335     staticMapChanged(m_staticMapModel->index(0, 0));
   336     missionMapChanged(m_missionMapModel->index(0, 0));
   336     missionMapChanged(m_missionMapModel->index(0, 0));
   337     changeMapType(MapModel::GeneratedMap);
   337     changeMapType(MapModel::GeneratedMap);
   338 }
   338 }
   339 
   339 
       
   340 void HWMapContainer::onImageReceived(const QPixmap &newImage)
       
   341 {
       
   342     // When image received from the engine.
       
   343     switch (m_mapInfo.type)
       
   344     {
       
   345         case MapModel::GeneratedMap:
       
   346         case MapModel::GeneratedMaze:
       
   347         case MapModel::GeneratedPerlin:
       
   348         case MapModel::HandDrawnMap:
       
   349         case MapModel::FortsMap:
       
   350             setImage(newImage);
       
   351             break;
       
   352         // Throw away image if we have switched the map mode in the meantime
       
   353         default:
       
   354             return;
       
   355     }
       
   356 }
       
   357 
   340 void HWMapContainer::setImage(const QPixmap &newImage)
   358 void HWMapContainer::setImage(const QPixmap &newImage)
   341 {
   359 {
   342     addInfoToPreview(newImage);
   360     addInfoToPreview(newImage);
   343     pMap = 0;
   361     pMap = 0;
   344 
   362 
   397 }
   415 }
   398 
   416 
   399 void HWMapContainer::askForGeneratedPreview()
   417 void HWMapContainer::askForGeneratedPreview()
   400 {
   418 {
   401     pMap = new HWMap(this);
   419     pMap = new HWMap(this);
   402     connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(setImage(const QPixmap)));
   420     connect(pMap, SIGNAL(ImageReceived(QPixmap)), this, SLOT(onImageReceived(const QPixmap)));
   403     connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int)));
   421     connect(pMap, SIGNAL(HHLimitReceived(int)), this, SLOT(setHHLimit(int)));
   404     connect(pMap, SIGNAL(destroyed(QObject *)), this, SLOT(onPreviewMapDestroyed(QObject *)));
   422     connect(pMap, SIGNAL(destroyed(QObject *)), this, SLOT(onPreviewMapDestroyed(QObject *)));
   405     pMap->getImage(m_seed,
   423     pMap->getImage(m_seed,
   406                    getTemplateFilter(),
   424                    getTemplateFilter(),
   407                    get_mapgen(),
   425                    get_mapgen(),
   557         changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0));
   575         changeMapType(MapModel::MissionMap, m_missionMapModel->index(m_missionMapModel->findMap(map), 0));
   558     } else
   576     } else
   559     {
   577     {
   560         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
   578         qDebug() << "HWMapContainer::intSetMap: Map doesn't exist: " << map;
   561         m_missingMap = true;
   579         m_missingMap = true;
   562         setMapNameLabel(map);
   580         m_curMap = map;
   563         if (m_mapInfo.type != MapModel::StaticMap && m_mapInfo.type != MapModel::MissionMap)
   581         if (m_mapInfo.type == MapModel::StaticMap)
       
   582             setupStaticMapsView();
       
   583         else if (m_mapInfo.type == MapModel::MissionMap)
       
   584             setupMissionMapsView();
       
   585         else
   564         {
   586         {
   565             m_mapInfo.type = MapModel::StaticMap;
   587             m_mapInfo.type = MapModel::StaticMap;
       
   588             setupStaticMapsView();
   566             changeMapType(m_mapInfo.type, QModelIndex());
   589             changeMapType(m_mapInfo.type, QModelIndex());
   567         }
   590         }
   568         updatePreview();
   591         updatePreview();
   569     }
   592     }
   570 }
   593 }
   771     updatePreview();
   794     updatePreview();
   772 }
   795 }
   773 
   796 
   774 void HWMapContainer::showEvent(QShowEvent * event)
   797 void HWMapContainer::showEvent(QShowEvent * event)
   775 {
   798 {
   776     if (!m_previewEnabled) {
   799     if (!m_previewEnabled)
       
   800     {
   777         m_previewEnabled = true;
   801         m_previewEnabled = true;
   778         setRandomTheme();
   802         setRandomTheme();
   779         updatePreview();
   803         updatePreview();
   780     }
   804     }
   781     QWidget::showEvent(event);
   805     QWidget::showEvent(event);
   787     if (!m_previewEnabled)
   811     if (!m_previewEnabled)
   788         return;
   812         return;
   789 
   813 
   790     if (pMap)
   814     if (pMap)
   791     {
   815     {
   792         disconnect(pMap, 0, this, SLOT(setImage(const QPixmap)));
   816         disconnect(pMap, 0, this, SLOT(onImageReceived(const QPixmap)));
   793         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   817         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
       
   818         disconnect(pMap, 0, this, SLOT(onPreviewMapDestroyed(QObject *)));
   794         pMap = 0;
   819         pMap = 0;
   795     }
   820     }
   796 
   821 
   797     QPixmap failPixmap;
   822     QPixmap failPixmap;
   798     QIcon failIcon;
   823     QIcon failIcon;
  1285     QItemSelectionModel * missionSelectionModel = missionMapList->selectionModel();
  1310     QItemSelectionModel * missionSelectionModel = missionMapList->selectionModel();
  1286     connect(missionSelectionModel,
  1311     connect(missionSelectionModel,
  1287             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1312             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1288             this,
  1313             this,
  1289             SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
  1314             SLOT(missionMapChanged(const QModelIndex &, const QModelIndex &)));
  1290     missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1315     if(!missionSelectionModel->hasSelection())
       
  1316         missionSelectionModel->setCurrentIndex(m_missionMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1291 }
  1317 }
  1292 
  1318 
  1293 void HWMapContainer::setupStaticMapsView()
  1319 void HWMapContainer::setupStaticMapsView()
  1294 {
  1320 {
  1295     if(m_staticViewSetup) return;
  1321     if(m_staticViewSetup) return;
  1301     QItemSelectionModel * staticSelectionModel = staticMapList->selectionModel();
  1327     QItemSelectionModel * staticSelectionModel = staticMapList->selectionModel();
  1302     connect(staticSelectionModel,
  1328     connect(staticSelectionModel,
  1303             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1329             SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
  1304             this,
  1330             this,
  1305             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
  1331             SLOT(staticMapChanged(const QModelIndex &, const QModelIndex &)));
  1306     staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1332     if(!staticSelectionModel->hasSelection())
       
  1333         staticSelectionModel->setCurrentIndex(m_staticMapModel->index(0, 0), QItemSelectionModel::Clear | QItemSelectionModel::SelectCurrent);
  1307 }
  1334 }
  1308 
  1335 
  1309 // Call this function instead of setting the text of the map name label
  1336 // Call this function instead of setting the text of the map name label
  1310 // directly.
  1337 // directly.
  1311 void HWMapContainer::setMapNameLabel(QString mapName)
  1338 void HWMapContainer::setMapNameLabel(QString mapName)