initial window scaling

This commit is contained in:
Hane 2024-04-12 21:09:04 +02:00
commit 5229154c45
2 changed files with 70 additions and 23 deletions

View file

@ -25,15 +25,13 @@ void ExtendedCheckBox::customEvent(QEvent* ev) {
QCheckBox::customEvent(ev);
}
QRect MainWindow::setSizePosition(int width, int height) {
QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) {
//setGeometry ignores decoration size, theres others for that
QRect trayIconPos = this->trayIcon->geometry();
int tix1, tix2, tiy1, tiy2;
trayIconPos.getCoords(&tix1, &tiy1, &tix2, &tiy2);
log_debugcpp("Tray Icon Pos: " + std::to_string(tix1) + " " + std::to_string(tix2)+" " + std::to_string(tiy1) + " " + std::to_string(tiy2));
screen = this->getCurrentScreen();
log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString());
this->setScreen(screen);
QRect screenRes = screen->geometry();
@ -60,15 +58,19 @@ QRect MainWindow::setSizePosition(int width, int height) {
switch (pos) {
case SpawnPos::UP | SpawnPos::RIGHT:
this->addToolBar(Qt::BottomToolBarArea, mainMenuBar);
return QRect((arx2 - width), ary1, width, height);
break;
case SpawnPos::DOWN | SpawnPos::LEFT:
this->addToolBar(Qt::TopToolBarArea, mainMenuBar);
return QRect(arx1, (ary2-height), width, height);
break;
case SpawnPos::DOWN | SpawnPos::RIGHT:
this->addToolBar(Qt::TopToolBarArea, mainMenuBar);
return QRect((arx2 - width), (ary2-height), width, height);
break;
default:
this->addToolBar(Qt::BottomToolBarArea, mainMenuBar);
return QRect(500, 400, width, height);
break;
}
@ -76,27 +78,49 @@ QRect MainWindow::setSizePosition(int width, int height) {
void MainWindow::calculateChildWidgetsSize() {
//We need dynamically added child widgets to expand so that we know their height
//TODO: more 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;
log_debugcpp("Window Width: " + std::to_string(width));
for (auto *ew : ews) {
ew->setWidth(width, widthRatio);
}
/*
* sessionwidget: mainLabel, mainSlider, muteButton
* endpointwidget: mainLabel
*
*
*
*
*
*
*
*/
this->setAttribute(Qt::WA_DontShowOnScreen, true);
this->show();
this->layout()->invalidate();
this->hide();
this->setAttribute(Qt::WA_DontShowOnScreen, false);
int height = 0, width = 0;
int height = 0;
for (auto *epw : this->ews) {
height += epw->height();
//width = (epw->width() > width) ? epw->width() : width;
}
width = scrollArea->width();
//width = scrollArea->width();
height += mainMenuBar->height();
height += hw->height();
/*
* Establishing initial window size and position
*/
//TODO: test. hardcode. var.
setGeometry(setSizePosition(width, height));
setGeometry(setSizePosition(screen, width, height));
}
QScreen* MainWindow::getCurrentScreen() {
@ -114,7 +138,7 @@ QScreen* MainWindow::getCurrentScreen() {
return QGuiApplication::primaryScreen();
}
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent){
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent), widthSpacer(1, 1, QSizePolicy::Expanding, QSizePolicy::Minimum){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx;
this->sh = sh;
@ -129,12 +153,12 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
mainSlider = new QSlider(Qt::Horizontal, this);
mainLabel->setMaximumWidth(150 /*1/16ish 1080p*/);
mainLabel->setMinimumWidth(150 /*1/16ish 1080p*/);
//mainLabel->setMaximumWidth(150 /*1/16ish 1080p*/);
//mainLabel->setMinimumWidth(150 /*1/16ish 1080p*/);
mainLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
mainSlider->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
mainSlider->setMinimumWidth(120 /*1/16 1080p*/);
//mainSlider->setMinimumWidth(120 /*1/16 1080p*/);
mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5);
@ -143,8 +167,8 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
muteButton->setCheckState((sh->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(sh->getMute() ? STRING_UNMUTE : STRING_MUTE);
muteButton->setMaximumWidth(60 /*1/32th 1080p*/);
muteButton->setMinimumWidth(60 /*1/32th 1080p*/);
//muteButton->setMaximumWidth(60 /*1/32th 1080p*/);
//muteButton->setMinimumWidth(60 /*1/32th 1080p*/);
float volume = sh->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
mainSlider->setValue((int)volume);
log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume));
@ -158,7 +182,7 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
*
* layout->setSizeConstraint(QLayout::SetMinAndMaxSize);
*/
widgetLayout->addItem(new QSpacerItem(200, 1, QSizePolicy::Expanding, QSizePolicy::Minimum));
widgetLayout->addItem(&widthSpacer);
widgetLayout->addWidget(mainLabel, Qt::AlignLeft | Qt::AlignBottom);
widgetLayout->addWidget(muteButton, Qt::AlignRight | Qt::AlignBottom);
widgetLayout->addWidget(mainSlider, Qt::AlignRight | Qt::AlignBottom);
@ -194,6 +218,16 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent)
volumePoller->start(10);
}
void SessionWidget::setWidth(uint64_t width, double widthRatio) {
/* og 1080p 120% testing values */
this->mainLabel->setMaximumWidth((int)(width * 0.30) /*1/16ish 1080p*/);
this->mainLabel->setMinimumWidth((int)(width * 0.30) /*1/16ish 1080p*/);
this->muteButton->setMaximumWidth((int)(width * 0.10) /*1/32th 1080p*/);
this->muteButton->setMinimumWidth((int)(width * 0.10) /*1/32th 1080p*/);
this->mainSlider->setMinimumWidth((int)(width * 0.30) /*1/16 1080p*/);
widthSpacer.changeSize((int)width * 0.20, 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/);
}
void SessionWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
this->sh->setMute(osh->getGuid(), muted);
@ -294,8 +328,8 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
return;
}
mainLabel->setMaximumWidth(350 /* 1080p 120%*/);
mainLabel->setMinimumWidth(350 /* 1080p 120%*/);
//mainLabel->setMaximumWidth(350 /* 1080p 120%*/);
//mainLabel->setMinimumWidth(350 /* 1080p 120%*/);
mainLabel->setWordWrap(true);
mainLabel->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
//mainLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
@ -316,7 +350,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
log_debugcpp("ENDPOINT SET WITH VOLUME " + std::to_string(volume));
//mainMuteLayout = new QGridLayout();
widgetLayout->addWidget(mainLabel, row, 0, 1, 3, Qt::AlignLeft | Qt::AlignVCenter);
widgetLayout->addWidget(mainLabel, row, 0, 1, 2, Qt::AlignLeft | Qt::AlignVCenter);
widgetLayout->addWidget(muteButton, row, 2, Qt::AlignRight | Qt::AlignVCenter);
widgetLayout->addWidget(mainVolumeLabel, row, 3, Qt::AlignRight | Qt::AlignVCenter);
row++;
@ -515,6 +549,15 @@ void MainWindow::reorderEndpointWidgetCollection() {
ews.resize(firstNullPosition + 1);
}
void EndpointWidget::setWidth(uint64_t width, double widthRatio) {
/* og 1080p 120% testing values */
this->mainLabel->setMaximumWidth((int)width * 0.35 /* 1080p 120%*/);
this->mainLabel->setMinimumWidth((int)width * 0.35 /* 1080p 120%*/);
for (auto sw : sessionWidgets){
sw->setWidth(width, widthRatio);
}
}
void EndpointWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
this->eph->setMute(osh->getGuid(), muted);