summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-04-27 14:11:58 +0200
committerChristian Klinger2016-04-27 14:11:58 +0200
commite1ccb202f8ca1efe3070735118b6c1cfa93c8c1b (patch)
tree45390674bdb63b1e1f98cc672ca5ab06d8d14d2f /src/server/mainwindow/mainwindow.cpp
parentrefactor to use Room struct (diff)
downloadpvs2-e1ccb202f8ca1efe3070735118b6c1cfa93c8c1b.tar.gz
pvs2-e1ccb202f8ca1efe3070735118b6c1cfa93c8c1b.tar.xz
pvs2-e1ccb202f8ca1efe3070735118b6c1cfa93c8c1b.zip
read gridSize&clientSize from config.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp60
1 files changed, 32 insertions, 28 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index 4963ccc..966356a 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -300,6 +300,25 @@ void MainWindow::tellClientCurrentSituation(Client* client)
}
+/**
+ * returns the minimal grid size such that all clients fit on the grid
+ **/
+QSize minimalGridSize(const QMap<QString, QPoint>& clientPositions, QSize& clientSize) {
+ /* collect the maximum coordinates */
+ int x = 0;
+ int y= 0;
+
+ for (auto it = clientPositions.begin(); it != clientPositions.end(); ++it) {
+ QPoint pos = it.value();
+ if (pos.x() > x) { x = pos.x(); }
+ if (pos.y() > y) { y = pos.y(); }
+
+ }
+ /* need a little extra space */
+ QSize size(x + clientSize.width(), y + clientSize.height());
+ return size;
+}
+
/***************************************************************************//**
* @brief MainWindow::tryToUseRoomTemplate
*/
@@ -314,7 +333,6 @@ void MainWindow::tryToUseRoomTemplate()
for (QString roomName : rooms)
{
- qDebug() << "i: " << roomName;
conf.beginGroup(roomName);
if (!conf.contains("mgrIP")) {
qDebug() << "Invalid config file!";
@@ -339,14 +357,11 @@ void MainWindow::tryToUseRoomTemplate()
/* read some other properties of the room */
if (conf.contains("gridSize")) {
gridSize = conf.value("gridSize").toSize();
- qDebug() << "read gridSize: " << gridSize ;
}
if (conf.contains("clientSize")) {
clientSize = conf.value("clientSize").toSize();
- qDebug() << "read clientSize: " << clientSize;
}
-
foreach (const QHostAddress &address, QNetworkInterface::allAddresses())
{
if (address != QHostAddress(QHostAddress::LocalHost) && mgrIP == address.toString())
@@ -368,11 +383,6 @@ void MainWindow::tryToUseRoomTemplate()
// Position is given in grid coordinates, createFrame take pixels
QString computerId = conf.value("ip").toString();
QPoint gridPosition = conf.value("pos").toPoint();
- qDebug() << computerId;
- qDebug() << gridPosition;
- qDebug() << getTileWidthPx() ;
- qDebug() << getTileHeightPx() ;
-
QPoint pxCoord(gridPosition.x() * getTileWidthPx(), gridPosition.y() * getTileHeightPx());
@@ -385,7 +395,15 @@ void MainWindow::tryToUseRoomTemplate()
}
conf.endGroup();
+ if (!gridSize.isValid()) {
+ /* ok, let's choose the minimum gridSize to fit all clients */
+ gridSize = minimalGridSize(clientPositions, clientSize);
+ qDebug() << "had to use minimalGridSize(): = " << gridSize;
+
+ }
+
Room* r = new Room(clientPositions, gridSize, clientSize);
+ qDebug() << "read new room: " << roomName << ": " << gridSize << ", " << clientSize;
roomsList.insert(roomName, r);
}
Global::setRooms(roomsList);
@@ -761,26 +779,12 @@ void MainWindow::onReloadRoomOk()
Room *room = Global::getRooms()[roomToReload];
- bool gridSizeSet = false; /* TODO: read grid size from config */
- if (!gridSizeSet) {
- /* collect the maximum coordinates */
- _tilesX = 0;
- _tilesY = 0;
-
- for (QMap<QString, QPoint>::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it) {
- QPoint pos = it.value();
- if (pos.x() > _tilesX) { _tilesX = pos.x(); }
- if (pos.y() > _tilesY) { _tilesY = pos.y(); }
-
- }
- /* need a little extra space */
- _tilesX += 1;
- _tilesY += 1;
+ _tilesX = room->gridSize.width();
+ _tilesY = room->gridSize.height();
- }
- qDebug() << "New Grid Size: " << _tilesX << ", " << _tilesY << endl;
- // qDebug() << " Room: " << room;
- // qDebug() << "_rooms: " << _rooms;
+ qDebug() << "changed room, grid size is now: " << _tilesX << ", " << _tilesY;
+ //qDebug() << " Room: " << room;
+ //qDebug() << "_rooms: " << _rooms;
for (QMap<QString, QPoint>::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it)
{
QString computerId = it.key();