diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 2bf785c..34c4c58 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -79,6 +79,7 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) { void MainWindow::calculateChildWidgetsSize() { //We need dynamically added child widgets to expand so that we know their height //todo: own function + setsizeposition refactor + update setWidth bodies + screen = this->getCurrentScreen(); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); 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)); 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) ew->setWidth(width, widthRatio); - } + if (!ew) continue; + ew->setSize(width, height); + } this->setAttribute(Qt::WA_DontShowOnScreen, true); - this->show(); - this->layout()->invalidate(); + this->showNormal(); + this->widget->layout()->invalidate(); + this->widget->updateGeometry(); this->hide(); 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) { - 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 += hw->height(); + + //height += lastRowSpacer->geometry().height(); /* * Establishing initial window size and position @@ -130,12 +143,12 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) //todo: based on qgridlayout, name+mute should be its own widget, same with channels this->idx = idx; this->sh = sh; - + + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); widgetLayout = new QHBoxLayout(this); //widgetLayout->setSizeConstraint(QLayout::SetFixedSize); widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - //widgetLayout->setMaximumSize(minimumSize()); - //this->setLayout( + widgetLayout->setContentsMargins(0, 10, 0, 10); muteButton = new QCheckBox(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); } -void SessionWidget::setWidth(uint64_t width, double widthRatio) { +void SessionWidget::setSize(uint64_t width, uint64_t height) { /* 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->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->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*/); 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++){ QSlider* tmp = new QSlider(Qt::Horizontal); QLabel* tmpLb = new QLabel(""); + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); //tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); tmp->setTickInterval(5); tmp->setSingleStep(1); @@ -249,8 +266,8 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge tmp->setValue((int) volume); tmpLb->setText(QString::number(volume)); //tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); - tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Preferred); + tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); + tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); this->channelSliders.push_back(tmp); this->channelLabels.push_back(tmpLb); widgetLayout->addWidget(tmp, 0, i); @@ -264,9 +281,18 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge }); } this->setLayout(widgetLayout); - } +/* + * QSize ChannelWidget::minimumSizeHint() const { + * return minimum; + * } + * + * void ChannelWidget::setMinimum(QSize minimum) { + * this->minimum = minimum; + * } + */ + void ChannelWidget::updateChannel(int channel) { this->channelSliders.at(channel)->blockSignals(true); 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; //todo: sussy this->eph->setState(EndpointState::ENDPOINT_ACTIVE, idx); - + this->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); //setAttribute(Qt::WA_TranslucentBackground); widgetLayout = new QGridLayout(this); //this->setLayout(widgetLayout); @@ -353,7 +379,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare if(epChannelCount) { cw = new ChannelWidget(epChannelCount, eph, this); //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); - /* First SessionWidget batch */ + /* First Widget batch */ for (size_t i = 0; i < eph->getSessionCount(); i++) { SessionWidget* sessionWidget = new SessionWidget(i, eph->getSessionHandlers().at(i), this); 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"); } + + void EndpointWidget::addSessionWidget(CustomWidgetEvent* ev){ uint64_t index = this->sessionWidgets.size(); SessionWidget* sw = new SessionWidget(index, ev->payload, this); ev->payload->setFrontIndex(index); this->widgetLayout->addWidget(sw, row, 0, 1, 4); - //sw->hide(); - //sw->show(); row++; sessionWidgets.push_back(sw); return; @@ -450,6 +476,7 @@ void EndpointWidget::removeSessionWidget(CustomWidgetEvent* ev) this->widgetLayout->removeWidget(deceased); delete deceased; sessionWidgets.at(i) = nullptr; + //row--; ev->payload->setFrontIndex(INT_MAX); //this->sessionWidgetsUpdateTimer->start(); return; @@ -484,6 +511,7 @@ void MainWindow::customEvent(QEvent* ev) { QMainWindow::customEvent(ev); } +//__attribute__((optimize("O0", "unroll-loops"))) void MainWindow::removeEndpointWidget(CustomWidgetEvent* ev){ uint64_t i = ev->payload; this->ews.at(i)->setParent(nullptr); @@ -533,12 +561,14 @@ void MainWindow::reorderEndpointWidgetCollection() { 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 */ this->mainLabel->setMaximumWidth((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){ - if (sw) sw->setWidth(width, widthRatio); + if (sw) sw->setSize(width, height); } } @@ -761,7 +791,7 @@ void MainWindow::closeEvent(QCloseEvent *event) { if (trayIcon->isVisible()) { //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(); event->ignore(); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index 0374db6..5ec06d7 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); + void setSize(uint64_t width, uint64_t height); public slots: void updateMainVolume(int newValue); void updateMute(int checked); @@ -106,6 +106,8 @@ Q_OBJECT public: ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent = nullptr); + //QSize minimumSizeHint() const override; + //void setMinimum(QSize minimum); void updateChannel(int channel); private: @@ -115,7 +117,7 @@ private: std::vector channelSliders; std::vector channelLabels; QGridLayout *widgetLayout; - + QSize minimum; }; class EndpointWidget : public QWidget { @@ -123,14 +125,16 @@ Q_OBJECT public: EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent = nullptr); - + //QSize minimumSizeHint() const override; + //void setMinimum(uint64_t height, double heightRatio); + EndpointHandler* getEndpointHandler(); std::map getDefaultRolesWidgets(); void setIndex(uint64_t idx); uint64_t getIndex(); //void setVolume(int channel, float volume); - void setWidth(uint64_t width, double widthRatio); + void setSize(uint64_t width, uint64_t height); ~EndpointWidget(); //void updateMainVolume(float newValue); @@ -170,6 +174,7 @@ private: uint64_t idx; ChannelWidget* cw; std::vector sessionWidgets; + QSize minimum; //std::vector *ephs; //std::vector *sliders; @@ -231,17 +236,15 @@ private: //TODO: Test //TODO: Come back here and check all are parametrized double widthRatio = 0.28; + double heightRatio = 0.05; uint64_t width; + uint64_t height; QScrollArea *scrollArea; HeaderWidget* hw; QToolBar *mainMenuBar; QScreen *screen; - //todo: ratio - //Win10 1080p 120% - QSize mwSize; QSpacerItem* lastRowSpacer; - //public slots: // void setEndpointHandlers(std::vector *ephs);