69 hhSmall.load(":/res/hh_small.png"); |
69 hhSmall.load(":/res/hh_small.png"); |
70 hhLimit = 18; |
70 hhLimit = 18; |
71 templateFilter = 0; |
71 templateFilter = 0; |
72 m_master = true; |
72 m_master = true; |
73 |
73 |
74 linearGrad = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); |
74 linearGradNormal = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); |
75 linearGrad.setColorAt(1, QColor(0, 0, 192)); |
75 linearGradNormal.setColorAt(1, QColor(0, 0, 192)); |
76 linearGrad.setColorAt(0, QColor(66, 115, 225)); |
76 linearGradNormal.setColorAt(0, QColor(66, 115, 225)); |
|
77 |
|
78 linearGradLoading = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); |
|
79 linearGradLoading.setColorAt(1, QColor(58, 58, 137)); |
|
80 linearGradLoading.setColorAt(0, QColor(90, 109, 153)); |
|
81 |
|
82 linearGradMapError = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); |
|
83 linearGradMapError.setColorAt(1, QColor(255, 1, 0)); |
|
84 linearGradMapError.setColorAt(0, QColor(255, 119, 0)); |
|
85 |
|
86 linearGradNoPreview = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); |
|
87 linearGradNoPreview.setColorAt(1, QColor(15, 9, 72)); |
|
88 linearGradNoPreview.setColorAt(0, QColor(15, 9, 72)); |
77 |
89 |
78 mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
90 mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), |
79 10, |
91 10, |
80 HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
92 HWApplication::style()->pixelMetric(QStyle::PM_LayoutRightMargin), |
81 HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
93 HWApplication::style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); |
331 pMap = 0; |
343 pMap = 0; |
332 |
344 |
333 cType->setEnabled(isMaster()); |
345 cType->setEnabled(isMaster()); |
334 } |
346 } |
335 |
347 |
336 void HWMapContainer::setImage(const QPixmap &newImage, bool showHHLimit) |
348 void HWMapContainer::setImage(const QPixmap &newImage, const QLinearGradient &linearGrad, bool showHHLimit) |
337 { |
349 { |
338 if (showHHLimit) |
350 addInfoToPreview(newImage, linearGrad, showHHLimit); |
339 { |
|
340 addInfoToPreview(newImage); |
|
341 } |
|
342 else |
|
343 { |
|
344 QIcon mapPreviewIcon = QIcon(); |
|
345 mapPreviewIcon.addPixmap(newImage, QIcon::Normal); |
|
346 mapPreviewIcon.addPixmap(newImage, QIcon::Disabled); |
|
347 mapPreview->setIcon(mapPreviewIcon); |
|
348 mapPreview->setIconSize(newImage.size()); |
|
349 } |
|
350 |
351 |
351 pMap = 0; |
352 pMap = 0; |
352 |
353 |
353 cType->setEnabled(isMaster()); |
354 cType->setEnabled(isMaster()); |
354 } |
355 } |
357 void HWMapContainer::setHHLimit(int newHHLimit) |
358 void HWMapContainer::setHHLimit(int newHHLimit) |
358 { |
359 { |
359 hhLimit = newHHLimit; |
360 hhLimit = newHHLimit; |
360 } |
361 } |
361 |
362 |
|
363 void HWMapContainer::addInfoToPreview(const QPixmap &image) |
|
364 { |
|
365 addInfoToPreview(image, linearGradNormal, true); |
|
366 } |
|
367 |
362 // Should this add text to identify map size? |
368 // Should this add text to identify map size? |
363 void HWMapContainer::addInfoToPreview(const QPixmap &image) |
369 void HWMapContainer::addInfoToPreview(const QPixmap &image, const QLinearGradient &linearGrad, bool drawHHLimit) |
364 { |
370 { |
365 QPixmap finalImage = QPixmap(image.size()); |
371 QPixmap finalImage = QPixmap(image.size()); |
366 //finalImage.fill(QColor(0, 0, 0, 0)); |
|
367 |
|
368 QPainter p(&finalImage); |
372 QPainter p(&finalImage); |
|
373 |
369 p.fillRect(finalImage.rect(), linearGrad); |
374 p.fillRect(finalImage.rect(), linearGrad); |
370 p.drawPixmap(finalImage.rect(), image); |
375 p.drawPixmap(finalImage.rect(), image); |
371 //p.setPen(QColor(0xf4,0x9e,0xe9)); |
376 |
372 p.setPen(QColor(0xff,0xcc,0x00)); |
377 if (drawHHLimit) |
373 p.setBrush(QColor(0, 0, 0)); |
378 { |
374 p.drawRect(finalImage.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); |
379 p.setPen(QColor(0xff,0xcc,0x00)); |
375 p.setFont(QFont("MS Shell Dlg", 10)); |
380 p.setBrush(QColor(0, 0, 0)); |
376 QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?"; |
381 p.setFont(QFont("MS Shell Dlg", 10)); |
377 p.drawText(finalImage.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text); |
382 |
378 p.drawPixmap(finalImage.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); |
383 p.drawRect(finalImage.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); |
379 |
384 |
380 // Shrink, crop, and center preview image |
385 QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?"; |
381 /*QPixmap centered(QSize(m_previewSize.width() - 6, m_previewSize.height() - 6)); |
386 p.drawText(finalImage.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text); |
382 QPainter pc(¢ered); |
387 p.drawPixmap(finalImage.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); |
383 pc.fillRect(centered.rect(), linearGrad); |
388 } |
384 pc.drawPixmap(-3, -3, finalImage);*/ |
|
385 |
389 |
386 // Set the map preview image. Make sure it is always colored the same, |
390 // Set the map preview image. Make sure it is always colored the same, |
387 // no matter if disabled or not. |
391 // no matter if disabled or not. |
388 QIcon mapPreviewIcon = QIcon(); |
392 QIcon mapPreviewIcon = QIcon(); |
389 mapPreviewIcon.addPixmap(finalImage, QIcon::Normal); |
393 mapPreviewIcon.addPixmap(finalImage, QIcon::Normal); |
408 m_mapFeatureSize |
412 m_mapFeatureSize |
409 ); |
413 ); |
410 |
414 |
411 setHHLimit(0); |
415 setHHLimit(0); |
412 |
416 |
|
417 QPixmap waitImage(m_previewSize); |
|
418 waitImage.fill(Qt::transparent); |
|
419 |
|
420 QPainter p(&waitImage); |
413 const QPixmap waitIcon(":/res/iconTime.png"); |
421 const QPixmap waitIcon(":/res/iconTime.png"); |
414 |
|
415 QPixmap waitImage(m_previewSize); |
|
416 QPainter p(&waitImage); |
|
417 |
|
418 p.fillRect(waitImage.rect(), linearGrad); |
|
419 int x = (waitImage.width() - waitIcon.width()) / 2; |
422 int x = (waitImage.width() - waitIcon.width()) / 2; |
420 int y = (waitImage.height() - waitIcon.height()) / 2; |
423 int y = (waitImage.height() - waitIcon.height()) / 2; |
421 p.drawPixmap(QPoint(x, y), waitIcon); |
424 p.drawPixmap(QPoint(x, y), waitIcon); |
422 |
425 |
423 addInfoToPreview(waitImage); |
426 setImage(waitImage, linearGradLoading, false); |
424 |
427 |
425 cType->setEnabled(false); |
428 cType->setEnabled(false); |
426 } |
429 } |
427 |
430 |
428 void HWMapContainer::previewClicked() |
431 void HWMapContainer::previewClicked() |
797 switch(m_mapInfo.type) |
800 switch(m_mapInfo.type) |
798 { |
801 { |
799 case MapModel::Invalid: |
802 case MapModel::Invalid: |
800 // Map error image |
803 // Map error image |
801 failPixmap = QPixmap(":/res/missingMap.png"); |
804 failPixmap = QPixmap(":/res/missingMap.png"); |
802 setImage(failPixmap, false); |
805 setImage(failPixmap, linearGradMapError, false); |
803 lblDesc->clear(); |
806 lblDesc->clear(); |
804 break; |
807 break; |
805 case MapModel::GeneratedMap: |
808 case MapModel::GeneratedMap: |
806 case MapModel::GeneratedMaze: |
809 case MapModel::GeneratedMaze: |
807 case MapModel::GeneratedPerlin: |
810 case MapModel::GeneratedPerlin: |
813 // For maps loaded from image |
816 // For maps loaded from image |
814 if(m_missingMap) |
817 if(m_missingMap) |
815 { |
818 { |
816 // Map error image due to missing map |
819 // Map error image due to missing map |
817 failPixmap = QPixmap(":/res/missingMap.png"); |
820 failPixmap = QPixmap(":/res/missingMap.png"); |
818 setImage(failPixmap, false); |
821 setImage(failPixmap, linearGradMapError, false); |
819 lblDesc->clear(); |
822 lblDesc->clear(); |
820 break; |
823 break; |
821 } |
824 } |
822 else |
825 else |
823 { |
826 { |
824 // Draw map preview |
827 // Draw map preview |
825 QPixmap mapImage; |
828 QPixmap mapImage; |
826 bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png"); |
829 bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png"); |
827 |
830 |
|
831 setHHLimit(m_mapInfo.limit); |
828 if(!success) |
832 if(!success) |
829 { |
833 { |
830 // Missing preview image |
834 // Missing preview image |
831 setImage(QPixmap()); |
835 QPixmap empty = QPixmap(m_previewSize); |
|
836 empty.fill(Qt::transparent); |
|
837 setImage(empty, linearGradNoPreview, true); |
832 return; |
838 return; |
833 } |
839 } |
834 |
|
835 setHHLimit(m_mapInfo.limit); |
|
836 setImage(mapImage); |
840 setImage(mapImage); |
837 } |
841 } |
838 } |
842 } |
839 } |
843 } |
840 |
844 |