From 2115cdf50841d2320df737bf4bc5b0147ddb8b08 Mon Sep 17 00:00:00 2001 From: Hane Date: Thu, 25 Apr 2024 20:21:21 +0200 Subject: [PATCH] wip: detected width bug (channels) --- src/debug.h | 16 +++++++---- src/global.h | 3 ++- src/qt/qtclasses.cpp | 63 +++++++++++++++++++++++++++++++------------- src/qt/qtclasses.h | 7 +++-- src/qtestmain.cpp | 5 +--- 5 files changed, 63 insertions(+), 31 deletions(-) diff --git a/src/debug.h b/src/debug.h index 0f993b1..2878c37 100644 --- a/src/debug.h +++ b/src/debug.h @@ -3,17 +3,19 @@ #if defined (QT_DEBUG) || defined (DEBUG) || defined (_DEBUG) #ifdef INIT_FILELOG + std::wstring_convert, wchar_t> converter; FILE* fileLog; errno_t lfResult; bool writable = false; - bool initializeFileLogging() { + void inline initializeFileLogging() { lfResult = fopen_s(&fileLog, "log.txt", "w"); - if (!lfResult) return true; - else return false; + if (!lfResult) writable = true; + else writable = false; } #else + extern std::wstring_convert, wchar_t> converter; extern errno_t lfResult; extern FILE* fileLog; extern bool writable; @@ -53,10 +55,13 @@ std::bitset varToBitset(T info) { #endif -#define log_to_file(fmt, cnt) do { \ + +#define log_to_file_simple(fmt) log_to_file(fmt, "") +#define log_to_file(fmt, cnt...) do { \ if(writable) fprintf_s(fileLog, fmt, cnt); \ } while (0) + #define print_as_binary(len, type, info) varToBitset(info) #define close_file_log_buffer() do { \ @@ -67,7 +72,8 @@ std::bitset varToBitset(T info) { #define log_debugcpp(str) #define log_wdebugcpp(str) #define print_as_binary(len, type, info) -#define log_to_file(fmt, cnt) +#define log_to_file_simple(fmt) +#define log_to_file(fmt, cnt...) #define initialize_file_log() false #define close_file_log_buffer() #endif diff --git a/src/global.h b/src/global.h index a96a114..b8b9bcb 100644 --- a/src/global.h +++ b/src/global.h @@ -3,11 +3,12 @@ #define __STDC_WANT_LIB_EXT1__ 1 #include #include +#include +#include #include #include #include #include -#include #include #include "debug.h" diff --git a/src/qt/qtclasses.cpp b/src/qt/qtclasses.cpp index 7aee177..b7a90ba 100644 --- a/src/qt/qtclasses.cpp +++ b/src/qt/qtclasses.cpp @@ -78,10 +78,12 @@ QRect MainWindow::setSizePosition(QScreen* screen, int width, int height) { } void MainWindow::compose() { + //todo: invalidate layout when adding sessions with window open //We need dynamically added child widgets to expand so that we know their height /* * Setting correct widget widths and heights */ + log_to_file_simple("[Compose]\n"); screen = this->getCurrentScreen(); log_debugcpp("Screen: " + screen->model().toStdString() + " " + screen->name().toStdString()); @@ -160,7 +162,9 @@ SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) widgetLayout = new QHBoxLayout(this); //widgetLayout->setSizeConstraint(QLayout::SetFixedSize); widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); - widgetLayout->setContentsMargins(0, 10, 0, 10); + int left = 0, top = 0, right = 0, bottom = 0; + widgetLayout->getContentsMargins(&left, &top, &right, &bottom); + widgetLayout->setContentsMargins(0, top, 0, bottom); muteButton = new QCheckBox(this); mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this); @@ -236,7 +240,19 @@ void SessionWidget::calculateSize(uint64_t width, uint64_t height) { 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*/); + widthSpacer->changeSize((int)(width * 0.20), 1, QSizePolicy::Expanding, QSizePolicy::Minimum /*200*/); + + log_to_file("\t[Session %s sizes]\n", converter.to_bytes(this->getName()).c_str()); + log_to_file("\tMain label Maximum size: %d, %d \n", mainLabel->maximumWidth(), mainLabel->maximumHeight()); + log_to_file("\tMain label Minimum size: %d, %d \n", mainLabel->minimumWidth(), mainLabel->minimumHeight()); + log_to_file("\tMute btn Maximum width: %d \n", muteButton->maximumWidth()); + log_to_file("\tMute btn Minimum width: %d \n", muteButton->minimumWidth()); + log_to_file("\tSlider Minimum width: %d \n", mainSlider->minimumWidth()); + log_to_file("\tSpacer Minimum width: %d \n\n", widthSpacer->minimumSize().width()); +} + +std::wstring SessionWidget::getName() { + return sh->getName(); } void SessionWidget::updateMute(int checked){ @@ -257,6 +273,7 @@ SessionWidget::~SessionWidget() { ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ this->eph = eph; this->channelCount = channelCount; + this->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding); widgetLayout = new QGridLayout(this); float volume = 100; int left = 0, top = 0, right = 0, bottom = 0; @@ -267,31 +284,30 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge * Channel sliders setup */ //uint32_t epChannelCount = eph->getChannelCount(); - for(uint32_t i = 0; i < channelCount && channelCount > 1; i++){ + for(uint64_t channel = 0, col = 0, row = 0; channel < channelCount && channelCount > 1; channel++){ 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); tmp->setRange(0,100); - volume = eph->getVolume(i) * 100; + volume = eph->getVolume(channel) * 100; tmp->setValue((int) volume); tmpLb->setText(QString::number(volume)); //tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); - tmp->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); - tmpLb->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Minimum); + tmp->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); + tmpLb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); this->channelSliders.push_back(tmp); this->channelLabels.push_back(tmpLb); - widgetLayout->addWidget(tmp, 0, i); - widgetLayout->addWidget(tmpLb, 1, i); + widgetLayout->addWidget(tmp, row , col); + widgetLayout->addWidget(tmpLb, row + 1, col++); + if(channel % 2 != 0) { row += 2; col = 0; } //TODO: check if there's a need to prevent deadlocks; probably this will eventually turn into its own func //this causes channel bar desync when back -> front. blocksignals below fix it. huh. - connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ - this->eph->setVolume(osh->getGuid(), i, newValue); - this->channelLabels.at(i)->setText(QString::number(newValue)); + connect(tmp, &QSlider::valueChanged, [this, channel](int newValue){ + this->eph->setVolume(osh->getGuid(), channel, newValue); + this->channelLabels.at(channel)->setText(QString::number(newValue)); }); } this->setLayout(widgetLayout); @@ -314,6 +330,10 @@ void ChannelWidget::updateChannel(int channel) { this->channelSliders.at(channel)->blockSignals(false); } +uint32_t ChannelWidget::getChannelCount() const { + return channelCount; +} + EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t idx) : QWidget(parent) { //todo: based on qgridlayout, name+mute should be its own widget, same with channels row = 0; @@ -392,7 +412,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i uint32_t epChannelCount = eph->getChannelCount(); if(epChannelCount > 1) { - cw = new ChannelWidget(epChannelCount, eph, this); + cw = new ChannelWidget(epChannelCount, eph, nullptr); //cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/, Qt::AlignTop); } @@ -583,12 +603,17 @@ void MainWindow::reorderEndpointWidgetCollection() { void EndpointWidget::calculateSize(uint64_t width, uint64_t height) { /* og 1080p 120% testing values */ - this->mainLabel->setMaximumWidth((int)width * 0.50 /* 1080p 120%*/); - this->mainLabel->setMinimumWidth((int)width * 0.50 /* 1080p 120%*/); - + log_to_file("[EndpointWidget %s sizes]\n", converter.to_bytes(this->getEndpointHandler()->getName()).c_str()); + log_to_file("Params: {Width: %u Height: %u}\n", width, height); + this->mainLabel->setMaximumWidth((int)(width * 0.50) /* 1080p 120%*/); + this->mainLabel->setMinimumWidth((int)(width * 0.50) /* 1080p 120%*/); + log_to_file("Main label width: %d \n", this->mainLabel->maximumWidth()); + if (cw) { - this->cw->setMinimumSize(QSize(1, height * 0.06)); - this->cw->setMaximumSize(QSize(QWIDGETSIZE_MAX, height * 0.06)); + this->cw->setMinimumSize(QSize(1, (height * 0.06) * (int)((cw->getChannelCount() / 2) + 0.5))); + this->cw->setMaximumSize(QSize(QWIDGETSIZE_MAX, (height * 0.06) * (int)((cw->getChannelCount() / 2) + 0.5))); + log_to_file("Channels Maximum size: %d, %d \n", cw->maximumWidth(), cw->maximumHeight()); + log_to_file("Channels Minimum size: %d, %d \n", cw->minimumWidth(), cw->minimumHeight()); } for (auto sw : sessionWidgets){ if (sw) sw->calculateSize(width, height); diff --git a/src/qt/qtclasses.h b/src/qt/qtclasses.h index ab7b7e3..524c7bb 100644 --- a/src/qt/qtclasses.h +++ b/src/qt/qtclasses.h @@ -87,7 +87,9 @@ Q_OBJECT public: SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent /* = nullptr */); ~SessionWidget(); - void calculateSize(uint64_t width, uint64_t height); + void calculateSize(uint64_t width, uint64_t height); + std::wstring getName(); + public slots: void updateMainVolume(int newValue); void updateMute(int checked); @@ -111,7 +113,8 @@ public: //QSize minimumSizeHint() const override; //void setMinimum(QSize minimum); void updateChannel(int channel); - + uint32_t getChannelCount() const; + private: const double roundingFactor = 0.005; EndpointHandler* eph; diff --git a/src/qtestmain.cpp b/src/qtestmain.cpp index 5a11676..7f953c0 100644 --- a/src/qtestmain.cpp +++ b/src/qtestmain.cpp @@ -47,10 +47,7 @@ int main (int argc, char* argv[]) { //QApplication::setStyle("windowsvista"); //Check if running //https://stackoverflow.com/questions/48060989/qt-show-application-if-currently-running - writable = initialize_file_log(); - log_to_file("%d hola", 3); - //int bro = fprintf_s(fileLog, "hola\n"); - //bro = fprintf(fileLog, "hola"); + initialize_file_log(); atexit(closeDebugFileLog); //std::set_terminate(closeDebugFileLog2); if (!isSingleInstanceRunning("Mixer"))