From b6b7e1c577b379e2435e34d5ec9b743b14b39962 Mon Sep 17 00:00:00 2001 From: Hane Date: Tue, 14 May 2024 19:48:11 +0200 Subject: [PATCH] code cleanup: refactored ugly window width/scrheight cache --- src/qt/qtclasses.cpp | 13 ++++++++++--- src/qt/qtclasses.h | 4 +--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 5e0bd3a..efac234 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -633,7 +633,16 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent* ev){ uint64_t index = this->sessionWidgets.size(); SessionWidget* sw = new SessionWidget(index, ev->payload, this); ev->payload->setFrontIndex(index); - sw->calculateSize(currentWidth, currentHeight); + //MainWindow* mw = dynamic_cast(parent()); + //TODO: change mainwindow's widget name and subclass qwidget + const QWidgetList topLevelWidgets = QApplication::topLevelWidgets(); + for (QWidget *widget : topLevelWidgets) { + if (dynamic_cast(widget)) { + double widthRatio = ((MainWindow*)widget)->widthRatio; + sw->calculateSize(std::abs(this->screen()->geometry().width()) * widthRatio, + std::abs(this->screen()->geometry().height())); + } + } this->widgetLayout->addWidget(sw, row, 0, 1, 4); row++; sessionWidgets.push_back(sw); @@ -740,8 +749,6 @@ void MainWindow::reorderEndpointWidgetCollection() { void EndpointWidget::calculateSize(uint64_t width, uint64_t height) { /* og 1080p 120% testing values */ - this->currentWidth = width; - this->currentHeight = height; log_to_file("[EndpointWidget %s sizes]\n", converter.to_bytes(this->getEndpointHandler()->getName()).c_str()); log_to_file("Params: {Width: %u Height: %u}\n", width, height); this->mainLabel->setMaximumWidth((int)(width * 0.50) /* 1080p 120%*/); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 854e7d8..c85b9ad 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -201,8 +201,6 @@ private: ChannelWidget* cw; std::vector sessionWidgets; QSize minimum; - uint64_t currentWidth = 1; - uint64_t currentHeight = 1; //std::vector *ephs; //std::vector *sliders; @@ -272,7 +270,7 @@ private: QToolBar *mainMenuBar; QScreen *screen; QSpacerItem* lastRowSpacer; - + friend class EndpointWidget; //public slots: // void setEndpointHandlers(std::vector *ephs);