main window behaving as overlay
This commit is contained in:
parent
90286b6853
commit
9d79757a49
3 changed files with 47 additions and 39 deletions
|
|
@ -40,7 +40,7 @@ QRect MainWindow::setSizePosition(int width, int height) {
|
|||
availableRes.getCoords(&arx1, &ary1, &arx2, &ary2);
|
||||
|
||||
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;
|
||||
|
||||
switch (pos) {
|
||||
|
|
@ -51,7 +51,7 @@ QRect MainWindow::setSizePosition(int width, int height) {
|
|||
return QRect(arx1, (ary2-height), width, height);
|
||||
break;
|
||||
case SpawnPos::DOWN | SpawnPos::RIGHT:
|
||||
return QRect((arx2 - width), (ary2-height), windowWidth, height);
|
||||
return QRect((arx2 - width), (ary2-height), width, height);
|
||||
break;
|
||||
default:
|
||||
return QRect(500, 400, width, height);
|
||||
|
|
@ -61,18 +61,21 @@ 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: MenuBar height
|
||||
//TODO: more heights
|
||||
this->setAttribute(Qt::WA_DontShowOnScreen, true);
|
||||
this->show();
|
||||
this->layout()->invalidate();
|
||||
this->hide();
|
||||
this->setAttribute(Qt::WA_DontShowOnScreen, false);
|
||||
|
||||
|
||||
int height = 0, width = 0;
|
||||
for (auto *epw : this->ews) {
|
||||
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
|
||||
|
|
@ -181,14 +184,15 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
|
|||
this->channelCount = channelCount;
|
||||
widgetLayout = new QGridLayout(this);
|
||||
float volume = 100;
|
||||
|
||||
/*
|
||||
* Channel sliders setup
|
||||
*/
|
||||
//uint32_t epChannelCount = eph->getChannelCount();
|
||||
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("");
|
||||
tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
//tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
tmp->setTickInterval(5);
|
||||
tmp->setSingleStep(1);
|
||||
tmp->setRange(0,100);
|
||||
|
|
@ -196,6 +200,7 @@ ChannelWidget::ChannelWidget(uint32_t channelCount, EndpointHandler* eph, QWidge
|
|||
volume = eph->getVolume(i) * 100;
|
||||
tmp->setValue((int) volume);
|
||||
tmpLb->setText(QString::number(volume));
|
||||
//tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
this->channelSliders.push_back(tmp);
|
||||
this->channelLabels.push_back(tmpLb);
|
||||
widgetLayout->addWidget(tmp, 0, i);
|
||||
|
|
@ -219,7 +224,7 @@ void ChannelWidget::updateChannel(int channel) {
|
|||
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
|
||||
row = 0;
|
||||
this->idx = idx;
|
||||
|
|
@ -234,9 +239,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
|
|||
if (parent == nullptr) { log_debugcpp("ayooooo?"); }
|
||||
|
||||
defaultRolesCheckBoxes = {
|
||||
{Roles::ROLE_ALL, new ExtendedCheckBox(this)},
|
||||
{Roles::ROLE_CONSOLE, new ExtendedCheckBox(this)},
|
||||
{Roles::ROLE_MULTIMEDIA, new ExtendedCheckBox(this)},
|
||||
{Roles::ROLE_ALL, new ExtendedCheckBox(this)},
|
||||
{Roles::ROLE_CONSOLE, new ExtendedCheckBox(this)},
|
||||
{Roles::ROLE_MULTIMEDIA, 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) {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
@ -258,14 +263,14 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
|
|||
//mainLabel->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
|
||||
|
||||
//muteButton->setStyleSheet("background-color: #A3C1DA; color: red");
|
||||
mainSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
mainSlider->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Expanding);
|
||||
mainSlider->setFocusPolicy(Qt::StrongFocus);
|
||||
mainSlider->setTickPosition(QSlider::TicksBothSides);
|
||||
mainSlider->setTickInterval(5);
|
||||
mainSlider->setSingleStep(1);
|
||||
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);
|
||||
float volume = eph->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
|
||||
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(muteButton, row, 1, 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();
|
||||
row++;
|
||||
|
||||
|
|
@ -292,6 +297,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
|
|||
uint32_t epChannelCount = eph->getChannelCount();
|
||||
if(epChannelCount) {
|
||||
cw = new ChannelWidget(epChannelCount, eph, this);
|
||||
//cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/);
|
||||
}
|
||||
|
||||
|
|
@ -369,11 +375,13 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
|
|||
/* First SessionWidget 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);
|
||||
widgetLayout->addWidget(sessionWidget, row, 0, 1, 4 /* colmax */);
|
||||
row++;
|
||||
sessionWidgets.push_back(sessionWidget);
|
||||
eph->getSessionHandlers().at(i)->setFrontIndex(i);
|
||||
}
|
||||
/* This spacer provides proper spacing when window vertically > widgets */
|
||||
//widgetLayout->addItem(&lastRowSpacer, row, 0);
|
||||
|
||||
/* Add/Remove SessionWidget callback */
|
||||
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));
|
||||
});
|
||||
|
||||
//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");
|
||||
}
|
||||
|
||||
|
|
@ -455,7 +458,8 @@ void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* 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);
|
||||
ews.push_back(epw);
|
||||
return;
|
||||
|
|
@ -573,16 +577,16 @@ HeaderWidget::HeaderWidget(QWidget *parent) : QWidget(parent) {
|
|||
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);
|
||||
//setCentralWidget(centralWidget);
|
||||
//todo: ratio
|
||||
//resize(windowWidth, 440);
|
||||
setWindowFlags(Qt::Window | Qt::MSWindowsFixedSizeDialogHint);
|
||||
#ifdef DEBUG
|
||||
setWindowFlags(Qt::FramelessWindowHint | Qt::ToolTip);
|
||||
setWindowTitle(STRING_TITLE);
|
||||
setWindowFlags(Qt::FramelessWindowHint);
|
||||
#endif
|
||||
connect(qApp, &QGuiApplication::applicationStateChanged, this, [=](Qt::ApplicationState state){
|
||||
if(state == Qt::ApplicationState::ApplicationInactive) hide();
|
||||
});
|
||||
/*
|
||||
* Registering needed custom events
|
||||
*/
|
||||
|
|
@ -619,7 +623,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
|
||||
scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
|
||||
scrollArea->setStyleSheet("QScrollBar:vertical { width: 4px; }");
|
||||
scrollArea->setMinimumWidth(500);
|
||||
//scrollArea->setMinimumWidth(500);
|
||||
setCentralWidget(scrollArea);
|
||||
|
||||
/*
|
||||
|
|
@ -705,6 +709,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
|
||||
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
|
|
@ -724,6 +729,7 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||
case QSystemTrayIcon::Trigger:
|
||||
this->calculateChildWidgetsSize();
|
||||
this->showNormal();
|
||||
this->activateWindow();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
|
@ -732,6 +738,7 @@ void MainWindow::trayIconActivated(QSystemTrayIcon::ActivationReason reason) {
|
|||
|
||||
void MainWindow::reloadEndpointWidgets() {
|
||||
size_t i = 0;
|
||||
//widgetLayout->addItem(&lastRowSpacer, i++, 0);
|
||||
for (size_t epwIndex = 0; i < (osh->getPlaybackEndpointHandlers().size()); i++) {
|
||||
if (osh->getPlaybackEndpointHandlers().at(i)->getState() == EndpointState::ENDPOINT_ACTIVE){
|
||||
log_debugcpp("EPWidget creation");
|
||||
|
|
@ -744,6 +751,8 @@ void MainWindow::reloadEndpointWidgets() {
|
|||
}
|
||||
}
|
||||
//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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -230,8 +230,11 @@ private:
|
|||
HeaderWidget* hw;
|
||||
QMenuBar *mainMenuBar;
|
||||
QScreen *screen;
|
||||
//todo: ratio
|
||||
//Win10 1080p 120%
|
||||
QSize mwSize;
|
||||
QSpacerItem lastRowSpacer;
|
||||
|
||||
|
||||
//public slots:
|
||||
// void setEndpointHandlers(std::vector<EndpointHandler*> *ephs);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,3 @@
|
|||
//#include <stdio.h>
|
||||
//#include <stdlib.h>
|
||||
|
||||
//#include <qapplicationstatic.h>
|
||||
|
||||
//#define QTBLESSED
|
||||
#include <QApplication>
|
||||
#include <QMainWindow>
|
||||
|
||||
|
|
@ -66,10 +60,12 @@ int main (int argc, char* argv[]) {
|
|||
*/
|
||||
|
||||
//app->setStyleSheet(styleSheet);
|
||||
window.calculateChildWidgetsSize();
|
||||
#ifdef DEBUG
|
||||
window.show();
|
||||
#endif
|
||||
/*
|
||||
* #ifdef DEBUG
|
||||
* window.calculateChildWidgetsSize();
|
||||
* window.show();
|
||||
* #endif
|
||||
*/
|
||||
return app->exec();
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue