From b39ee0b0a3b8c51da2f2ef709dbb88e20ec93703 Mon Sep 17 00:00:00 2001 From: Christian Klinger Date: Wed, 27 Apr 2016 15:54:03 +0200 Subject: add aspect ratio preservation. --- src/server/mainwindow/mainwindow.cpp | 67 +++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 13 deletions(-) (limited to 'src/server/mainwindow/mainwindow.cpp') diff --git a/src/server/mainwindow/mainwindow.cpp b/src/server/mainwindow/mainwindow.cpp index d20b525..ff814c0 100644 --- a/src/server/mainwindow/mainwindow.cpp +++ b/src/server/mainwindow/mainwindow.cpp @@ -59,9 +59,12 @@ MainWindow::MainWindow(QString ipListUrl, QWidget* parent) : _mode = Mode::Multicast; _streamingSource = 0; - /* default value, these should be updated on loading a room */ - _tilesX = 20; - _tilesY = 20; + /* default value, these will be updated a room is loaded */ + _tilesX = 10; + _tilesY = 10; + + _virtCols = 0; + _virtRows = 0; _sessionNameWindow = new SessionNameWindow(this); _helpWindow = new HelpWindow(this); @@ -491,6 +494,26 @@ void MainWindow::changeEvent(QEvent* e) QMainWindow::changeEvent(e); } +enum AspectStatus { GRID_OK, GRID_TOO_WIDE, GRID_TOO_TALL }; + +/** + * check the difference in the aspect ratio between the frame size and the grid + * size. The parameters in here are hand-adjusted. Feel free to make it more or + * less sensitive. + * */ +AspectStatus checkAspectRatio(const QSize& frameSize, const QSize& gridSize) { + float aspectRoom = ((float) gridSize.height()) / ((float) gridSize.width()); + float aspectFrame = ((float) frameSize.height()) / ((float) frameSize.width()); + + if (aspectRoom / aspectFrame < 0.8) { + return GRID_TOO_WIDE; + } + if ( aspectFrame / aspectRoom < 0.8) { + return GRID_TOO_TALL; + } + return GRID_OK; +} + /***************************************************************************//** * Resize event. * @param e @@ -498,12 +521,36 @@ void MainWindow::changeEvent(QEvent* e) void MainWindow::resizeEvent(QResizeEvent* e) { Room* room = Global::getRooms()[Global::getCurrentRoom()]; - QSize& clientSize = room->clientSize; - // Resize all connection windows - if (ui->frmRoom->size().width() < 100 || ui->frmRoom->size().height() < 100 || _tilesX <= 0 || _tilesY <= 0) - return; + + /* Place the trash-bin */ const int nw = ui->frmRoom->size().width() / _tilesX; const int nh = ui->frmRoom->size().height() / _tilesY; + const int width = ui->frmRoom->geometry().width() - (nw + 1); + const int height = ui->frmRoom->geometry().height() - (nh + 1); + ui->trash->move(width, height); + ui->trash->resize(getTileWidthPx(), getTileHeightPx()); + + + if (room == NULL) {return; } /* Nothing to do here */ /* TODO: But still place the trashbin */ + QSize& clientSize = room->clientSize; + if (ui->frmRoom->size().width() < 100 || ui->frmRoom->size().height() < 100 || _tilesX <= 0 || _tilesY <= 0) { return; } + + QSize newGridSize = room->gridSize; + + /* do we have to add virtual columns? */ + while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_WIDE) { + /* add row */ + newGridSize.setHeight(newGridSize.height() + 1); + } + while (checkAspectRatio(ui->frmRoom->size(), newGridSize) == GRID_TOO_TALL) { + /* add column */ + newGridSize.setWidth(newGridSize.width() + 1); + } + this->_tilesX = newGridSize.width(); + this->_tilesY = newGridSize.height(); + + + /* Resize all connection windows */ for (QList::iterator it = _clientFrames.begin(); it != _clientFrames.end(); ++it) { int newPosX = (*it)->getGridPosition().x() * getTileWidthPx(); @@ -513,12 +560,6 @@ void MainWindow::resizeEvent(QResizeEvent* e) (*it)->setSize(getTileWidthPx() * clientSize.width(), getTileHeightPx() * clientSize.height()); (*it)->move(newPos); } - - // Resize trash and set position. - const int width = ui->frmRoom->geometry().width() - (nw + 1); - const int height = ui->frmRoom->geometry().height() - (nh + 1); - ui->trash->move(width, height); - ui->trash->resize(nw, nh); // qDebug() << "Trash pos: " << ui->trash->pos(); } -- cgit v1.2.3-55-g7522