Commit ed992344 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev
Browse files

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? ;-)

svn path=/trunk/KDE/kdegames/klines/; revision=670136
parent 5d103a58
......@@ -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 @@ MainWidget::MainWidget( QWidget* parent )
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 @@ void MainWidget::setShowNextColors(bool visible)
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"
......@@ -37,6 +37,7 @@ public:
public slots:
void setShowNextColors(bool);
private:
virtual void resizeEvent( QResizeEvent* );
KLinesScene* m_scene;
QLabel *m_next_label;
};
......
......@@ -26,26 +26,10 @@
#include "animator.h"
#include "renderer.h"
#include <QResizeEvent>
#include <QGraphicsSceneMouseEvent>
#include <QPainter>
#include <kdebug.h>
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 =======================
#include <KDebug>
KLinesScene::KLinesScene( QObject* parent )
: QGraphicsScene(parent),
......@@ -616,7 +600,7 @@ void KLinesScene::undo()
m_previewItem->setPreviewColors( m_nextColors );
emit scoreChanged(m_score);
emit stateChanged("not_undoable");
}
......
......@@ -24,7 +24,6 @@
#define KL_SCENE_H
#include <QGraphicsScene>
#include <QGraphicsView>
#include <KRandomSequence>
#include "commondefs.h"
......@@ -244,12 +243,4 @@ private:
UndoInfo m_undoInfo;
};
class KLinesView : public QGraphicsView
{
public:
KLinesView( KLinesScene* scene, QWidget *parent );
private:
void resizeEvent(QResizeEvent *);
};
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment