make lazy loading of map preview a little bit less of a hack
authorsheepluva
Mon, 02 Dec 2013 20:25:15 +0100
changeset 9739 c2c9dd2544b8
parent 9738 18bb6d1fc9d9
child 9740 d159ddae0358
make lazy loading of map preview a little bit less of a hack
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/ui/widget/mapContainer.cpp	Mon Dec 02 23:20:07 2013 +0400
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Mon Dec 02 20:25:15 2013 +0100
@@ -55,7 +55,9 @@
     mapgen(MAPGEN_REGULAR),
     m_previewSize(256, 128)
 {
-    m_previewDirty = true;
+    // don't show preview anything until first show event
+    m_previewEnabled = false;
+
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
     templateFilter = 0;
@@ -609,24 +611,20 @@
     updatePreview();
 }
 
-void HWMapContainer::paintEvent(QPaintEvent * event)
+void HWMapContainer::showEvent(QShowEvent * event)
 {
-    if (m_previewDirty)
+    if (!m_previewEnabled) {
+        m_previewEnabled = true;
         updatePreview();
-    QWidget::paintEvent(event);
+    }
+    QWidget::showEvent(event);
 }
 
 void HWMapContainer::updatePreview()
 {
-    // don't update preview if e.g. widget not being displayed
-    if (this->visibleRegion().isEmpty())
-    {
-        // but remember to update it later
-        m_previewDirty = true;
+    // abort if the widget isn't supposed to show anything yet
+    if (!m_previewEnabled)
         return;
-    }
-
-    m_previewDirty = false;
 
     if (pMap)
     {
--- a/QTfrontend/ui/widget/mapContainer.h	Mon Dec 02 23:20:07 2013 +0400
+++ b/QTfrontend/ui/widget/mapContainer.h	Mon Dec 02 20:25:15 2013 +0100
@@ -111,7 +111,7 @@
 
     protected:
         virtual void resizeEvent ( QResizeEvent * event );
-        virtual void paintEvent ( QPaintEvent * event );
+        virtual void showEvent ( QShowEvent * event );
 
     private:
         QVBoxLayout mainLayout;
@@ -150,7 +150,7 @@
         QPushButton * btnSeed;
         bool m_master;
         QList<QWidget *> m_childWidgets;
-        bool m_previewDirty;
+        bool m_previewEnabled;
 
         void intSetSeed(const QString & seed);
         void intSetMap(const QString & map);