From c441b1ecf2a1da26bc314a31a161c29970dbbde3 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Fri, 29 Apr 2016 12:50:45 +0200 Subject: added background-image loading. --- src/server/mainwindow/mainwindow.cpp | 39 ++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 11 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index 48e9b18..9f667a6 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -368,6 +368,9 @@ void MainWindow::tryToUseRoomTemplate() } conf.endArray(); + /* read backgroundImage */ + QString image = conf.contains("backgroundImage") ? conf.value("backgroundImage").toString() : ""; + // Find the managerIP of current room. QString mgrIP = conf.value("mgrIP").toString(); @@ -420,8 +423,7 @@ void MainWindow::tryToUseRoomTemplate() qDebug() << "had to use minimalGridSize(): = " << gridSize; } - - Room* r = new Room(clientPositions, gridSize, clientSize); + Room* r = new Room(clientPositions, gridSize, clientSize, image); qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize; roomsList.insert(roomName, r); } @@ -564,6 +566,7 @@ void MainWindow::resizeEvent(QResizeEvent* e) (*it)->setSize(getTileWidthPx() * clientSize.width(), getTileHeightPx() * clientSize.height()); (*it)->move(newPos); } + } @@ -824,29 +827,43 @@ void MainWindow::onReloadRoomOk() Room *room = Global::getRooms()[roomToReload]; + /* set tiles */ _tilesX = room->gridSize.width(); _tilesY = room->gridSize.height(); - qDebug() << "changed room, grid size is now: " << _tilesX << ", " << _tilesY; - //qDebug() << " Room: " << room; - //qDebug() << "_rooms: " << _rooms; + + /* place connection frames */ for (QMap::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) { QString computerId = it.key(); QPoint pos = it.value(); - qDebug() << "ComputerID: " << computerId; - qDebug() << "Pos: " << pos; - - - // Transform to pixels for createFrame(computerId, position). + /* Transform to pixels for createFrame(computerId, position).*/ QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx()); ConnectionFrame *cf = createFrame(computerId, pxPos, pos); cf->move(cf->getCurrentPosition()); onPlaceFrame(false, cf); } - } + + /* load background image */ + QString imgPath = Global::getRooms()[Global::getCurrentRoom()]->imagePath; + if (imgPath == "") { + /* set empty pixmap*/ + QPixmap empty; + ui->imageLabel->setPixmap(empty); + } else { + qDebug() << "set background image path: " << imgPath; + QImage backgroundImage; + backgroundImage.load(imgPath); + ui->imageLabel->setPixmap(QPixmap::fromImage(backgroundImage)); + ui->imageLabel->setScaledContents(true); + } + + /* and force a resize event (this scales the image) */ + resizeEvent(NULL); + + } } int MainWindow::getTileWidthPx() const { -- cgit v1.2.3-55-g7522