# HG changeset patch # User Wuzzy # Date 1521469271 -3600 # Node ID 1381ce67a781bdb9687a365a0185fc10a1546337 # Parent dd054edd56df229d90f48abb8b9ca48a66a5e4e2 Tweak map preview background colors diff -r dd054edd56df -r 1381ce67a781 QTfrontend/res/missingMap.png Binary file QTfrontend/res/missingMap.png has changed diff -r dd054edd56df -r 1381ce67a781 QTfrontend/ui/widget/mapContainer.cpp --- a/QTfrontend/ui/widget/mapContainer.cpp Mon Mar 19 14:07:29 2018 +0100 +++ b/QTfrontend/ui/widget/mapContainer.cpp Mon Mar 19 15:21:11 2018 +0100 @@ -71,9 +71,21 @@ templateFilter = 0; m_master = true; - linearGrad = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); - linearGrad.setColorAt(1, QColor(0, 0, 192)); - linearGrad.setColorAt(0, QColor(66, 115, 225)); + linearGradNormal = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); + linearGradNormal.setColorAt(1, QColor(0, 0, 192)); + linearGradNormal.setColorAt(0, QColor(66, 115, 225)); + + linearGradLoading = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); + linearGradLoading.setColorAt(1, QColor(58, 58, 137)); + linearGradLoading.setColorAt(0, QColor(90, 109, 153)); + + linearGradMapError = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); + linearGradMapError.setColorAt(1, QColor(255, 1, 0)); + linearGradMapError.setColorAt(0, QColor(255, 119, 0)); + + linearGradNoPreview = QLinearGradient(QPoint(128, 0), QPoint(128, 128)); + linearGradNoPreview.setColorAt(1, QColor(15, 9, 72)); + linearGradNoPreview.setColorAt(0, QColor(15, 9, 72)); mainLayout.setContentsMargins(HWApplication::style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 10, @@ -333,20 +345,9 @@ cType->setEnabled(isMaster()); } -void HWMapContainer::setImage(const QPixmap &newImage, bool showHHLimit) +void HWMapContainer::setImage(const QPixmap &newImage, const QLinearGradient &linearGrad, bool showHHLimit) { - if (showHHLimit) - { - addInfoToPreview(newImage); - } - else - { - QIcon mapPreviewIcon = QIcon(); - mapPreviewIcon.addPixmap(newImage, QIcon::Normal); - mapPreviewIcon.addPixmap(newImage, QIcon::Disabled); - mapPreview->setIcon(mapPreviewIcon); - mapPreview->setIconSize(newImage.size()); - } + addInfoToPreview(newImage, linearGrad, showHHLimit); pMap = 0; @@ -359,29 +360,32 @@ hhLimit = newHHLimit; } +void HWMapContainer::addInfoToPreview(const QPixmap &image) +{ + addInfoToPreview(image, linearGradNormal, true); +} + // Should this add text to identify map size? -void HWMapContainer::addInfoToPreview(const QPixmap &image) +void HWMapContainer::addInfoToPreview(const QPixmap &image, const QLinearGradient &linearGrad, bool drawHHLimit) { QPixmap finalImage = QPixmap(image.size()); -//finalImage.fill(QColor(0, 0, 0, 0)); + QPainter p(&finalImage); - QPainter p(&finalImage); p.fillRect(finalImage.rect(), linearGrad); p.drawPixmap(finalImage.rect(), image); - //p.setPen(QColor(0xf4,0x9e,0xe9)); - p.setPen(QColor(0xff,0xcc,0x00)); - p.setBrush(QColor(0, 0, 0)); - p.drawRect(finalImage.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); - p.setFont(QFont("MS Shell Dlg", 10)); - QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?"; - p.drawText(finalImage.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text); - p.drawPixmap(finalImage.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); + + if (drawHHLimit) + { + p.setPen(QColor(0xff,0xcc,0x00)); + p.setBrush(QColor(0, 0, 0)); + p.setFont(QFont("MS Shell Dlg", 10)); - // Shrink, crop, and center preview image - /*QPixmap centered(QSize(m_previewSize.width() - 6, m_previewSize.height() - 6)); - QPainter pc(¢ered); - pc.fillRect(centered.rect(), linearGrad); - pc.drawPixmap(-3, -3, finalImage);*/ + p.drawRect(finalImage.rect().width() - hhSmall.rect().width() - 28, 3, 40, 20); + + QString text = (hhLimit > 0) ? QString::number(hhLimit) : "?"; + p.drawText(finalImage.rect().width() - hhSmall.rect().width() - 14 - (hhLimit > 9 ? 10 : 0), 18, text); + p.drawPixmap(finalImage.rect().width() - hhSmall.rect().width() - 5, 5, hhSmall.rect().width(), hhSmall.rect().height(), hhSmall); + } // Set the map preview image. Make sure it is always colored the same, // no matter if disabled or not. @@ -410,17 +414,16 @@ setHHLimit(0); - const QPixmap waitIcon(":/res/iconTime.png"); + QPixmap waitImage(m_previewSize); + waitImage.fill(Qt::transparent); - QPixmap waitImage(m_previewSize); QPainter p(&waitImage); - - p.fillRect(waitImage.rect(), linearGrad); + const QPixmap waitIcon(":/res/iconTime.png"); int x = (waitImage.width() - waitIcon.width()) / 2; int y = (waitImage.height() - waitIcon.height()) / 2; p.drawPixmap(QPoint(x, y), waitIcon); - addInfoToPreview(waitImage); + setImage(waitImage, linearGradLoading, false); cType->setEnabled(false); } @@ -799,7 +802,7 @@ case MapModel::Invalid: // Map error image failPixmap = QPixmap(":/res/missingMap.png"); - setImage(failPixmap, false); + setImage(failPixmap, linearGradMapError, false); lblDesc->clear(); break; case MapModel::GeneratedMap: @@ -815,7 +818,7 @@ { // Map error image due to missing map failPixmap = QPixmap(":/res/missingMap.png"); - setImage(failPixmap, false); + setImage(failPixmap, linearGradMapError, false); lblDesc->clear(); break; } @@ -825,14 +828,15 @@ QPixmap mapImage; bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png"); + setHHLimit(m_mapInfo.limit); if(!success) { // Missing preview image - setImage(QPixmap()); + QPixmap empty = QPixmap(m_previewSize); + empty.fill(Qt::transparent); + setImage(empty, linearGradNoPreview, true); return; } - - setHHLimit(m_mapInfo.limit); setImage(mapImage); } } diff -r dd054edd56df -r 1381ce67a781 QTfrontend/ui/widget/mapContainer.h --- a/QTfrontend/ui/widget/mapContainer.h Mon Mar 19 14:07:29 2018 +0100 +++ b/QTfrontend/ui/widget/mapContainer.h Mon Mar 19 15:21:11 2018 +0100 @@ -105,7 +105,6 @@ void setRandomSeed(); void setRandomTheme(); void setRandomMap(); - void addInfoToPreview(const QPixmap & image); void setNewSeed(const QString & newSeed); void mapTypeChanged(int); void showThemePrompt(); @@ -177,7 +176,9 @@ void intSetFeatureSize(int size); void setMissingTheme(const QString & name); void mapChanged(const QModelIndex & map, int type, const QModelIndex & old = QModelIndex()); - void setImage(const QPixmap & newImage, bool showHHLimit); + void setImage(const QPixmap & newImage, const QLinearGradient & linearGrad, bool showHHLimit); + void addInfoToPreview(const QPixmap & image); + void addInfoToPreview(const QPixmap & image, const QLinearGradient & linearGrad, bool drawHHLimit); void setMapInfo(MapModel::MapInfo mapInfo); void changeMapType(MapModel::MapType type, const QModelIndex & newMap = QModelIndex()); void updateHelpTexts(MapModel::MapType type); @@ -194,7 +195,10 @@ QString m_theme; QString m_curMap; - QLinearGradient linearGrad; ///< for preview background + QLinearGradient linearGradNormal; ///< for preview background + QLinearGradient linearGradLoading; ///< for preview background while loading/generating map + QLinearGradient linearGradNoPreview; ///< for preview background when map preview image is missing + QLinearGradient linearGradMapError; ///< for preview background when map is missing QSize m_previewSize; };