fixed window resize delayed for one present

This commit is contained in:
Hane 2024-04-16 19:25:33 +02:00
commit bf01df610d
2 changed files with 63 additions and 30 deletions

View file

@ -79,6 +79,7 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
void MainWindow::calculateChildWidgetsSize() { void MainWindow::calculateChildWidgetsSize() {
//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 //todo: own function + setsizeposition refactor + update setWidth bodies
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();
@ -87,23 +88,35 @@ void MainWindow::calculateChildWidgetsSize() {
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; width = (uint64_t)std::abs(srx2) * this->widthRatio;
int height = (uint64_t)std::abs(sry2);
log_debugcpp("Window Width: " + std::to_string(width)); log_debugcpp("Window Width: " + std::to_string(width));
for (auto *ew : ews) { for (auto *ew : ews) {
if (ew) ew->setWidth(width, widthRatio); if (!ew) continue;
ew->setSize(width, height);
} }
this->setAttribute(Qt::WA_DontShowOnScreen, true); this->setAttribute(Qt::WA_DontShowOnScreen, true);
this->show(); this->showNormal();
this->layout()->invalidate(); this->widget->layout()->invalidate();
this->widget->updateGeometry();
this->hide(); this->hide();
this->setAttribute(Qt::WA_DontShowOnScreen, false); this->setAttribute(Qt::WA_DontShowOnScreen, false);
int height = 0; height = 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) {
height += epw->height(); if (!epw) continue;
epw->layout()->getContentsMargins(&left, &top, &right, &bottom);
//epw->updateGeometry();
height += epw->sizeHint().height();
height += top;
height += bottom;
} }
height += mainMenuBar->height(); height += mainMenuBar->height();
height += hw->height();
//height += lastRowSpacer->geometry().height();
/* /*
* Establishing initial window size and position * Establishing initial window size and position
@ -131,11 +144,11 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
this->idx = idx; this->idx = idx;
this->sh = sh; this->sh = sh;
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
widgetLayout = new QHBoxLayout(this); widgetLayout = new QHBoxLayout(this);
//widgetLayout->setSizeConstraint(QLayout::SetFixedSize); //widgetLayout->setSizeConstraint(QLayout::SetFixedSize);
widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
//widgetLayout->setMaximumSize(minimumSize()); widgetLayout->setContentsMargins(0, 10, 0, 10);
//this->setLayout(
muteButton = new QCheckBox(this); muteButton = new QCheckBox(this);
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this); mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
@ -199,12 +212,15 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
volumePoller->start(10); volumePoller->start(10);
} }
void SessionWidget::setWidth(uint64_t width, double widthRatio) { void SessionWidget::setSize(uint64_t width, uint64_t height) {
/* og 1080p 120% testing values */ /* og 1080p 120% testing values */
this->mainLabel->setMaximumWidth((int)(width * 0.30) /*1/16ish 1080p*/); this->mainLabel->setMaximumWidth((int)(width * 0.30) /*1/16ish 1080p*/);
this->mainLabel->setMinimumWidth((int)(width * 0.30) /*1/16ish 1080p*/); this->mainLabel->setMinimumWidth((int)(width * 0.30) /*1/16ish 1080p*/);
this->mainLabel->setMaximumHeight((int)(height * 0.02));
this->mainLabel->setMinimumHeight((int)(height * 0.02));
this->muteButton->setMaximumWidth((int)(width * 0.10) /*1/32th 1080p*/); this->muteButton->setMaximumWidth((int)(width * 0.10) /*1/32th 1080p*/);
this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/); this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/);
//this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/16 1080p*/);
this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/); this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/);
widthSpacer->changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/); widthSpacer->changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/);
} }
@ -240,6 +256,7 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
for(uint32_t i = 0; i < channelCount && channelCount > 1; i++){ for(uint32_t i = 0; i < channelCount && channelCount > 1; i++){
QSlider* tmp = new QSlider(Qt::Horizontal); QSlider* tmp = new QSlider(Qt::Horizontal);
QLabel* tmpLb = new QLabel(""); QLabel* tmpLb = new QLabel("");
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
//tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); //tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
tmp->setTickInterval(5); tmp->setTickInterval(5);
tmp->setSingleStep(1); tmp->setSingleStep(1);
@ -249,8 +266,8 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
tmp->setValue((int) volume); tmp->setValue((int) volume);
tmpLb->setText(QString::number(volume)); tmpLb->setText(QString::number(volume));
//tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); //tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum);
this->channelSliders.push_back(tmp); this->channelSliders.push_back(tmp);
this->channelLabels.push_back(tmpLb); this->channelLabels.push_back(tmpLb);
widgetLayout->addWidget(tmp, 0, i); widgetLayout->addWidget(tmp, 0, i);
@ -264,9 +281,18 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
}); });
} }
this->setLayout(widgetLayout); this->setLayout(widgetLayout);
} }
/*
* QSize ChannelWidget::minimumSizeHint() const {
* return minimum;
* }
*
* void ChannelWidget::setMinimum(QSize minimum) {
* this->minimum = minimum;
* }
*/
void ChannelWidget::updateChannel(int channel) { void ChannelWidget::updateChannel(int channel) {
this->channelSliders.at(channel)->blockSignals(true); this->channelSliders.at(channel)->blockSignals(true);
this->channelSliders.at(channel)->setValue((int)((eph->getCallbackInfo()->channelVolumes[channel] + roundingFactor) * 100)); this->channelSliders.at(channel)->setValue((int)((eph->getCallbackInfo()->channelVolumes[channel] + roundingFactor) * 100));
@ -281,7 +307,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
this->eph = eph; this->eph = eph;
//todo: sussy //todo: sussy
this->eph->setState(EndpointState::ENDPOINT_ACTIVE, idx); this->eph->setState(EndpointState::ENDPOINT_ACTIVE, idx);
this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
//setAttribute(Qt::WA_TranslucentBackground); //setAttribute(Qt::WA_TranslucentBackground);
widgetLayout = new QGridLayout(this); widgetLayout = new QGridLayout(this);
//this->setLayout(widgetLayout); //this->setLayout(widgetLayout);
@ -353,7 +379,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
if(epChannelCount) { if(epChannelCount) {
cw = new ChannelWidget(epChannelCount, eph, this); cw = new ChannelWidget(epChannelCount, eph, this);
//cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); //cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/); widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/, Qt::AlignTop);
} }
/* /*
@ -408,7 +434,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
}); });
timer->start(10); timer->start(10);
/* First SessionWidget batch */ /* First Widget batch */
for (size_t i = 0; i < eph->getSessionCount(); i++) { for (size_t i = 0; i < eph->getSessionCount(); i++) {
SessionWidget* sessionWidget = new SessionWidget(i, eph->getSessionHandlers().at(i), this); SessionWidget* sessionWidget = new SessionWidget(i, eph->getSessionHandlers().at(i), this);
widgetLayout->addWidget(sessionWidget, row, 0, 1, 4 /* colmax */); widgetLayout->addWidget(sessionWidget, row, 0, 1, 4 /* colmax */);
@ -430,13 +456,13 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
log_debugcpp("ENDPOINT_WIDGETED"); log_debugcpp("ENDPOINT_WIDGETED");
} }
void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
uint64_t index = this->sessionWidgets.size(); uint64_t index = this->sessionWidgets.size();
SessionWidget* sw = new SessionWidget(index, ev->payload, this); SessionWidget* sw = new SessionWidget(index, ev->payload, this);
ev->payload->setFrontIndex(index); ev->payload->setFrontIndex(index);
this->widgetLayout->addWidget(sw, row, 0, 1, 4); this->widgetLayout->addWidget(sw, row, 0, 1, 4);
//sw->hide();
//sw->show();
row++; row++;
sessionWidgets.push_back(sw); sessionWidgets.push_back(sw);
return; return;
@ -450,6 +476,7 @@ void EndpointWidget::removeSessionWidget(CustomWidgetEvent<SessionHandler*>* ev)
this->widgetLayout->removeWidget(deceased); this->widgetLayout->removeWidget(deceased);
delete deceased; delete deceased;
sessionWidgets.at(i) = nullptr; sessionWidgets.at(i) = nullptr;
//row--;
ev->payload->setFrontIndex(INT_MAX); ev->payload->setFrontIndex(INT_MAX);
//this->sessionWidgetsUpdateTimer->start(); //this->sessionWidgetsUpdateTimer->start();
return; return;
@ -484,6 +511,7 @@ void MainWindow::customEvent(QEvent* ev) {
QMainWindow::customEvent(ev); QMainWindow::customEvent(ev);
} }
//__attribute__((optimize("O0", "unroll-loops")))
void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev){ void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev){
uint64_t i = ev->payload; uint64_t i = ev->payload;
this->ews.at(i)->setParent(nullptr); this->ews.at(i)->setParent(nullptr);
@ -533,12 +561,14 @@ void MainWindow::reorderEndpointWidgetCollection() {
ews.resize(firstNullPosition + 1); ews.resize(firstNullPosition + 1);
} }
void EndpointWidget::setWidth(uint64_t width, double widthRatio) { void EndpointWidget::setSize(uint64_t width, uint64_t height) {
/* og 1080p 120% testing values */ /* og 1080p 120% testing values */
this->mainLabel->setMaximumWidth((int)width * 0.35 /* 1080p 120%*/); this->mainLabel->setMaximumWidth((int)width * 0.35 /* 1080p 120%*/);
this->mainLabel->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/); this->mainLabel->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/);
this->cw->setMinimumSize(QSize(1, height * 0.06));
this->cw->setMaximumSize(QSize(QWIDGETSIZE_MAX, height * 0.06));
for (auto sw : sessionWidgets){ for (auto sw : sessionWidgets){
if (sw) sw->setWidth(width, widthRatio); if (sw) sw->setSize(width, height);
} }
} }
@ -761,7 +791,7 @@ void MainWindow::closeEvent(QCloseEvent *event) {
if (trayIcon->isVisible()) { if (trayIcon->isVisible()) {
//todo: would be nice to show this to 1st time users; ini-san will come... //todo: would be nice to show this to 1st time users; ini-san will come...
//this->trayIcon->showMessage("ini file calling","tratarte como un gilipollas la primera vez", QSystemTrayIcon::Information); //this->trayIcon->showMessage("ini file calling","primerita vez", QSystemTrayIcon::Information);
hide(); hide();
event->ignore(); event->ignore();

View file

@ -85,7 +85,7 @@ Q_OBJECT
public: public:
SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */); SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */);
~SessionWidget(); ~SessionWidget();
void setWidth(uint64_t width, double widthRatio); void setSize(uint64_t width, uint64_t height);
public slots: public slots:
void updateMainVolume(int newValue); void updateMainVolume(int newValue);
void updateMute(int checked); void updateMute(int checked);
@ -106,6 +106,8 @@ Q_OBJECT
public: public:
ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent = nullptr); ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent = nullptr);
//QSize minimumSizeHint() const override;
//void setMinimum(QSize minimum);
void updateChannel(int channel); void updateChannel(int channel);
private: private:
@ -115,7 +117,7 @@ private:
std::vector<QSlider*> channelSliders; std::vector<QSlider*> channelSliders;
std::vector<QLabel*> channelLabels; std::vector<QLabel*> channelLabels;
QGridLayout *widgetLayout; QGridLayout *widgetLayout;
QSize minimum;
}; };
class EndpointWidget : public QWidget { class EndpointWidget : public QWidget {
@ -123,6 +125,8 @@ Q_OBJECT
public: public:
EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr);
//QSize minimumSizeHint() const override;
//void setMinimum(uint64_t height, double heightRatio);
EndpointHandler* getEndpointHandler(); EndpointHandler* getEndpointHandler();
std::map<Roles, ExtendedCheckBox*> getDefaultRolesWidgets(); std::map<Roles, ExtendedCheckBox*> getDefaultRolesWidgets();
@ -130,7 +134,7 @@ public:
void setIndex(uint64_t idx); void setIndex(uint64_t idx);
uint64_t getIndex(); uint64_t getIndex();
//void setVolume(int channel, float volume); //void setVolume(int channel, float volume);
void setWidth(uint64_t width, double widthRatio); void setSize(uint64_t width, uint64_t height);
~EndpointWidget(); ~EndpointWidget();
//void updateMainVolume(float newValue); //void updateMainVolume(float newValue);
@ -170,6 +174,7 @@ private:
uint64_t idx; uint64_t idx;
ChannelWidget* cw; ChannelWidget* cw;
std::vector<SessionWidget*> sessionWidgets; std::vector<SessionWidget*> sessionWidgets;
QSize minimum;
//std::vector<EndpointHandler*> *ephs; //std::vector<EndpointHandler*> *ephs;
//std::vector<QSlider> *sliders; //std::vector<QSlider> *sliders;
@ -231,18 +236,16 @@ 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 width;
uint64_t height;
QScrollArea *scrollArea; QScrollArea *scrollArea;
HeaderWidget* hw; HeaderWidget* hw;
QToolBar *mainMenuBar; QToolBar *mainMenuBar;
QScreen *screen; QScreen *screen;
//todo: ratio
//Win10 1080p 120%
QSize mwSize;
QSpacerItem* lastRowSpacer; QSpacerItem* lastRowSpacer;
//public slots: //public slots:
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); // void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);