QTfrontend/ui/widget/mapContainer.cpp
changeset 7014 c0b32404ef74
parent 7008 25563f054ef3
child 7017 19a434fc91fc
equal deleted inserted replaced
7013:54db061b5710 7014:c0b32404ef74
   209     hhLimit = newHHLimit;
   209     hhLimit = newHHLimit;
   210 }
   210 }
   211 
   211 
   212 void HWMapContainer::mapChanged(int index)
   212 void HWMapContainer::mapChanged(int index)
   213 {
   213 {
       
   214     if (index < 0)
       
   215         return;
       
   216 
   214     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
   217     Q_ASSERT(chooseMap->itemData(index, Qt::UserRole + 1).canConvert<MapModel::MapInfo>());
   215     m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
   218     m_mapInfo = chooseMap->itemData(index, Qt::UserRole + 1).value<MapModel::MapInfo>();
   216     m_curMap = chooseMap->currentText();
   219     m_curMap = chooseMap->currentText();
   217 
   220 
   218     switch(m_mapInfo.type)
   221     switch(m_mapInfo.type)
   377 
   380 
   378 void HWMapContainer::intSetMap(const QString & map)
   381 void HWMapContainer::intSetMap(const QString & map)
   379 {
   382 {
   380     int id = m_mapModel->indexOf(map);
   383     int id = m_mapModel->indexOf(map);
   381 
   384 
   382     if(id >= 0)
   385     if (pMap)
   383     {
   386     {
   384         if (pMap)
   387         disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   385         {
   388         disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   386             disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
   389         pMap = 0;
   387             disconnect(pMap, 0, this, SLOT(setHHLimit(int)));
   390     }
   388             pMap = 0;
   391 
   389         }
   392     chooseMap->setCurrentIndex(id);
   390         chooseMap->setCurrentIndex(id);
   393 
       
   394     if(id < 0)
       
   395     {
       
   396         m_mapInfo.type = MapModel::Invalid;
       
   397         m_curMap = map;
   391     }
   398     }
   392 }
   399 }
   393 
   400 
   394 void HWMapContainer::setMap(const QString &map)
   401 void HWMapContainer::setMap(const QString &map)
   395 {
   402 {
   424             // get random map of same type
   431             // get random map of same type
   425             idx = m_mapModel->randomMap(m_mapInfo.type);
   432             idx = m_mapModel->randomMap(m_mapInfo.type);
   426             chooseMap->setCurrentIndex(idx);
   433             chooseMap->setCurrentIndex(idx);
   427             break;
   434             break;
   428         case MapModel::Invalid:
   435         case MapModel::Invalid:
   429             Q_ASSERT(false);
   436             chooseMap->setCurrentIndex(0);
   430     }
   437     }
   431 }
   438 }
   432 
   439 
   433 
   440 
   434 void HWMapContainer::setRandomSeed()
   441 void HWMapContainer::setRandomSeed()
   536     updatePreview();
   543     updatePreview();
   537 }
   544 }
   538 
   545 
   539 void HWMapContainer::updatePreview()
   546 void HWMapContainer::updatePreview()
   540 {
   547 {
       
   548     QPixmap failIcon;
       
   549 
   541     switch(m_mapInfo.type)
   550     switch(m_mapInfo.type)
   542     {
   551     {
       
   552         case MapModel::Invalid:
       
   553             failIcon = QPixmap(":/res/btnDisabled.png");
       
   554             imageButt->setIcon(failIcon);
       
   555             imageButt->setIconSize(failIcon.size());
       
   556             break;
   543         case MapModel::GeneratedMap:
   557         case MapModel::GeneratedMap:
   544             askForGeneratedPreview();
   558             askForGeneratedPreview();
   545             break;
   559             break;
   546         case MapModel::GeneratedMaze:
   560         case MapModel::GeneratedMaze:
   547             askForGeneratedPreview();
   561             askForGeneratedPreview();
   592             setRandomTheme();
   606             setRandomTheme();
   593     }
   607     }
   594 
   608 
   595     // restore map selection
   609     // restore map selection
   596     if (!m_curMap.isEmpty())
   610     if (!m_curMap.isEmpty())
   597     {
   611         setMap(m_curMap);
   598         int idx = chooseMap->findText(m_curMap);
       
   599         if (idx >= 0)
       
   600             chooseMap->setCurrentIndex(idx);
       
   601         else
       
   602             chooseMap->setCurrentIndex(0);
       
   603     }
       
   604 
   612 
   605 }
   613 }
   606 
   614 
   607 
   615 
   608 void HWMapContainer::onPreviewMapDestroyed(QObject * map)
   616 void HWMapContainer::onPreviewMapDestroyed(QObject * map)