summaryrefslogtreecommitdiffstats
path: root/src/server/mainwindow/mainwindow.cpp
diff options
context:
space:
mode:
authorChristian Klinger2016-04-27 12:24:37 +0200
committerChristian Klinger2016-04-27 12:24:37 +0200
commitf193e6f2e2385a9e240db18d2fda07aae42e1d2a (patch)
tree6273c5979fdb434b66d12d49df51830f7bbbef6d /src/server/mainwindow/mainwindow.cpp
parentbasic resizing works. (diff)
downloadpvs2-f193e6f2e2385a9e240db18d2fda07aae42e1d2a.tar.gz
pvs2-f193e6f2e2385a9e240db18d2fda07aae42e1d2a.tar.xz
pvs2-f193e6f2e2385a9e240db18d2fda07aae42e1d2a.zip
refactor to use Room struct
to save additional properties like gridSize and clientSize.
Diffstat (limited to 'src/server/mainwindow/mainwindow.cpp')
-rw-r--r--src/server/mainwindow/mainwindow.cpp78
1 files changed, 43 insertions, 35 deletions
diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp
index a60d1a7..4963ccc 100644
--- a/src/server/mainwindow/mainwindow.cpp
+++ b/src/server/mainwindow/mainwindow.cpp
@@ -59,7 +59,7 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
_mode = Mode::Multicast;
_streamingSource = 0;
- /* stupid default, just for testing */
+ /* default value, these should be updated on loading a room */
_tilesX = 20;
_tilesY = 20;
@@ -142,11 +142,6 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) :
this->onSessionNameUpdate(); // Just make lable visible.
_countSessionNameUpdate = 0;
- /* better calculate on demand */
-// _tileWidth = ui->frmRoom->size().width() / _tilesX;
-// _tileHeight = ui->frmRoom->size().height() / _tilesY;
-
-
tryToUseRoomTemplate();
}
@@ -310,42 +305,54 @@ void MainWindow::tellClientCurrentSituation(Client* client)
*/
void MainWindow::tryToUseRoomTemplate()
{
- QMap<QString, QMap<QString, QPoint> > roomsList;
+ QMap<QString, Room* > roomsList;
SYSTEM_SETTINGS(conf);
- if (!conf.contains("rooms")) {
- qDebug() << "Invalid config file!";
- return;
- }
+ if (!conf.contains("rooms")) { qDebug() << "Invalid config file!"; return; }
QStringList rooms = conf.value("rooms").toStringList();
qDebug() << rooms;
- for (auto i : rooms)
+ for (QString roomName : rooms)
{
- qDebug() << "i: " << i;
- conf.beginGroup(i);
+ qDebug() << "i: " << roomName;
+ conf.beginGroup(roomName);
if (!conf.contains("mgrIP")) {
qDebug() << "Invalid config file!";
return;
}
-
+ QMap<QString, QPoint> clientPositions;
// First store all room configurations in _rooms.
int size = conf.beginReadArray("client");
for (int j = 0; j < size; j++) {
conf.setArrayIndex(j);
// qDebug() << "ip: " << conf.value("ip").toString() << " pos: " << conf.value("pos").toPoint();
- roomsList[i].insert(conf.value("ip").toString(), conf.value("pos").toPoint());
+ // roomsList[i].insert(conf.value("ip").toString(), conf.value("pos").toPoint());
+ clientPositions.insert(conf.value("ip").toString(), conf.value("pos").toPoint());
}
conf.endArray();
// Find the managerIP of current room.
QString mgrIP = conf.value("mgrIP").toString();
+
+ QSize gridSize;
+ QSize clientSize(1,1);
+ /* 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())
{
qDebug("Found this ip in config.");
- Global::setCurrentRoom(i);
+ Global::setCurrentRoom(roomName);
int size = conf.beginReadArray("client");
for (int j = 0; j < size; ++j) {
conf.setArrayIndex(j);
@@ -377,6 +384,9 @@ void MainWindow::tryToUseRoomTemplate()
}
}
conf.endGroup();
+
+ Room* r = new Room(clientPositions, gridSize, clientSize);
+ roomsList.insert(roomName, r);
}
Global::setRooms(roomsList);
}
@@ -472,16 +482,12 @@ void MainWindow::resizeEvent(QResizeEvent* e)
const int nh = ui->frmRoom->size().height() / _tilesY;
for (QList<ConnectionFrame*>::iterator it = _clientFrames.begin(); it != _clientFrames.end(); ++it)
{
- const QPoint &oldpos = (*it)->frameGeometry().topLeft();
int newPosX = (*it)->getGridPosition().x() * getTileWidthPx();
int newPosY = (*it)->getGridPosition().y() * getTileHeightPx();
QPoint newPos(newPosX, newPosY);
- qDebug("Move C");
(*it)->setSize(getTileWidthPx(), getTileHeightPx());
(*it)->move(newPos);
- //(*it)->move((oldpos.x() / getTileWidthPx()) * nw, (oldpos.y() / getTileHeightPx()) * nh);
- //(*it)->setSize(nw, nh);
}
// Resize trash and set position.
@@ -754,26 +760,28 @@ void MainWindow::onReloadRoomOk()
_reloadWindow->hide();
- QMap<QString, QPoint> room = Global::getRooms()[roomToReload];
+ Room *room = Global::getRooms()[roomToReload];
+ bool gridSizeSet = false; /* TODO: read grid size from config */
+ if (!gridSizeSet) {
+ /* collect the maximum coordinates */
+ _tilesX = 0;
+ _tilesY = 0;
- /* collect the maximum coordinates to resize the grid */
- _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(); }
- for (QMap<QString, QPoint>::iterator it = room.begin(); it != room.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;
}
- /* need a little extra space */
- _tilesX += 1;
- _tilesY += 1;
-
qDebug() << "New Grid Size: " << _tilesX << ", " << _tilesY << endl;
// qDebug() << " Room: " << room;
// qDebug() << "_rooms: " << _rooms;
- for (QMap<QString, QPoint>::iterator it = room.begin(); it != room.end(); ++it)
+ for (QMap<QString, QPoint>::iterator it = room->clientPositions.begin(); it != room->clientPositions.end(); ++it)
{
QString computerId = it.key();
QPoint pos = it.value();
@@ -786,7 +794,7 @@ void MainWindow::onReloadRoomOk()
QPoint pxPos(pos.x() * getTileWidthPx(), pos.y() * getTileHeightPx());
ConnectionFrame *cf = createFrame(computerId, pxPos, pos);
- cf->move(cf->getCurrentPosition()); /* TODO: this affects the placement */
+ cf->move(cf->getCurrentPosition());
onPlaceFrame(false, cf);
}
}