From f1b734bea6397153cdf742166717a4a4c54d350c Mon Sep 17 00:00:00 2001 From: Hane Date: Sat, 18 Jan 2025 18:51:32 +0100 Subject: [PATCH] fixed visuals when adding epw/sw while window is visible --- src/qt/qtclasses.cpp | 52 +++++++++++++++++++++++--------------------- src/qt/qtclasses.h | 2 +- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index ff5cb51..2e2a4b0 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -266,9 +266,12 @@ void MainWindow::updateColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a) { scrollArea->verticalScrollBar()->setPalette(pal); } -void MainWindow::compose() { - //todo: invalidate layout when adding sessions with window open +void MainWindow::compose(bool isVisible) { //We need dynamically added child widgets to expand so that we know their height + this->setUpdatesEnabled(false); + uint64_t windowWidth; + uint64_t screenHeight; + uint64_t windowHeight; /* * Setting correct widget widths and heights */ @@ -281,24 +284,22 @@ void MainWindow::compose() { 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)); - - uint64_t windowWidth = (((uint64_t)std::abs(screenRes.width())) * widthRatio); - uint64_t screenHeight = (uint64_t)std::abs(screenRes.height()); + windowWidth = (((uint64_t)std::abs(screenRes.width())) * widthRatio); + screenHeight = (uint64_t)std::abs(screenRes.height()); log_debugcpp("Window Width: " + std::to_string(windowWidth)); log_to_file("Window Width: %d \n", windowWidth); - - - this->createLayout(new QGridLayout()); this->scrollArea->setMaximumWidth((int)windowWidth); this->scrollArea->setMinimumWidth((int)windowWidth); this->mainMenuBar->setMinimumWidth((int)windowWidth); this->mainMenuBar->setMaximumWidth((int)windowWidth); + + this->createLayout(new QGridLayout()); for (auto *epw : ews) { if (!epw) continue; epw->updateChannelsVisibility(); epw->calculateSize(windowWidth - scrollArea->verticalScrollBar()->sizeHint().width() - - widgetLayout->contentsMargins().left() - , screenHeight); + - widgetLayout->contentsMargins().left() + , screenHeight); log_debugcpp("epw loop"); log_debugcpp("epw roles: " + print_as_binary((epw->getEndpointHandler()->getRoles()))); //std::bitset content = @@ -309,7 +310,7 @@ void MainWindow::compose() { /* * Calculating window height */ - uint64_t windowHeight = 0; + windowHeight = 0; int left = 0, top = 0, right = 0, bottom = 0; for (int i = 0; i < 2; i++) { if (!ews[i]) continue; @@ -321,13 +322,17 @@ void MainWindow::compose() { windowHeight += mainMenuBar->sizeHint().height(); log_debugcpp("windowHeight final value: " + std::to_string(windowHeight)); - //Undoing scrolling - scrollArea->verticalScrollBar()->setValue(0); - - /* - * Establishing initial window size and position - */ - setGeometry(setSizePosition(screen, windowWidth, windowHeight)); + this->setUpdatesEnabled(true); + if (!isVisible) { + /* + * Undoing scrolling + */ + scrollArea->verticalScrollBar()->setValue(0); + /* + * Establishing initial window size and position + */ + setGeometry(setSizePosition(screen, windowWidth, windowHeight)); + } } QScreen* MainWindow::getCurrentScreen() { @@ -683,7 +688,6 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i eph->getSessionHandlers().at(i)->setFrontIndex(i); } - /* Add/Remove SessionWidget callback */ eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) { QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent((QEvent::Type)CustomQEvent::SessionWidgetCreated, sessionHandler)); @@ -707,10 +711,8 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent* ev){ const QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); for (QWidget *widget : topLevelWidgets) { if (qobject_cast(widget)) { - double widthRatio = ((MainWindow*)widget)->widthRatio; - double dpr = ((MainWindow*)widget)->dpr; - sw->calculateSize((std::abs(this->screen()->geometry().width()) * widthRatio) * dpr, - std::abs(this->screen()->geometry().height())); + QCoreApplication::instance()->postEvent + (widget, new QEvent((QEvent::Type)CustomQEvent::RecomposeMainWindow)); } } this->widgetLayout->addWidget(sw, row, 0, 1, 4); @@ -768,7 +770,7 @@ void MainWindow::customEvent(QEvent* ev) { this->addEndpointWidget((CustomWidgetEvent*)ev); } else if (ev->type() == (QEvent::Type)CustomQEvent::RecomposeMainWindow) { ev->setAccepted(true); - if (this->isVisible()) this->compose(); + if (this->isVisible()) this->compose(true); } else if (ev->type() == (QEvent::Type)CustomQEvent::EndpointRoleChange) { ev->setAccepted(true); this->flushRoleChanges(); @@ -1327,7 +1329,7 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) { case QSystemTrayIcon::Trigger: if (!this->isVisible() && !recentlyClosed) { log_to_file("Recently Closed: %d \n", recentlyClosed); - this->compose(); + this->compose(false); this->showNormal(); this->activateWindow(); } diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 73a6b2c..0d5733f 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -183,7 +183,7 @@ class MainWindow : public QMainWindow { public: MainWindow(QWidget *parent = nullptr); void reloadEndpointWidgets(); - void compose(); + void compose(bool isVisible); void updateColor(uint8_t r, uint8_t g, uint8_t b, uint8_t a); protected: