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;
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;