[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdegames/klines
From:       Dmitry Suzdalev <dimsuz () gmail ! com>
Date:       2007-05-31 12:05:59
Message-ID: 1180613159.033787.5340.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 670136 by dimsuz:

At last I found a way how to distinguish resizeEvent() that is
called when widget is shown from resizeEvent() called when widget
is hidden!
It really matters when you re-render complex svg on each resize and
when resizeEvent() comes from some Qt internal magic (layouting etc).
Why re-render if widget isn't visible and this resizeEvent() for sure
won't be last in sequence?

Now I know the True (tm)

Many thanks to aseigo & JohnFlux :-)

You just need to check what
QWidget::testAttribute( Qt::WA_PendingResizeEvent ) returns.

If this is false, then paint! :-)

One step further on the way to faster startup times.

Hmm... Or am I only one who just discovered this? ;-)


 M  +18 -2     mwidget.cpp  
 M  +1 -0      mwidget.h  
 M  +3 -19     scene.cpp  
 M  +0 -9      scene.h  


--- trunk/KDE/kdegames/klines/mwidget.cpp #670135:670136
@@ -4,7 +4,7 @@
     email                : roman@sbrf.barrt.ru
     copyright            : (C) 2000 by Roman Razilov
     email                : Roman.Razilov@gmx.de
-    copyright            : (C) 2006 by Dmitry Suzdalev
+    copyright            : (C) 2006-2007 by Dmitry Suzdalev
     email                : dimsuz@gmail.com
  ***************************************************************************/
 
@@ -21,8 +21,10 @@
 
 #include <KLocale>
 
+#include <QGraphicsView>
 #include <QLabel>
 #include <QLayout>
+#include <QResizeEvent>
 
 MainWidget::MainWidget( QWidget* parent )
     : QWidget( parent )
@@ -31,8 +33,12 @@
     mainLay->setMargin( 0 );
 
     m_scene = new KLinesScene(this);
-    KLinesView* klview = new KLinesView( m_scene, this );
+    QGraphicsView* klview = new QGraphicsView( m_scene, this );
     klview->setCacheMode( QGraphicsView::CacheBackground );
+    klview->setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+    klview->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
+    klview->setFrameStyle(QFrame::NoFrame);
+
     mainLay->addWidget( klview );
 }
 
@@ -47,4 +53,14 @@
     m_scene->setPreviewZoneVisible( visible );
 }
 
+void MainWidget::resizeEvent( QResizeEvent* ev)
+{
+    // if this flag is set it means that resizeEvent is called
+    // while widget is hidden.
+    // so we'll wait with resize until it will be unset to not
+    // waste time resizing invisible scene
+    if ( !testAttribute( Qt::WA_PendingResizeEvent ) )
+        m_scene->resizeScene( ev->size().width(), ev->size().height() );
+}
+
 #include "mwidget.moc"
--- trunk/KDE/kdegames/klines/mwidget.h #670135:670136
@@ -37,6 +37,7 @@
 public slots:
     void setShowNextColors(bool);
 private:
+    virtual void resizeEvent( QResizeEvent* );
     KLinesScene* m_scene;
     QLabel *m_next_label;
 };
--- trunk/KDE/kdegames/klines/scene.cpp #670135:670136
@@ -26,27 +26,11 @@
 #include "animator.h"
 #include "renderer.h"
 
-#include <QResizeEvent>
 #include <QGraphicsSceneMouseEvent>
+#include <QPainter>
 
-#include <kdebug.h>
+#include <KDebug>
 
-KLinesView::KLinesView( KLinesScene* scene, QWidget* parent )
-    : QGraphicsView(scene, parent)
-{
-    //setMinimumSize( defaultFieldSize, defaultFieldSize );
-    setVerticalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
-    setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
-    setFrameStyle(QFrame::NoFrame);
-}
-
-void KLinesView::resizeEvent( QResizeEvent* ev )
-{
-    static_cast<KLinesScene*>(scene())->resizeScene( ev->size().width(), ev->size().height() );
-}
-
-// =============== KLinesScene =======================
-
 KLinesScene::KLinesScene( QObject* parent )
     : QGraphicsScene(parent),
       m_playFieldOrigin(0, 0 ), m_numFreeCells(FIELD_SIZE*FIELD_SIZE),
@@ -616,7 +600,7 @@
     m_previewItem->setPreviewColors( m_nextColors );
 
     emit scoreChanged(m_score);
-    
+
     emit stateChanged("not_undoable");
 }
 
--- trunk/KDE/kdegames/klines/scene.h #670135:670136
@@ -24,7 +24,6 @@
 #define KL_SCENE_H
 
 #include <QGraphicsScene>
-#include <QGraphicsView>
 #include <KRandomSequence>
 
 #include "commondefs.h"
@@ -244,12 +243,4 @@
     UndoInfo m_undoInfo;
 };
 
-class KLinesView : public QGraphicsView
-{
-public:
-    KLinesView( KLinesScene* scene, QWidget *parent );
-private:
-    void resizeEvent(QResizeEvent *);
-};
-
 #endif
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic