diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index dfdbede..1ecf82f 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -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); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index b3bb7ea..5176939 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -85,7 +85,7 @@ Q_OBJECT public: SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */); ~SessionWidget(); - + void setWidth(uint64_t width, double widthRatio); public slots: void updateMainVolume(int newValue); void updateMute(int checked); @@ -98,6 +98,8 @@ private: QCheckBox *muteButton = nullptr; SessionHandler* sh; QTimer* volumePoller = nullptr; + + QSpacerItem widthSpacer; }; class ChannelWidget : public QWidget { @@ -128,8 +130,9 @@ public: void setIndex(uint64_t idx); uint64_t getIndex(); - void setVolume(int channel, float volume); - + //void setVolume(int channel, float volume); + void setWidth(uint64_t width, double widthRatio); + ~EndpointWidget(); //void updateMainVolume(float newValue); //void updateVolume(uint32_t channel, float newValue); @@ -203,7 +206,7 @@ public: protected: void closeEvent(QCloseEvent *event) override; void customEvent(QEvent* ev) override; - QRect setSizePosition(int width, int height); + QRect setSizePosition(QScreen* screen, int width, int height); QScreen* getCurrentScreen(); private slots: @@ -228,7 +231,8 @@ private: static constexpr uint64_t ewsUpdateTimerFrequency = 500; //TODO: Test //TODO: Come back here and check all are parametrized - uint64_t windowWidth = 600; + double widthRatio = 0.28; + uint64_t width; QScrollArea *scrollArea; HeaderWidget* hw;