main window behaving as overlay

This commit is contained in:
Hane 2024-04-06 18:42:19 +02:00
commit 9d79757a49
3 changed files with 47 additions and 39 deletions

View file

@ -40,7 +40,7 @@ QRect MainWindow::setSizePosition(int width, int height) {
availableRes.getCoords(&arx1, &ary1, &arx2, &ary2); availableRes.getCoords(&arx1, &ary1, &arx2, &ary2);
uint8_t pos = 0; uint8_t pos = 0;
pos = tiy2 < (sry2 / 2) ? SpawnPos::UP : SpawnPos::DOWN; pos = tiy2 < (sry2 / 2) ? SpawnPos::UP : SpawnPos::DOWN;
pos = tix2 < (srx2 / 2) ? pos | SpawnPos::LEFT : pos | SpawnPos::RIGHT; pos = tix2 < (srx2 / 2) ? pos | SpawnPos::LEFT : pos | SpawnPos::RIGHT;
switch (pos) { switch (pos) {
@ -51,7 +51,7 @@ QRect MainWindow::setSizePosition(int width, int height) {
return QRect(arx1, (ary2-height), width, height); return QRect(arx1, (ary2-height), width, height);
break; break;
case SpawnPos::DOWN | SpawnPos::RIGHT: case SpawnPos::DOWN | SpawnPos::RIGHT:
return QRect((arx2 - width), (ary2-height), windowWidth, height); return QRect((arx2 - width), (ary2-height), width, height);
break; break;
default: default:
return QRect(500, 400, width, height); return QRect(500, 400, width, height);
@ -61,7 +61,7 @@ QRect MainWindow::setSizePosition(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: MenuBar height //TODO: more heights
this->setAttribute(Qt::WA_DontShowOnScreen, true); this->setAttribute(Qt::WA_DontShowOnScreen, true);
this->show(); this->show();
this->layout()->invalidate(); this->layout()->invalidate();
@ -71,8 +71,11 @@ void MainWindow::calculateChildWidgetsSize() {
int height = 0, width = 0; int height = 0, width = 0;
for (auto *epw : this->ews) { for (auto *epw : this->ews) {
height += epw->height(); height += epw->height();
width = (epw->width() > width) ? epw->width() : width; //width = (epw->width() > width) ? epw->width() : width;
} }
width = scrollArea->width();
height += mainMenuBar->height();
height += hw->height();
/* /*
* Establishing initial window size and position * Establishing initial window size and position
@ -181,14 +184,15 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
this->channelCount = channelCount; this->channelCount = channelCount;
widgetLayout = new QGridLayout(this); widgetLayout = new QGridLayout(this);
float volume = 100; float volume = 100;
/* /*
* Channel sliders setup * Channel sliders setup
*/ */
//uint32_t epChannelCount = eph->getChannelCount(); //uint32_t epChannelCount = eph->getChannelCount();
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("");
tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); //tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
tmp->setTickInterval(5); tmp->setTickInterval(5);
tmp->setSingleStep(1); tmp->setSingleStep(1);
tmp->setRange(0,100); tmp->setRange(0,100);
@ -196,6 +200,7 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
volume = eph->getVolume(i) * 100; volume = eph->getVolume(i) * 100;
tmp->setValue((int) volume); tmp->setValue((int) volume);
tmpLb->setText(QString::number(volume)); tmpLb->setText(QString::number(volume));
//tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
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);
@ -219,7 +224,7 @@ void ChannelWidget::updateChannel(int channel) {
this->channelSliders.at(channel)->blockSignals(false); this->channelSliders.at(channel)->blockSignals(false);
} }
EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent){ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *parent) : QWidget(parent) {
//todo: based on qgridlayout, name+mute should be its own widget, same with channels //todo: based on qgridlayout, name+mute should be its own widget, same with channels
row = 0; row = 0;
this->idx = idx; this->idx = idx;
@ -234,9 +239,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
if (parent == nullptr) { log_debugcpp("ayooooo?"); } if (parent == nullptr) { log_debugcpp("ayooooo?"); }
defaultRolesCheckBoxes = { defaultRolesCheckBoxes = {
{Roles::ROLE_ALL, new ExtendedCheckBox(this)}, {Roles::ROLE_ALL, new ExtendedCheckBox(this)},
{Roles::ROLE_CONSOLE, new ExtendedCheckBox(this)}, {Roles::ROLE_CONSOLE, new ExtendedCheckBox(this)},
{Roles::ROLE_MULTIMEDIA, new ExtendedCheckBox(this)}, {Roles::ROLE_MULTIMEDIA, new ExtendedCheckBox(this)},
{Roles::ROLE_COMMUNICATIONS, new ExtendedCheckBox(this)} {Roles::ROLE_COMMUNICATIONS, new ExtendedCheckBox(this)}
}; };
@ -249,7 +254,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
if (this->eph->getState() != EndpointState::ENDPOINT_ACTIVE) { if (this->eph->getState() != EndpointState::ENDPOINT_ACTIVE) {
widgetLayout->addWidget(mainLabel, row, 0); widgetLayout->addWidget(mainLabel, row, 0);
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0); //widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
return; return;
} }
@ -258,14 +263,14 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
//mainLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed); //mainLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
//muteButton->setStyleSheet("background-color: #A3C1DA; color: red"); //muteButton->setStyleSheet("background-color: #A3C1DA; color: red");
mainSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); mainSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
mainSlider->setFocusPolicy(Qt::StrongFocus); mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides); mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5); mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1); mainSlider->setSingleStep(1);
mainSlider->setRange(0,100); mainSlider->setRange(0,100);
muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked)); muteButton->setCheckState((eph->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE); muteButton->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100; float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
mainSlider->setValue((int)volume); mainSlider->setValue((int)volume);
@ -276,7 +281,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
widgetLayout->addWidget(mainLabel, row, 0, Qt::AlignLeft | Qt::AlignVCenter); widgetLayout->addWidget(mainLabel, row, 0, Qt::AlignLeft | Qt::AlignVCenter);
widgetLayout->addWidget(muteButton, row, 1, Qt::AlignLeft | Qt::AlignVCenter); widgetLayout->addWidget(muteButton, row, 1, Qt::AlignLeft | Qt::AlignVCenter);
widgetLayout->addWidget(mainSlider, row, 2, 1, 2, Qt::AlignLeft | Qt::AlignVCenter); widgetLayout->addWidget(mainSlider, row, 2, 1, 2, Qt::AlignLeft | Qt::AlignVCenter);
widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize); //widgetLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
//int debug2 = this->minimumWidth(); //int debug2 = this->minimumWidth();
row++; row++;
@ -292,6 +297,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
uint32_t epChannelCount = eph->getChannelCount(); uint32_t epChannelCount = eph->getChannelCount();
if(epChannelCount) { if(epChannelCount) {
cw = new ChannelWidget(epChannelCount, eph, this); 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*/);
} }
@ -369,11 +375,13 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
/* First SessionWidget batch */ /* First SessionWidget 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); widgetLayout->addWidget(sessionWidget, row, 0, 1, 4 /* colmax */);
row++; row++;
sessionWidgets.push_back(sessionWidget); sessionWidgets.push_back(sessionWidget);
eph->getSessionHandlers().at(i)->setFrontIndex(i); eph->getSessionHandlers().at(i)->setFrontIndex(i);
} }
/* This spacer provides proper spacing when window vertically > widgets */
//widgetLayout->addItem(&lastRowSpacer, row, 0);
/* Add/Remove SessionWidget callback */ /* Add/Remove SessionWidget callback */
eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) { eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) {
@ -384,11 +392,6 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<SessionHandler*>((QEvent::Type)CustomQEvent::SessionWidgetObsolete, sessionHandler)); QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<SessionHandler*>((QEvent::Type)CustomQEvent::SessionWidgetObsolete, sessionHandler));
}); });
//todo parent?
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 4, 0);
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 6, 0);
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 6, 1);
log_debugcpp("ENDPOINT_WIDGETED"); log_debugcpp("ENDPOINT_WIDGETED");
} }
@ -456,6 +459,7 @@ void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev){
void MainWindow::addEndpointWidget(CustomWidgetEvent<EndpointHandler*>* ev){ void MainWindow::addEndpointWidget(CustomWidgetEvent<EndpointHandler*>* ev){
EndpointWidget* epw = new EndpointWidget(this->ews.size(), ev->payload, widget); EndpointWidget* epw = new EndpointWidget(this->ews.size(), ev->payload, widget);
//epw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
this->widgetLayout->addWidget(epw); this->widgetLayout->addWidget(epw);
ews.push_back(epw); ews.push_back(epw);
return; return;
@ -573,16 +577,16 @@ HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) {
this->setLayout(widgetLayout); this->setLayout(widgetLayout);
} }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), lastRowSpacer(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding) {
//setWindowState(Qt::WindowFullScreen); //setWindowState(Qt::WindowFullScreen);
//setCentralWidget(centralWidget); //setCentralWidget(centralWidget);
//todo: ratio //todo: ratio
//resize(windowWidth, 440);
setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint); setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint);
#ifdef DEBUG setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
setWindowTitle(STRING_TITLE); setWindowTitle(STRING_TITLE);
setWindowFlags(Qt::FramelessWindowHint); connect(qApp, &QGuiApplication::applicationStateChanged, this, [=](Qt::ApplicationState state){
#endif if(state == Qt::ApplicationState::ApplicationInactive) hide();
});
/* /*
* Registering needed custom events * Registering needed custom events
*/ */
@ -619,7 +623,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn); scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
scrollArea->setStyleSheet("QScrollBar:vertical { width: 4px; }"); scrollArea->setStyleSheet("QScrollBar:vertical { width: 4px; }");
scrollArea->setMinimumWidth(500); //scrollArea->setMinimumWidth(500);
setCentralWidget(scrollArea); setCentralWidget(scrollArea);
/* /*
@ -705,6 +709,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) { osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph)); QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
}); });
} }
void MainWindow::closeEvent(QCloseEvent *event) { void MainWindow::closeEvent(QCloseEvent *event) {
@ -724,6 +729,7 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
case QSystemTrayIcon::Trigger: case QSystemTrayIcon::Trigger:
this->calculateChildWidgetsSize(); this->calculateChildWidgetsSize();
this->showNormal(); this->showNormal();
this->activateWindow();
break; break;
default: default:
break; break;
@ -732,6 +738,7 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
void MainWindow::reloadEndpointWidgets() { void MainWindow::reloadEndpointWidgets() {
size_t i = 0; size_t i = 0;
//widgetLayout->addItem(&lastRowSpacer, i++, 0);
for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) { for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) {
if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){ if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){
log_debugcpp("EPWidget creation"); log_debugcpp("EPWidget creation");
@ -744,6 +751,8 @@ void MainWindow::reloadEndpointWidgets() {
} }
} }
//todo:: tas aqui tirao, no me gustas y probablemente yo a ti tampoco //todo:: tas aqui tirao, no me gustas y probablemente yo a ti tampoco
widgetLayout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0); //seguramente falle al querer rematar esto con redimensionar la ventana sólo
//con los default endpoints en vista
widgetLayout->addItem(&lastRowSpacer, i, 0);
} }

View file

@ -230,8 +230,11 @@ private:
HeaderWidget* hw; HeaderWidget* hw;
QMenuBar *mainMenuBar; QMenuBar *mainMenuBar;
QScreen *screen; QScreen *screen;
//todo: ratio
//Win10 1080p 120% //Win10 1080p 120%
QSize mwSize; QSize mwSize;
QSpacerItem lastRowSpacer;
//public slots: //public slots:
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs); // void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);

View file

@ -1,9 +1,3 @@
//#include <stdio.h>
//#include <stdlib.h>
//#include <qapplicationstatic.h>
//#define QTBLESSED
#include <QApplication> #include <QApplication>
#include <QMainWindow> #include <QMainWindow>
@ -66,10 +60,12 @@ int main (int argc, char* argv[]) {
*/ */
//app->setStyleSheet(styleSheet); //app->setStyleSheet(styleSheet);
window.calculateChildWidgetsSize(); /*
#ifdef DEBUG * #ifdef DEBUG
window.show(); * window.calculateChildWidgetsSize();
#endif * window.show();
* #endif
*/
return app->exec(); return app->exec();
} }