Commit 1bebafe0 authored by Dmitry Suzdalev's avatar Dmitry Suzdalev

Finally figured out how to set fixed size correctly

Thanks to pinotree!

svn path=/branches/work/kreversi_rewrite/; revision=571853
parent d16f0617
......@@ -10,7 +10,7 @@ set(kreversi_SRCS
kreversigame.cpp
kreversiscene.cpp
kreversiview.cpp
Engine.cpp
#Engine.cpp
mainwindow.cpp
main.cpp )
......
......@@ -11,17 +11,28 @@ const int CHIP_SIZE = 32;
KReversiView::KReversiView( QGraphicsScene* scene, QWidget *parent )
: QGraphicsView(scene, parent)
{
setRenderHints(QPainter::Antialiasing );
scene->setSceneRect( 0, 0, CHIP_SIZE*BOARD_SIZE, CHIP_SIZE*BOARD_SIZE );
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
// FIXME dimsuz: let it be so at the beginning
}
void KReversiView::showEvent(QShowEvent*)
{
// NOTE. it seems that QGV initializes it's margin only when
// it has been shown. So we need to setSize here
// Rude. It would be much better to calc the sizes in constructor.
setFixedSize(sizeHint());
}
QSize KReversiView::sizeHint() const
{
kDebug() << "sceneRect:" << sceneRect() << endl;
QRect r = mapFromScene(sceneRect()).boundingRect();
kDebug() << "viewRect:" << r << endl;
return QSize(r.size());
// QGraphicsView creates a 4px (as by time of writing)
// margin around the scene // and it's no way not to
// hardcode it here, rather then this:
// we map scene's (0,0) to view coord-system and then use
// (for example) x coordinate of resulting point.
// That'll be the margin
int margin = mapFromScene( 0, 0 ).x();
return QSize(scene()->width()+(margin*2), scene()->height()+margin*2);
}
......@@ -9,5 +9,6 @@ public:
KReversiView( QGraphicsScene* scene, QWidget *parent );
private:
virtual QSize sizeHint() const;
virtual void showEvent(QShowEvent*);
};
#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