Fix map type combo box being disabled for good when you select image or mission map
authorWuzzy <Wuzzy2@mail.ru>
Mon, 19 Mar 2018 14:07:29 +0100
changeset 13258 dd054edd56df
parent 13257 5200231eb120
child 13259 1381ce67a781
Fix map type combo box being disabled for good when you select image or mission map
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/ui/widget/mapContainer.cpp	Mon Mar 19 13:35:13 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Mon Mar 19 14:07:29 2018 +0100
@@ -333,6 +333,27 @@
     cType->setEnabled(isMaster());
 }
 
+void HWMapContainer::setImage(const QPixmap &newImage, 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());
+    }
+
+    pMap = 0;
+
+    cType->setEnabled(isMaster());
+}
+
+
 void HWMapContainer::setHHLimit(int newHHLimit)
 {
     hhLimit = newHHLimit;
@@ -776,12 +797,9 @@
     switch(m_mapInfo.type)
     {
         case MapModel::Invalid:
+            // Map error image
             failPixmap = QPixmap(":/res/missingMap.png");
-            failIcon = QIcon();
-            failIcon.addPixmap(failPixmap, QIcon::Normal);
-            failIcon.addPixmap(failPixmap, QIcon::Disabled);
-            mapPreview->setIcon(failIcon);
-            mapPreview->setIconSize(failPixmap.size());
+            setImage(failPixmap, false);
             lblDesc->clear();
             break;
         case MapModel::GeneratedMap:
@@ -792,30 +810,30 @@
             askForGeneratedPreview();
             break;
         default:
+            // For maps loaded from image
             if(m_missingMap)
             {
+                // Map error image due to missing map
                 failPixmap = QPixmap(":/res/missingMap.png");
-                failIcon = QIcon();
-                failIcon.addPixmap(failPixmap, QIcon::Normal);
-                failIcon.addPixmap(failPixmap, QIcon::Disabled);
-                mapPreview->setIcon(failIcon);
-                mapPreview->setIconSize(failPixmap.size());
+                setImage(failPixmap, false);
                 lblDesc->clear();
                 break;
             }
             else
             {
+                // Draw map preview
                 QPixmap mapImage;
                 bool success = mapImage.load("physfs://Maps/" + m_mapInfo.name + "/preview.png");
 
                 if(!success)
                 {
-                    mapPreview->setIcon(QIcon());
+                    // Missing preview image
+                    setImage(QPixmap());
                     return;
                 }
 
-                hhLimit = m_mapInfo.limit;
-                addInfoToPreview(mapImage);
+                setHHLimit(m_mapInfo.limit);
+                setImage(mapImage);
             }
     }
 }
--- a/QTfrontend/ui/widget/mapContainer.h	Mon Mar 19 13:35:13 2018 +0100
+++ b/QTfrontend/ui/widget/mapContainer.h	Mon Mar 19 14:07:29 2018 +0100
@@ -177,6 +177,7 @@
         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 setMapInfo(MapModel::MapInfo mapInfo);
         void changeMapType(MapModel::MapType type, const QModelIndex & newMap = QModelIndex());
         void updateHelpTexts(MapModel::MapType type);