recent code slightly refactored

This commit is contained in:
Hane 2024-04-16 19:53:57 +02:00
commit 78fabd3917
2 changed files with 28 additions and 36 deletions

View file

@ -71,61 +71,56 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
break; break;
default: default:
this->addToolBar(Qt::BottomToolBarArea, mainMenuBar); this->addToolBar(Qt::BottomToolBarArea, mainMenuBar);
log_debugcpp("Failed positioning window");
return QRect(500, 400, width, height); return QRect(500, 400, width, height);
break; break;
} }
} }
void MainWindow::calculateChildWidgetsSize() { void MainWindow::compose() {
//We need dynamically added child widgets to expand so that we know their height //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(); screen = this->getCurrentScreen();
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
QRect screenRes = screen->geometry(); QRect screenRes = screen->geometry();
int srx1, srx2, sry1, sry2; int srx1, srx2, sry1, sry2;
screenRes.getCoords(&srx1, &sry1, &srx2, &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)); 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; uint64_t windowWidth = (uint64_t)std::abs(srx2) * this->widthRatio;
int height = (uint64_t)std::abs(sry2); uint64_t screenHeight = (uint64_t)std::abs(sry2);
log_debugcpp("Window Width: " + std::to_string(width)); log_debugcpp("Window Width: " + std::to_string(windowWidth));
for (auto *ew : ews) { for (auto *epw : ews) {
if (!ew) continue; if (!epw) continue;
ew->setSize(width, height); epw->setSize(windowWidth, screenHeight);
} }
this->setAttribute(Qt::WA_DontShowOnScreen, true); /*
this->showNormal(); * Calculating window height
this->widget->layout()->invalidate(); */
this->widget->updateGeometry(); uint64_t windowHeight = 0;
this->hide();
this->setAttribute(Qt::WA_DontShowOnScreen, false);
height = 0;
int left = 0, top = 0, right = 0, bottom = 0; int left = 0, top = 0, right = 0, bottom = 0;
//this->widget->updateGeometry();
//height = widget->height();
for (auto *epw : this->ews) { for (auto *epw : this->ews) {
if (!epw) continue; if (!epw) continue;
epw->layout()->getContentsMargins(&left, &top, &right, &bottom); epw->layout()->getContentsMargins(&left, &top, &right, &bottom);
//epw->updateGeometry(); windowHeight += epw->sizeHint().height();
height += epw->sizeHint().height(); windowHeight += top;
height += top; windowHeight += bottom;
height += bottom;
} }
height += mainMenuBar->height(); windowHeight += mainMenuBar->height();
//height += lastRowSpacer->geometry().height();
/* /*
* Establishing initial window size and position * Establishing initial window size and position
*/ */
setGeometry(setSizePosition(screen, width, height)); setGeometry(setSizePosition(screen, windowWidth, windowHeight));
} }
QScreen* MainWindow::getCurrentScreen() { QScreen* MainWindow::getCurrentScreen() {
//Using cursor pos as screen detector. Flawed. //todo: Using cursor pos as screen detector. Flawed.
QPoint cursorPos = QCursor::pos(); QPoint cursorPos = QCursor::pos();
log_debugcpp("Cursor pos: " + std::to_string(cursorPos.ry()) + " " + std::to_string(cursorPos.rx())); 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) { void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
switch (reason) { switch (reason) {
case QSystemTrayIcon::Trigger: case QSystemTrayIcon::Trigger:
this->calculateChildWidgetsSize(); this->compose();
this->showNormal(); this->showNormal();
this->activateWindow(); this->activateWindow();
break; break;

View file

@ -205,7 +205,7 @@ class MainWindow : public QMainWindow {
public: public:
MainWindow(QWidget *parent = nullptr); MainWindow(QWidget *parent = nullptr);
void reloadEndpointWidgets(); void reloadEndpointWidgets();
void calculateChildWidgetsSize(); void compose();
protected: protected:
void closeEvent(QCloseEvent *event) override; void closeEvent(QCloseEvent *event) override;
@ -236,10 +236,7 @@ private:
//TODO: Test //TODO: Test
//TODO: Come back here and check all are parametrized //TODO: Come back here and check all are parametrized
double widthRatio = 0.28; double widthRatio = 0.28;
double heightRatio = 0.05;
uint64_t width;
uint64_t height;
QScrollArea *scrollArea; QScrollArea *scrollArea;
HeaderWidget* hw; HeaderWidget* hw;
QToolBar *mainMenuBar; QToolBar *mainMenuBar;