From 75ffb4d9c7a7a22ddf472735073815f68c763cd4 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Fri, 22 Apr 2016 17:07:24 +0200 Subject: determine grid size based on the loaded room config. --- src/server/mainwindow/mainwindow.cpp | 80 ++++++++++++++++++++++++------------ 1 file changed, 54 insertions(+), 26 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index bdd4603..a8d35a8 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -59,6 +59,10 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _mode = Mode::Multicast; _streamingSource = 0; + /* stupid default, just for testing */ + _tilesX = 20; + _tilesY = 20; + _sessionNameWindow = new SessionNameWindow(this); _helpWindow = new HelpWindow(this); _helpWindow->setWindowTitle("Help"); @@ -138,8 +142,9 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : this->onSessionNameUpdate(); // Just make lable visible. _countSessionNameUpdate = 0; - _tileWidth = ui->frmRoom->size().width() / _tilesX; - _tileHeight = ui->frmRoom->size().height() / _tilesY; + /* better calculate on demand */ +// _tileWidth = ui->frmRoom->size().width() / _tilesX; +// _tileHeight = ui->frmRoom->size().height() / _tilesY; tryToUseRoomTemplate(); @@ -166,8 +171,8 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame) for (QList::iterator it(_clientFrames.begin()); it != _clientFrames.end(); ++it) { const QPoint &oldpos = (*it)->frameGeometry().topLeft(); - const int tx = oldpos.x() / _tileWidth; - const int ty = oldpos.y() / _tileHeight; + const int tx = oldpos.x() / getTileWidthPx(); + const int ty = oldpos.y() / getTileHeightPx(); const int index = tx + ty * _tilesX; if (frame == *it) { @@ -195,8 +200,8 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame) const int index = (i + currentIndex) % elems; if (grid[index]) continue; - const int x = (index % _tilesX) * _tileWidth; - const int y = (index / _tilesX) * _tileHeight; + const int x = (index % _tilesX) * getTileWidthPx(); + const int y = (index / _tilesX) * getTileHeightPx(); //qDebug() << "Index=" << index << " i=" << i << " cI=" << currentIndex << " elems=" << elems << " x=" << x << " y=" << y; qDebug("Move B"); frame->move(x, y); @@ -213,7 +218,7 @@ void MainWindow::placeFrameInFreeSlot(ConnectionFrame* frame) ConnectionFrame* MainWindow::createFrame() { // Allocate and resize - ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, _tileWidth, _tileHeight); + ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, getTileWidthPx(), getTileHeightPx()); _clientFrames.append(cf); cf->show(); connect(cf, SIGNAL(frameMoved(bool, ConnectionFrame *)), this, SLOT(onPlaceFrame(bool, ConnectionFrame *))); @@ -230,7 +235,7 @@ ConnectionFrame* MainWindow::createFrame() ConnectionFrame* MainWindow::createFrame(QString computerId, QPoint position) { // Allocate and resize - ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, _tileWidth, _tileHeight); + ConnectionFrame *cf = new ConnectionFrame(ui->frmRoom, getTileWidthPx(), getTileHeightPx()); cf->setComputerId(computerId); cf->setCurrentPosition(position); _clientFrames.append(cf); @@ -271,7 +276,7 @@ void MainWindow::savePosition(ConnectionFrame *cf) Client *client = cf->client(); if (client == NULL) return; - QPoint pos(cf->pos().x() / _tileWidth, cf->pos().y() / _tileHeight); + QPoint pos(cf->pos().x() / getTileWidthPx(), cf->pos().y() / getTileHeightPx()); USER_SETTINGS(settings); settings.beginGroup("client_position"); settings.setValue(client->ip(), pos); @@ -357,11 +362,11 @@ void MainWindow::tryToUseRoomTemplate() QPoint coord = conf.value("pos").toPoint(); qDebug() << computerId; qDebug() << coord; - qDebug() << _tileWidth ; - qDebug() << _tileHeight ; + qDebug() << getTileWidthPx() ; + qDebug() << getTileHeightPx() ; - coord.setX(coord.x() * _tileWidth); - coord.setY(coord.y() * _tileHeight); + coord.setX(coord.x() * getTileWidthPx()); + coord.setY(coord.y() * getTileHeightPx()); qDebug() << coord ; ConnectionFrame *cf = createFrame(computerId, coord); @@ -469,7 +474,7 @@ void MainWindow::resizeEvent(QResizeEvent* e) { const QPoint &oldpos = (*it)->frameGeometry().topLeft(); qDebug("Move C"); - (*it)->move((oldpos.x() / _tileWidth) * nw, (oldpos.y() / _tileHeight) * nh); + (*it)->move((oldpos.x() / getTileWidthPx()) * nw, (oldpos.y() / getTileHeightPx()) * nh); (*it)->setSize(nw, nh); } @@ -480,8 +485,6 @@ void MainWindow::resizeEvent(QResizeEvent* e) ui->trash->resize(nw, nh); // qDebug() << "Trash pos: " << ui->trash->pos(); - _tileWidth = nw; - _tileHeight = nh; } /***************************************************************************//** @@ -552,16 +555,16 @@ void MainWindow::onPlaceFrame(bool activateTrash, ConnectionFrame* frame) return; const QPoint &p = frame->frameGeometry().center(); const QSize &s = ui->frmRoom->geometry().size(); - int x = (p.x() / _tileWidth) * _tileWidth; - int y = (p.y() / _tileHeight) * _tileHeight; + int x = (p.x() / getTileWidthPx()) * getTileWidthPx(); + int y = (p.y() / getTileHeightPx()) * getTileHeightPx(); if (x < 0) x = 0; - else if (x > s.width() - _tileWidth) - x = (_tilesX - 1) * _tileWidth; + else if (x > s.width() - getTileWidthPx()) + x = (_tilesX - 1) * getTileWidthPx(); if (y < 0) y = 0; - else if (y > s.height() - _tileHeight) - y = (_tilesY - 1) * _tileHeight; + else if (y > s.height() - getTileHeightPx()) + y = (_tilesY - 1) * getTileHeightPx(); // Check if x coordinate is in trash position. Check only if activateTrash = true! if (activateTrash) @@ -744,7 +747,24 @@ void MainWindow::onReloadRoomOk() _reloadWindow->ui->roomList->clear(); _reloadWindow->hide(); + QMap room = Global::getRooms()[roomToReload]; + + /* collect the maximum coordinates to resize the grid */ + _tilesX = 0; + _tilesY = 0; + + for (QMap::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; + + qDebug() << "New Grid Size: " << _tilesX << ", " << _tilesY << endl; // qDebug() << " Room: " << room; // qDebug() << "_rooms: " << _rooms; for (QMap::iterator it = room.begin(); it != room.end(); ++it) @@ -755,17 +775,25 @@ void MainWindow::onReloadRoomOk() qDebug() << "ComputerID: " << computerId; qDebug() << "Pos: " << pos; + // Transform to pixels for createFrame(computerId, position). - pos.setX(pos.x() * _tileWidth); - pos.setY(pos.y() * _tileHeight); + pos.setX(pos.x() * getTileWidthPx()); + pos.setY(pos.y() * getTileHeightPx()); ConnectionFrame *cf = createFrame(computerId, pos); - cf->move(cf->getCurrentPosition()); + cf->move(cf->getCurrentPosition()); /* TODO: this affects the placement */ onPlaceFrame(false, cf); } } } +int MainWindow::getTileWidthPx() const { + return ui->frmRoom->size().width() / _tilesX; +} +int MainWindow::getTileHeightPx() const { + return ui->frmRoom->size().height() / _tilesY; +} + /***************************************************************************//** * Display popup which explains possible actions about the buttons. */ @@ -1138,7 +1166,7 @@ void MainWindow::onClientAuthenticated(Client* client) if (y < 0) y = 0; qDebug("Move E"); - cf->move(x * _tileWidth, y * _tileHeight); + cf->move(x * getTileWidthPx(), y * getTileHeightPx()); onPlaceFrame(true, cf); } else -- cgit v1.2.3-55-g7522