QTfrontend/ui/widget/mapContainer.cpp
changeset 7017 19a434fc91fc
parent 7014 c0b32404ef74
child 7018 6a1f46c026bf
equal deleted inserted replaced
7016:8b34f46e10c1 7017:19a434fc91fc
    39 
    39 
    40 HWMapContainer::HWMapContainer(QWidget * parent) :
    40 HWMapContainer::HWMapContainer(QWidget * parent) :
    41     QWidget(parent),
    41     QWidget(parent),
    42     mainLayout(this),
    42     mainLayout(this),
    43     pMap(0),
    43     pMap(0),
    44     mapgen(MAPGEN_REGULAR)
    44     mapgen(MAPGEN_REGULAR),
       
    45     m_previewSize(256, 128)
    45 {
    46 {
    46     hhSmall.load(":/res/hh_small.png");
    47     hhSmall.load(":/res/hh_small.png");
    47     hhLimit = 18;
    48     hhLimit = 18;
    48     templateFilter = 0;
    49     templateFilter = 0;
       
    50 
       
    51     linearGrad = QLinearGradient(QPoint(128, 0), QPoint(128, 128));
       
    52     linearGrad.setColorAt(1, QColor(0, 0, 192));
       
    53     linearGrad.setColorAt(0, QColor(66, 115, 225));
    49 
    54 
    50     mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    55     mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin),
    51                                   1,
    56                                   1,
    52                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    57                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin),
    53                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
    58                                   HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin));
   183     updateModelViews();
   188     updateModelViews();
   184 }
   189 }
   185 
   190 
   186 void HWMapContainer::setImage(const QImage newImage)
   191 void HWMapContainer::setImage(const QImage newImage)
   187 {
   192 {
   188     QPixmap px(256, 128);
   193     QPixmap px(m_previewSize);
   189     QPixmap pxres(256, 128);
   194     QPixmap pxres(px.size());
   190     QPainter p(&pxres);
   195     QPainter p(&pxres);
   191 
   196 
   192     px.fill(Qt::yellow);
   197     px.fill(Qt::yellow);
   193     QBitmap bm = QBitmap::fromImage(newImage);
   198     QBitmap bm = QBitmap::fromImage(newImage);
   194     px.setMask(bm);
   199     px.setMask(bm);
   195 
   200 
   196     QLinearGradient linearGrad(QPoint(128, 0), QPoint(128, 128));
   201     p.fillRect(pxres.rect(), linearGrad);
   197     linearGrad.setColorAt(1, QColor(0, 0, 192));
       
   198     linearGrad.setColorAt(0, QColor(66, 115, 225));
       
   199     p.fillRect(QRect(0, 0, 256, 128), linearGrad);
       
   200     p.drawPixmap(QPoint(0, 0), px);
   202     p.drawPixmap(QPoint(0, 0), px);
   201 
   203 
   202     addInfoToPreview(pxres);
   204     addInfoToPreview(pxres);
   203     //chooseMap->setCurrentIndex(mapgen);
   205     //chooseMap->setCurrentIndex(mapgen);
   204     pMap = 0;
   206     pMap = 0;
   279     //p.setPen(QColor(0xf4,0x9e,0xe9));
   281     //p.setPen(QColor(0xf4,0x9e,0xe9));
   280     p.setPen(QColor(0xff,0xcc,0x00));
   282     p.setPen(QColor(0xff,0xcc,0x00));
   281     p.setBrush(QColor(0, 0, 0));
   283     p.setBrush(QColor(0, 0, 0));
   282     p.drawRect(image.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20);
   284     p.drawRect(image.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20);
   283     p.setFont(QFont("MS Shell Dlg", 10));
   285     p.setFont(QFont("MS Shell Dlg", 10));
   284     p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, QString::number(hhLimit));
   286     QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?";
       
   287     p.drawText(image.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text);
   285     p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall);
   288     p.drawPixmap(image.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall);
   286 
   289 
   287     imageButt->setIcon(finalImage);
   290     imageButt->setIcon(finalImage);
   288     imageButt->setIconSize(image.size());
   291     imageButt->setIconSize(image.size());
   289 }
   292 }
   305                    getTemplateFilter(),
   308                    getTemplateFilter(),
   306                    get_mapgen(),
   309                    get_mapgen(),
   307                    getMazeSize(),
   310                    getMazeSize(),
   308                    getDrawnMapData()
   311                    getDrawnMapData()
   309                   );
   312                   );
       
   313 
       
   314     setHHLimit(0);
       
   315 
       
   316     const QPixmap waitIcon(":/res/iconTime.png");
       
   317 
       
   318     QPixmap waitImage(m_previewSize);
       
   319     QPainter p(&waitImage);
       
   320 
       
   321     p.fillRect(waitImage.rect(), linearGrad);
       
   322     int x = (waitImage.width() - waitIcon.width()) / 2;
       
   323     int y = (waitImage.height() - waitIcon.height()) / 2;
       
   324     p.drawPixmap(QPoint(x, y), waitIcon);
       
   325 
       
   326     addInfoToPreview(waitImage);
   310 }
   327 }
   311 
   328 
   312 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &)
   329 void HWMapContainer::themeSelected(const QModelIndex & current, const QModelIndex &)
   313 {
   330 {
   314     m_theme = current.data().toString();
   331     m_theme = current.data().toString();