QTfrontend/mapContainer.cpp
changeset 320 1ee7f087195a
parent 314 83773ccf4f09
child 325 17c860483407
equal deleted inserted replaced
319:7f3bd9e31f18 320:1ee7f087195a
    31 
    31 
    32 HWMapContainer::HWMapContainer(QWidget * parent) :
    32 HWMapContainer::HWMapContainer(QWidget * parent) :
    33   QWidget(parent), mainLayout(this)
    33   QWidget(parent), mainLayout(this)
    34 {
    34 {
    35   imageButt=new QPushButton(this);
    35   imageButt=new QPushButton(this);
    36   imageButt->setMaximumSize(256, 128);
    36   imageButt->setFixedSize(256, 128);
    37   imageButt->setFlat(true);
    37   imageButt->setFlat(true);
    38   imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    38   imageButt->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
    39   mainLayout.addWidget(imageButt);
    39   mainLayout.addWidget(imageButt);
    40   connect(imageButt, SIGNAL(clicked()), this, SLOT(changeImage()));
    40   connect(imageButt, SIGNAL(clicked()), this, SLOT(setRandomSeed()));
    41   changeImage();
    41   setRandomSeed();
    42 
    42 
    43   chooseMap=new QComboBox(this);
    43   chooseMap=new QComboBox(this);
    44   QDir tmpdir;
    44   QDir tmpdir;
    45   tmpdir.cd(datadir->absolutePath());
    45   tmpdir.cd(datadir->absolutePath());
    46   tmpdir.cd("Maps");
    46   tmpdir.cd("Maps");
    80     changeImage();
    80     changeImage();
    81     return;
    81     return;
    82   }
    82   }
    83 
    83 
    84   QPixmap mapImage;
    84   QPixmap mapImage;
    85   if(!mapImage.load(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.png")) {
    85   if(!mapImage.load(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/map.png")) {
    86     changeImage();
    86     changeImage();
    87     chooseMap->setCurrentIndex(0);
    87     chooseMap->setCurrentIndex(0);
    88     return;
    88     return;
    89   }
    89   }
    90   imageButt->setIcon(mapImage.scaled(256,128));
    90   imageButt->setIcon(mapImage.scaled(256, 128));
       
    91   QFile mapCfgFile(datadir->absolutePath() + "/Maps/" + chooseMap->currentText() + "/map.cfg");
       
    92   if (mapCfgFile.open(QFile::ReadOnly)) {
       
    93     QTextStream input(&mapCfgFile);
       
    94     input >> theme;
       
    95     mapCfgFile.close();
       
    96   }
    91 }
    97 }
    92 
    98 
    93 void HWMapContainer::changeImage()
    99 void HWMapContainer::changeImage()
    94 {
   100 {
    95   pMap=new HWMap();
   101   pMap = new HWMap();
    96   connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
   102   connect(pMap, SIGNAL(ImageReceived(const QImage)), this, SLOT(setImage(const QImage)));
    97   m_seed = QUuid::createUuid().toString();
       
    98   pMap->getImage(m_seed.toStdString());
   103   pMap->getImage(m_seed.toStdString());
       
   104   theme = (Themes->size() > 0) ? Themes->at(rand() % Themes->size()) : "steel";
    99 }
   105 }
   100 
   106 
   101 QString HWMapContainer::getCurrentSeed() const
   107 QString HWMapContainer::getCurrentSeed() const
   102 {
   108 {
   103   return m_seed;
   109   return m_seed;
   104 }
   110 }
   105 
   111 
   106 QString HWMapContainer::getCurrentMap() const
   112 QString HWMapContainer::getCurrentMap() const
   107 {
   113 {
   108   if(!chooseMap->currentIndex()) throw MapFileErrorException();
   114   if(!chooseMap->currentIndex()) return QString();
   109   return chooseMap->currentText();
   115   return chooseMap->currentText();
   110 }
   116 }
   111 
   117 
   112 QString HWMapContainer::getCurrentTheme() const
   118 QString HWMapContainer::getCurrentTheme() const
   113 {
   119 {
   114   if(!chooseMap->currentIndex()) throw MapFileErrorException();
   120 	return theme;
   115   QFile mapCfgFile(datadir->absolutePath()+"/Maps/"+chooseMap->currentText()+"/map.cfg");
       
   116   if (mapCfgFile.open(QFile::ReadOnly)) {
       
   117     QTextStream input(&mapCfgFile);
       
   118     QString theme;
       
   119     input >> theme;
       
   120     mapCfgFile.close();
       
   121     if(theme.length()>256) throw MapFileErrorException(); // theme name too long
       
   122     return theme;
       
   123   } else {
       
   124     throw MapFileErrorException();
       
   125   }
       
   126 }
   121 }
   127 
   122 
   128 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   123 void HWMapContainer::resizeEvent ( QResizeEvent * event )
   129 {
   124 {
   130   //imageButt->setIconSize(imageButt->size());
   125   //imageButt->setIconSize(imageButt->size());
   131 }
   126 }
       
   127 
       
   128 void HWMapContainer::setSeed(const QString & seed)
       
   129 {
       
   130 	m_seed = seed;
       
   131 	changeImage();
       
   132 }
       
   133 
       
   134 void HWMapContainer::setMap(const QString & map)
       
   135 {
       
   136 
       
   137 }
       
   138 
       
   139 void HWMapContainer::setTheme(const QString & theme)
       
   140 {
       
   141 	this->theme = theme;
       
   142 }
       
   143 
       
   144 void HWMapContainer::setRandomSeed()
       
   145 {
       
   146   m_seed = QUuid::createUuid().toString();
       
   147   changeImage();
       
   148 }