From b98db19af8246775502c74cd676b961b67f6a2c5 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Mon, 23 May 2016 12:22:57 +0200 Subject: may fix the unwanted window growth. --- src/server/mainwindow/mainwindow.cpp | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index e6efb1c..c834957 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -592,7 +592,7 @@ void MainWindow::resizeEvent(QResizeEvent* e) /* Bring back frame that are now out of the screen */ for (auto it = _clientFrames.begin(); it != _clientFrames.end(); ++it) { const QPoint gp = (*it)->getGridPosition(); - if ( gp.x() > _tilesX || gp.y() > _tilesY ) { + if ( gp.x() >= _tilesX || gp.y() >= _tilesY ) { qDebug() << "bring frame back"; placeFrameInFreeSlot(*it, (*it)->getCurrentPosition()); } @@ -609,6 +609,18 @@ void MainWindow::resizeEvent(QResizeEvent* e) (*it)->setSize(getTileWidthPx() * clientSize.width(), getTileHeightPx() * clientSize.height()); (*it)->move(newPos); } + + /* update background image label */ + if (_backgroundImage != NULL) { + int w = ui->frmRoom->width() - 5; /* to make sure that we don't enlarge the window */ + int h = ui->frmRoom->height() - 5; + ui->imageLabel->hide(); + ui->imageLabel->setScaledContents(true); + ui->imageLabel->setPixmap(QPixmap::fromImage(*_backgroundImage).scaled(w,h, Qt::IgnoreAspectRatio)); + ui->imageLabel->show(); + } else { + ui->imageLabel->clear(); + } } @@ -840,25 +852,25 @@ void MainWindow::switchRoomTo(QString roomToReload) { /* load background image */ QString imgPath = Global::getCurrentRoom()->imagePath; qDebug() << "imgPath is " << imgPath; - if (imgPath == "") { - /* set empty pixmap*/ - QPixmap empty; - ui->imageLabel->setPixmap(empty); - } else { + + /* delete old image */ + if (_backgroundImage != NULL) {delete _backgroundImage; } + _backgroundImage = NULL; + + if (imgPath != "") { qDebug() << "set background image path: " << imgPath; - QImage image; if (imgPath.endsWith("svg")) { /* render once with maximal screen size */ const QSize &s = QApplication::desktop()->screenGeometry().size(); // ui->frmRoom->geometry().size(); QSvgRenderer renderer(imgPath); - image = QImage(s, QImage::Format_ARGB32); - QPainter painter(&image); + _backgroundImage = new QImage(s, QImage::Format_ARGB32); + _backgroundImage->fill(Qt::lightGray); /* background color */ + QPainter painter(_backgroundImage); renderer.render(&painter); } else { - image.load(imgPath); + _backgroundImage = new QImage(); + _backgroundImage->load(imgPath); } - ui->imageLabel->setPixmap(QPixmap::fromImage(image)); - ui->imageLabel->setScaledContents(true); } /* and force a resize event (this scales the image) */ -- cgit v1.2.3-55-g7522