don't generate any map previews until they are actually visible. this should improve hedgewars startup performance on weak machines
authorsheepluva
Mon, 02 Dec 2013 12:40:16 +0100
changeset 9735 6312152d92ad
parent 9734 da2cb993fd61
child 9736 d2b01d350035
don't generate any map previews until they are actually visible. this should improve hedgewars startup performance on weak machines
QTfrontend/ui/widget/mapContainer.cpp
QTfrontend/ui/widget/mapContainer.h
--- a/QTfrontend/ui/widget/mapContainer.cpp	Mon Dec 02 04:35:02 2013 +0200
+++ b/QTfrontend/ui/widget/mapContainer.cpp	Mon Dec 02 12:40:16 2013 +0100
@@ -55,6 +55,7 @@
     mapgen(MAPGEN_REGULAR),
     m_previewSize(256, 128)
 {
+    m_previewDirty = true;
     hhSmall.load(":/res/hh_small.png");
     hhLimit = 18;
     templateFilter = 0;
@@ -608,8 +609,25 @@
     updatePreview();
 }
 
+void HWMapContainer::paintEvent(QPaintEvent * event)
+{
+    if (m_previewDirty)
+        updatePreview();
+    QWidget::paintEvent(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;
+        return;
+    }
+
+    m_previewDirty = false;
+
     if (pMap)
     {
         disconnect(pMap, 0, this, SLOT(setImage(const QImage)));
--- a/QTfrontend/ui/widget/mapContainer.h	Mon Dec 02 04:35:02 2013 +0200
+++ b/QTfrontend/ui/widget/mapContainer.h	Mon Dec 02 12:40:16 2013 +0100
@@ -111,6 +111,7 @@
 
     protected:
         virtual void resizeEvent ( QResizeEvent * event );
+        virtual void paintEvent ( QPaintEvent * event );
 
     private:
         QVBoxLayout mainLayout;
@@ -149,6 +150,7 @@
         QPushButton * btnSeed;
         bool m_master;
         QList<QWidget *> m_childWidgets;
+        bool m_previewDirty;
 
         void intSetSeed(const QString & seed);
         void intSetMap(const QString & map);