QTfrontend/ui/widget/mapContainer.cpp
changeset 8467 dc53b4b66fa0
parent 8453 06541556df53
child 8475 f605bc59c603
equal deleted inserted replaced
8466:29b891dbf2a0 8467:dc53b4b66fa0
   130     /* Map preview label */
   130     /* Map preview label */
   131 
   131 
   132     QLabel * lblMapPreviewText = new QLabel(this);
   132     QLabel * lblMapPreviewText = new QLabel(this);
   133     lblMapPreviewText->setText(tr("Map preview:"));
   133     lblMapPreviewText->setText(tr("Map preview:"));
   134     leftLayout->addWidget(lblMapPreviewText, 0);
   134     leftLayout->addWidget(lblMapPreviewText, 0);
   135     leftLayout->addSpacing(2);
       
   136 
   135 
   137     /* Map Preview */
   136     /* Map Preview */
   138 
   137 
   139     mapPreview = new QLabel(this);
   138     mapPreview = new QPushButton(this);
   140     mapPreview->setObjectName("mapPreview");
   139     mapPreview->setObjectName("mapPreview");
   141     mapPreview->setFixedSize(256, 128);
   140     mapPreview->setFixedSize(256, 128);
       
   141     mapPreview->setContentsMargins(0, 0, 0, 0);
   142     leftLayout->addWidget(mapPreview, 0);
   142     leftLayout->addWidget(mapPreview, 0);
       
   143     connect(mapPreview, SIGNAL(clicked()), this, SLOT(previewClicked()));
   143 
   144 
   144     /* Bottom-Left layout */
   145     /* Bottom-Left layout */
   145 
   146 
   146     QVBoxLayout * bottomLeftLayout = new QVBoxLayout();
   147     QVBoxLayout * bottomLeftLayout = new QVBoxLayout();
   147     leftLayout->addLayout(bottomLeftLayout, 1);
   148     leftLayout->addLayout(bottomLeftLayout, 1);
   228     lblDesc = new QLabel();
   229     lblDesc = new QLabel();
   229     lblDesc->setWordWrap(true);
   230     lblDesc->setWordWrap(true);
   230     lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
   231     lblDesc->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
   231     lblDesc->setAlignment(Qt::AlignTop | Qt::AlignLeft);
   232     lblDesc->setAlignment(Qt::AlignTop | Qt::AlignLeft);
   232     lblDesc->setStyleSheet("font: 10px;");
   233     lblDesc->setStyleSheet("font: 10px;");
   233     bottomLeftLayout->addWidget(lblDesc, 1);
   234     bottomLeftLayout->addWidget(lblDesc, 100);
   234 
   235 
   235     /* Add stretch above theme button */
   236     /* Add stretch above theme button */
   236 
   237 
   237     bottomLeftLayout->addStretch(1);
   238     bottomLeftLayout->addStretch(1);
   238 
   239 
   268     px.fill(Qt::yellow);
   269     px.fill(Qt::yellow);
   269     QBitmap bm = QBitmap::fromImage(newImage);
   270     QBitmap bm = QBitmap::fromImage(newImage);
   270     px.setMask(bm);
   271     px.setMask(bm);
   271 
   272 
   272     p.fillRect(pxres.rect(), linearGrad);
   273     p.fillRect(pxres.rect(), linearGrad);
   273     p.drawPixmap(QPoint(0, 0), px);
   274     p.drawPixmap(0, 0, px);
   274 
   275 
   275     addInfoToPreview(pxres);
   276     addInfoToPreview(pxres);
   276     pMap = 0;
   277     pMap = 0;
   277 
   278 
   278     cType->setEnabled(isMaster());
   279     cType->setEnabled(isMaster());
   298     p.setFont(QFont("MS Shell Dlg", 10));
   299     p.setFont(QFont("MS Shell Dlg", 10));
   299     QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?";
   300     QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?";
   300     p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text);
   301     p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text);
   301     p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall);
   302     p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall);
   302 
   303 
   303     mapPreview->setPixmap(finalImage);
   304     // Shrink, crop, and center preview image
       
   305     QPixmap centered(QSize(m_previewSize.width() - 6, m_previewSize.height() - 6));
       
   306     QPainter pc(&centered);
       
   307     pc.fillRect(centered.rect(), linearGrad);
       
   308     pc.drawPixmap(-3, -3, finalImage);
       
   309 
       
   310     mapPreview->setIcon(QIcon(centered));
       
   311     mapPreview->setIconSize(centered.size());
   304 }
   312 }
   305 
   313 
   306 void HWMapContainer::askForGeneratedPreview()
   314 void HWMapContainer::askForGeneratedPreview()
   307 {
   315 {
   308     pMap = new HWMap(this);
   316     pMap = new HWMap(this);
   329     p.drawPixmap(QPoint(x, y), waitIcon);
   337     p.drawPixmap(QPoint(x, y), waitIcon);
   330 
   338 
   331     addInfoToPreview(waitImage);
   339     addInfoToPreview(waitImage);
   332 
   340 
   333     cType->setEnabled(false);
   341     cType->setEnabled(false);
       
   342 }
       
   343 
       
   344 void HWMapContainer::previewClicked()
       
   345 {
       
   346     switch (m_mapInfo.type)
       
   347     {
       
   348         case MapModel::HandDrawnMap:
       
   349             emit drawMapRequested();
       
   350             break;
       
   351         default:
       
   352             setRandomMap();
       
   353             break;
       
   354     }
   334 }
   355 }
   335 
   356 
   336 QString HWMapContainer::getCurrentSeed() const
   357 QString HWMapContainer::getCurrentSeed() const
   337 {
   358 {
   338     return m_seed;
   359     return m_seed;
   592 
   613 
   593     switch(m_mapInfo.type)
   614     switch(m_mapInfo.type)
   594     {
   615     {
   595         case MapModel::Invalid:
   616         case MapModel::Invalid:
   596             failIcon = QPixmap(":/res/btnDisabled.png");
   617             failIcon = QPixmap(":/res/btnDisabled.png");
   597             mapPreview->setPixmap(failIcon);
   618             mapPreview->setIcon(QIcon(failIcon));
       
   619             mapPreview->setIconSize(failIcon.size());
   598             break;
   620             break;
   599         case MapModel::GeneratedMap:
   621         case MapModel::GeneratedMap:
   600             askForGeneratedPreview();
   622             askForGeneratedPreview();
   601             break;
   623             break;
   602         case MapModel::GeneratedMaze:
   624         case MapModel::GeneratedMaze:
   609             QPixmap mapImage;
   631             QPixmap mapImage;
   610             bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png");
   632             bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png");
   611 
   633 
   612             if(!success)
   634             if(!success)
   613             {
   635             {
   614                 mapPreview->setPixmap(QPixmap());
   636                 mapPreview->setIcon(QIcon());
   615                 return;
   637                 return;
   616             }
   638             }
   617 
   639 
   618             hhLimit = m_mapInfo.limit;
   640             hhLimit = m_mapInfo.limit;
   619             addInfoToPreview(mapImage);
   641             addInfoToPreview(mapImage);
   727         {
   749         {
   728             cType->setCurrentIndex(i);
   750             cType->setCurrentIndex(i);
   729             break;
   751             break;
   730         }
   752         }
   731     }
   753     }
       
   754 
       
   755     repaint();
   732 
   756 
   733     emit mapgenChanged(mapgen);
   757     emit mapgenChanged(mapgen);
   734 }
   758 }
   735 
   759 
   736 void HWMapContainer::updateThemeButtonSize()
   760 void HWMapContainer::updateThemeButtonSize()
   885     return m_master;
   909     return m_master;
   886 }
   910 }
   887 
   911 
   888 void HWMapContainer::setMaster(bool master)
   912 void HWMapContainer::setMaster(bool master)
   889 {
   913 {
       
   914     if (master == m_master) return;
   890     m_master = master;
   915     m_master = master;
   891 
   916 
   892     foreach (QWidget *widget, m_childWidgets)
   917     foreach (QWidget *widget, m_childWidgets)
   893         widget->setEnabled(master);
   918         widget->setEnabled(master);
   894 }
   919 }