wip: no endpoint, role rework, visual ratio
This commit is contained in:
parent
e42dbaa194
commit
d4db24ed7d
12 changed files with 184 additions and 57 deletions
|
|
@ -245,10 +245,17 @@ void MainWindow::compose() {
|
|||
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));
|
||||
|
||||
uint64_t windowWidth = (uint64_t)std::abs(screenRes.width()) * this->widthRatio;
|
||||
dpr = screen->devicePixelRatio();
|
||||
log_to_file("dpr: %f \n", dpr);
|
||||
uint64_t windowWidth = ((uint64_t)std::abs(screenRes.width()) * widthRatio) * dpr;
|
||||
uint64_t screenHeight = (uint64_t)std::abs(screenRes.height());
|
||||
log_debugcpp("Window Width: " + std::to_string(windowWidth));
|
||||
|
||||
QFontMetrics fontMetrics = this->fontMetrics();
|
||||
int maxCharWidth = fontMetrics.maxWidth();
|
||||
int charHeight = fontMetrics.height();
|
||||
//QSize QFontMetrics::size(int flags, const QString &text, int tabStops = 0, int *tabArray = nullptr) const
|
||||
|
||||
this->createLayout(new QGridLayout());
|
||||
//scrollArea->verticalScrollBar()->setMinimumWidth(windowWidth * (widthRatio));
|
||||
//scrollArea->verticalScrollBar()->setMaximumWidth(windowWidth * (widthRatio));
|
||||
|
|
@ -259,8 +266,7 @@ void MainWindow::compose() {
|
|||
* this->hide();
|
||||
* this->setAttribute(Qt::WA_DontShowOnScreen, false);
|
||||
*/
|
||||
const qreal dpr = screen->devicePixelRatio();
|
||||
log_to_file("dpr: %f \n", dpr);
|
||||
|
||||
for (auto *epw : ews) {
|
||||
if (!epw) continue;
|
||||
epw->calculateSize(windowWidth, screenHeight);
|
||||
|
|
@ -396,7 +402,7 @@ void SessionWidget::calculateSize(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->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*/);
|
||||
|
|
@ -410,7 +416,9 @@ void SessionWidget::calculateSize(uint64_t width, uint64_t height) {
|
|||
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());
|
||||
log_to_file("\tSlider Maximum width: %d \n", mainSlider->maximumWidth());
|
||||
log_to_file("\tSpacer Minimum width: %d \n", widthSpacer->minimumSize().width());
|
||||
log_to_file("\tSpacer Maximum width: %d \n\n", widthSpacer->maximumSize().width());
|
||||
}
|
||||
|
||||
std::wstring SessionWidget::getName() {
|
||||
|
|
@ -457,8 +465,10 @@ 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::Minimum, QSizePolicy::Minimum);
|
||||
tmpLb->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
//tmp->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum);
|
||||
tmp->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
//mainSlider->setFocusPolicy(Qt::StrongFocus);
|
||||
tmpLb->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
this->channelSliders.push_back(tmp);
|
||||
this->channelLabels.push_back(tmpLb);
|
||||
widgetLayout->addWidget(tmp, row , col);
|
||||
|
|
@ -505,7 +515,6 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i
|
|||
//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);
|
||||
log_debugcpp("epw main layout parent: " + std::to_string((intptr_t)(widgetLayout->parent())));
|
||||
|
|
@ -575,6 +584,7 @@ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent, uint64_t i
|
|||
uint32_t epChannelCount = eph->getChannelCount();
|
||||
if(epChannelCount > 1) {
|
||||
cw = new ChannelWidget(epChannelCount, eph, nullptr);
|
||||
cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
||||
//cw->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
|
||||
widgetLayout->addWidget(cw, row++, 0, 1, 4 /*colmax*/, Qt::AlignTop);
|
||||
}
|
||||
|
|
@ -672,7 +682,8 @@ void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
|
|||
for (QWidget *widget : topLevelWidgets) {
|
||||
if (qobject_cast<MainWindow*>(widget)) {
|
||||
double widthRatio = ((MainWindow*)widget)->widthRatio;
|
||||
sw->calculateSize(std::abs(this->screen()->geometry().width()) * widthRatio,
|
||||
double dpr = ((MainWindow*)widget)->dpr;
|
||||
sw->calculateSize((std::abs(this->screen()->geometry().width()) * widthRatio) * dpr,
|
||||
std::abs(this->screen()->geometry().height()));
|
||||
}
|
||||
}
|
||||
|
|
@ -726,6 +737,9 @@ void MainWindow::customEvent(QEvent* ev) {
|
|||
} else if (ev->type() == (QEvent::Type)CustomQEvent::RecomposeMainWindow) {
|
||||
ev->setAccepted(true);
|
||||
if (this->isVisible()) this->compose();
|
||||
} else if (ev->type() == (QEvent::Type)CustomQEvent::EndpointRoleChange) {
|
||||
ev->setAccepted(true);
|
||||
this->flushRoleChanges();
|
||||
}
|
||||
QMainWindow::customEvent(ev);
|
||||
}
|
||||
|
|
@ -783,14 +797,27 @@ void MainWindow::reorderEndpointWidgetCollection() {
|
|||
void EndpointWidget::calculateSize(uint64_t width, uint64_t height) {
|
||||
/* og 1080p 120% testing values */
|
||||
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("Params: {WWidth: %u SHeight: %u}\n", width, height);
|
||||
//this->setMaximumWidth(width);
|
||||
/*
|
||||
* this->mainLabel->setMaximumWidth((int)(width * 0.50) /\* 1080p 120%*\/);
|
||||
* this->mainLabel->setMinimumWidth((int)(width * 0.50) /\* 1080p 120%*\/);
|
||||
*/
|
||||
this->mainLabel->setMaximumSize((int)(width * 0.50), height /* 1080p 120%*/);
|
||||
this->mainLabel->setMinimumSize((int)(width * 0.50), 1 /* 1080p 120%*/);
|
||||
this->muteButton->setMaximumSize((int)(width * 0.10), height /* 1080p 120%*/);
|
||||
this->mainVolumeLabel->setMaximumSize((int)(width * 0.10), height /* 1080p 120%*/);
|
||||
for (auto roleCheckbox : defaultRolesCheckBoxes) {
|
||||
roleCheckbox.second->setMaximumWidth((int)(width * 0.20) /* 1080p 120%*/);
|
||||
log_to_file("Role %d width: %d \n", roleCheckbox.first, roleCheckbox.second->maximumWidth());
|
||||
}
|
||||
log_to_file("Main label width: %d \n", this->mainLabel->maximumWidth());
|
||||
log_to_file("Mute button width: %d \n", this->muteButton->maximumWidth());
|
||||
log_to_file("Volume label width: %d \n", this->mainVolumeLabel->maximumWidth());
|
||||
|
||||
if (cw) {
|
||||
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)));
|
||||
//this->cw->setMaximumSize(QSize(width, (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());
|
||||
}
|
||||
|
|
@ -889,15 +916,23 @@ void MainWindow::createLayout(QGridLayout *newLayout) {
|
|||
widget->setLayout(newLayout);
|
||||
this->widgetLayout = newLayout;
|
||||
|
||||
bool areEndpoints = false;
|
||||
uint64_t i = 0;
|
||||
for (EndpointWidget *epw : ews) {
|
||||
if (!epw) continue;
|
||||
else areEndpoints = true;
|
||||
log_debugcpp("EPWidget positioning");
|
||||
log_wdebugcpp(L"epw name: " + epw->getEndpointHandler()->getName());
|
||||
epw->setIndex(i);
|
||||
this->widgetLayout->addWidget(epw, i++, 0);
|
||||
}
|
||||
widgetLayout->addItem(lastRowSpacer, i, 0);
|
||||
if(areEndpoints)
|
||||
widgetLayout->addItem(lastRowSpacer, i, 0);
|
||||
else {
|
||||
if (noEndpoints) delete noEndpoints;
|
||||
noEndpoints = new QLabel(STRING_NOENDPOINT, this);
|
||||
widgetLayout->addWidget(noEndpoints, i, 0);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||
|
|
@ -910,6 +945,17 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
//setStyleSheet("background: transparent; ");
|
||||
//setStyleSheet("background-color: rgba(255,182,193);");
|
||||
setWindowTitle(STRING_TITLE);
|
||||
/*
|
||||
* Font setup
|
||||
*/
|
||||
int id = QFontDatabase::addApplicationFont(":/assets/selawk.ttf");
|
||||
QString family = QFontDatabase::applicationFontFamilies(id).at(0);
|
||||
font = QFont(family);
|
||||
font.setKerning(true);
|
||||
font.setPointSize(12);
|
||||
this->setFont(font);
|
||||
//qputenv("QT_AUTO_SCREEN_SCALE_FACTOR", "1");
|
||||
|
||||
/*
|
||||
* Registering needed custom events
|
||||
*/
|
||||
|
|
@ -920,9 +966,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
QEvent::registerEventType(CustomQEvent::SessionWidgetObsolete);
|
||||
QEvent::registerEventType(CustomQEvent::SessionWidgetCreated);
|
||||
QEvent::registerEventType(CustomQEvent::RecomposeMainWindow);
|
||||
QEvent::registerEventType(CustomQEvent::EndpointRoleChange);
|
||||
|
||||
/* This spacer provides proper spacing when window vertically > widgets. */
|
||||
lastRowSpacer = new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
||||
|
||||
ewsUpdateTimer = new QTimer(this);
|
||||
recentlyClosedTimer = new QTimer(this);
|
||||
widget = new QWidget();
|
||||
|
|
@ -945,6 +993,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
* Scroll bar code
|
||||
*/
|
||||
scrollArea = new QScrollArea(this);
|
||||
//widget->setAttribute(Qt::WA_TranslucentBackground);
|
||||
scrollArea->setWidget(widget);
|
||||
scrollArea->setWidgetResizable(true);
|
||||
scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
|
||||
|
|
@ -959,6 +1008,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
* Menu bar code
|
||||
*/
|
||||
mainMenuBar = new QToolBar(this);
|
||||
/*
|
||||
* QPalette pal;
|
||||
* pal.setColor(QPalette::Window, Qt::transparent);
|
||||
* mainMenuBar->setPalette(pal);
|
||||
*/
|
||||
hw = new HeaderWidget(this);
|
||||
mainMenuBar->addWidget(hw);
|
||||
mainMenuBar->setMovable(false);
|
||||
|
|
@ -993,26 +1047,72 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
this->recentlyClosedTimer->start();
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Set of function callback definitons for EndpointSituationCallback
|
||||
*/
|
||||
osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) {
|
||||
//Sigh... I hope to get this right when librole is done...
|
||||
//todo: STILL BORKED. THEY'RE NOT FORFEITING THEIR OLD POSITION
|
||||
EndpointWidget *newDef = nullptr, *oldDef = nullptr;
|
||||
for (uint64_t i = 0; i < ews.size(); i++) {
|
||||
auto epw = this->ews.at(i);
|
||||
if (!epw) continue;
|
||||
if (epw->getEndpointHandler()->getId() == endpointId) {
|
||||
newDef = epw;
|
||||
continue; }
|
||||
if (epw->getEndpointHandler()->getRoles() & role) {
|
||||
oldDef = epw;
|
||||
continue; }
|
||||
}
|
||||
osh->setRoleBucketEntryFunction([this](Roles role, std::wstring endpointId) {
|
||||
std::pair<Roles, std::wstring> entry = { role, endpointId };
|
||||
this->roleBucketList.push_back(entry);
|
||||
QCoreApplication::instance()->postEvent(this, new QEvent((QEvent::Type)CustomQEvent::EndpointRoleChange),Qt::LowEventPriority);
|
||||
});
|
||||
|
||||
//debug if (role != Roles::ROLE_COMMUNICATIONS) return;
|
||||
if (oldDef && newDef) {
|
||||
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
|
||||
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
|
||||
});
|
||||
|
||||
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
|
||||
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::flushRoleChanges() {
|
||||
std::pair<Roles, std::wstring> change = roleBucketList.back();
|
||||
roleBucketList.pop_back();
|
||||
this->changeFrontDefaults(change.first, change.second);
|
||||
}
|
||||
|
||||
void MainWindow::changeFrontDefaults(Roles role, std::wstring endpointId) {
|
||||
//Sigh... I hope to get this right when librole is done...
|
||||
//todo: STILL BORKED. THEY'RE NOT FORFEITING THEIR OLD POSITION
|
||||
EndpointWidget *newDef = nullptr, *oldDef = nullptr;
|
||||
for (uint64_t i = 0; i < ews.size(); i++) {
|
||||
auto epw = this->ews.at(i);
|
||||
if (!epw) continue;
|
||||
if (epw->getEndpointHandler()->getId() == endpointId) {
|
||||
newDef = epw;
|
||||
continue; }
|
||||
if (epw->getEndpointHandler()->getRoles() & role) {
|
||||
oldDef = epw;
|
||||
continue; }
|
||||
}
|
||||
|
||||
|
||||
//debug if (role != Roles::ROLE_COMMUNICATIONS) return;
|
||||
if (newDef && !oldDef) {
|
||||
newDef->getDefaultRolesWidgets().at(role)->blockSignals(true);
|
||||
newDef->getEndpointHandler()->assignRoles(role);
|
||||
QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(role), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
|
||||
uint8_t newDefIdx = newDef->getIndex();
|
||||
uint8_t newDefRoles = newDef->getEndpointHandler()->getRoles();
|
||||
if (newDefRoles == Roles::ROLE_ALL) {
|
||||
newDef->setIndex(0);
|
||||
this->ews[0] = newDef;
|
||||
if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr;
|
||||
QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
|
||||
} else if ((newDefRoles & Roles::ROLE_MULTIMEDIA) ||
|
||||
(newDefRoles & Roles::ROLE_CONSOLE)){
|
||||
newDef->setIndex(0);
|
||||
this->ews[0] = newDef;
|
||||
} else if (newDefRoles & Roles::ROLE_COMMUNICATIONS) {
|
||||
newDef->setIndex(1);
|
||||
this->ews[1] = newDef;
|
||||
}
|
||||
log_debugcpp("newDef new idx: " + std::to_string(newDef->getIndex()));
|
||||
newDef->getDefaultRolesWidgets().at(role)->blockSignals(false);
|
||||
}
|
||||
else if (oldDef && newDef) {
|
||||
this->ews.at(oldDef->getIndex()) = nullptr;
|
||||
this->ews.at(newDef->getIndex()) = nullptr;
|
||||
newDef->getDefaultRolesWidgets().at(role)->blockSignals(true);
|
||||
|
|
@ -1023,6 +1123,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
if (newDefRoles == Roles::ROLE_ALL) {
|
||||
newDef->setIndex(0);
|
||||
this->ews[0] = newDef;
|
||||
if (this->ews[1] && newDef->getEndpointHandler()->getId() == endpointId) this->ews[1] = nullptr;
|
||||
QCoreApplication::instance()->postEvent(newDef->getDefaultRolesWidgets().at(Roles::ROLE_ALL), new QEvent((QEvent::Type)CustomQEvent::EndpointDefaultChange));
|
||||
} else if ((newDefRoles & Roles::ROLE_MULTIMEDIA) ||
|
||||
(newDefRoles & Roles::ROLE_CONSOLE)){
|
||||
|
|
@ -1060,19 +1161,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
}
|
||||
log_debugcpp("oldDef new idx: " + std::to_string(oldDef->getIndex()));
|
||||
oldDef->getDefaultRolesWidgets().at(role)->blockSignals(false);
|
||||
}
|
||||
QCoreApplication::instance()->postEvent
|
||||
(this, new QEvent((QEvent::Type)CustomQEvent::RecomposeMainWindow));
|
||||
});
|
||||
|
||||
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
|
||||
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
|
||||
});
|
||||
|
||||
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
|
||||
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
|
||||
});
|
||||
|
||||
}
|
||||
QCoreApplication::instance()->postEvent
|
||||
(this, new QEvent((QEvent::Type)CustomQEvent::RecomposeMainWindow));
|
||||
}
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue