diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 34c4c58..a004043 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -71,61 +71,56 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) { break; default: this->addToolBar(Qt::BottomToolBarArea, mainMenuBar); + log_debugcpp("Failed positioning window"); return QRect(500, 400, width, height); break; } } -void MainWindow::calculateChildWidgetsSize() { +void MainWindow::compose() { //We need dynamically added child widgets to expand so that we know their height - //todo: own function + setsizeposition refactor + update setWidth bodies - + + /* + * Setting correct widget widths and heights + */ screen = this->getCurrentScreen(); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); + QRect screenRes = screen->geometry(); int srx1, srx2, sry1, sry2; screenRes.getCoords(&srx1, &sry1, &srx2, &sry2); log_debugcpp("(for Percentage) Screen Res: " + std::to_string(srx1) + " " + std::to_string(srx2)+" " + std::to_string(sry1) + " " + std::to_string(sry2)); - width = (uint64_t)std::abs(srx2) * this->widthRatio; - int height = (uint64_t)std::abs(sry2); - log_debugcpp("Window Width: " + std::to_string(width)); - for (auto *ew : ews) { - if (!ew) continue; - ew->setSize(width, height); - } - - this->setAttribute(Qt::WA_DontShowOnScreen, true); - this->showNormal(); - this->widget->layout()->invalidate(); - this->widget->updateGeometry(); - this->hide(); - this->setAttribute(Qt::WA_DontShowOnScreen, false); - - height = 0; + uint64_t windowWidth = (uint64_t)std::abs(srx2) * this->widthRatio; + uint64_t screenHeight = (uint64_t)std::abs(sry2); + log_debugcpp("Window Width: " + std::to_string(windowWidth)); + for (auto *epw : ews) { + if (!epw) continue; + epw->setSize(windowWidth, screenHeight); + } + + /* + * Calculating window height + */ + uint64_t windowHeight = 0; int left = 0, top = 0, right = 0, bottom = 0; - //this->widget->updateGeometry(); - //height = widget->height(); for (auto *epw : this->ews) { if (!epw) continue; epw->layout()->getContentsMargins(&left, &top, &right, &bottom); - //epw->updateGeometry(); - height += epw->sizeHint().height(); - height += top; - height += bottom; + windowHeight += epw->sizeHint().height(); + windowHeight += top; + windowHeight += bottom; } - height += mainMenuBar->height(); + windowHeight += mainMenuBar->height(); - //height += lastRowSpacer->geometry().height(); - /* * Establishing initial window size and position */ - setGeometry(setSizePosition(screen, width, height)); + setGeometry(setSizePosition(screen, windowWidth, windowHeight)); } QScreen* MainWindow::getCurrentScreen() { - //Using cursor pos as screen detector. Flawed. + //todo: Using cursor pos as screen detector. Flawed. QPoint cursorPos = QCursor::pos(); log_debugcpp("Cursor pos: " + std::to_string(cursorPos.ry()) + " " + std::to_string(cursorPos.rx())); @@ -801,7 +796,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { switch (reason) { case QSystemTrayIcon::Trigger: - this->calculateChildWidgetsSize(); + this->compose(); this->showNormal(); this->activateWindow(); break; diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 5ec06d7..549569d 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -205,7 +205,7 @@ class MainWindow : public QMainWindow { public: MainWindow(QWidget *parent = nullptr); void reloadEndpointWidgets(); - void calculateChildWidgetsSize(); + void compose(); protected: void closeEvent(QCloseEvent *event) override; @@ -236,10 +236,7 @@ private: //TODO: Test //TODO: Come back here and check all are parametrized double widthRatio = 0.28; - double heightRatio = 0.05; - uint64_t width; - uint64_t height; - + QScrollArea *scrollArea; HeaderWidget* hw; QToolBar *mainMenuBar;