improved gameview resizing
This commit is contained in:
parent
0f272a2f51
commit
04a3d311be
2 changed files with 2 additions and 19 deletions
|
@ -10,25 +10,8 @@ GameView::GameView(QGraphicsScene *scene, QWidget *parent)
|
|||
// setViewportUpdateMode(FullViewportUpdate);
|
||||
}
|
||||
|
||||
void GameView::scaleToScene()
|
||||
{
|
||||
// This function ensures that the bounding rectangles of card pictures
|
||||
// have integer sizes. This is achieved by using a scale factor of n / 6.
|
||||
QRectF sr = scene()->sceneRect();
|
||||
QRectF vr = QRectF(viewport()->rect().adjusted(2, 2, -2, -2));
|
||||
qreal scale_h = vr.width() / sr.width();
|
||||
qreal scale_v = vr.height() / sr.height();
|
||||
qreal scale_total = qMin(scale_h, scale_v);
|
||||
|
||||
qreal scale_corr = (qreal) ((int) (scale_total * 6)) / 6;
|
||||
|
||||
qDebug(QString("scale_corr = %1 / 6").arg(scale_corr * 6).toLatin1());
|
||||
setTransform(QTransform().scale(scale_corr, scale_corr));
|
||||
}
|
||||
|
||||
void GameView::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
qDebug("GameView: resizeEvent");
|
||||
QGraphicsView::resizeEvent(event);
|
||||
scaleToScene();
|
||||
fitInView(scene()->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ void MainWindow::updateSceneSize()
|
|||
QSizeF zoneSize = zoneLayout->size();
|
||||
qDebug(QString("updateSceneSize: width=%1").arg(952 + zoneSize.width()).toLatin1());
|
||||
scene->setSceneRect(sr.x(), sr.y(), 952 + zoneSize.width(), sr.height());
|
||||
view->scaleToScene();
|
||||
view->fitInView(scene->sceneRect(), Qt::KeepAspectRatio);
|
||||
}
|
||||
|
||||
void MainWindow::textChanged(const QString &text)
|
||||
|
|
Loading…
Reference in a new issue