add session

This commit is contained in:
Hane 2024-02-03 18:52:18 +01:00
commit 0dd016bb16
6 changed files with 79 additions and 28 deletions

View file

@ -1,7 +1,7 @@
#include "qtclasses.h"
template <typename T>
EndpointWidgetEvent<T>::EndpointWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
CustomWidgetEvent<T>::CustomWidgetEvent(QEvent::Type type, T payload) : QEvent(type){
this->payload = payload;
}
@ -97,7 +97,7 @@ void SessionWidget::updateMainVolume(int newValue){
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
int row = 0;
row = 0;
this->idx = idx;
this->eph = eph;
//todo: sussy
@ -255,13 +255,18 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
});
timer->start(10);
/* sessions */
/* First SessionWidget batch */
for (size_t i = 0; i < eph->getSessionCount(); i++) {
SessionWidget* sessionWidget = new SessionWidget(i, eph->getSessionHandlers().at(i), this);
layout->addWidget(sessionWidget, row, 4);
row++;
sessionWidgets.push_back(sessionWidget);
}
/* New SessionWidget callback */
eph->setAddSessionWidgetFunction([this](SessionHandler* sessionHandler) {
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<SessionHandler*>((QEvent::Type)CustomQEvent::SessionWidgetCreated, sessionHandler));
});
//todo parent?
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
@ -271,6 +276,28 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
log_debugcpp("ENDPOINT_WIDGETED");
}
void EndpointWidget::addSessionWidget(CustomWidgetEvent<SessionHandler*>* ev){
SessionWidget* sw = new SessionWidget(this->sessionWidgets.size(), ev->payload, this);
this->layout->addWidget(sw, row, 4);
row++;
sessionWidgets.push_back(sw);
return;
}
void EndpointWidget::customEvent(QEvent* ev) {
if (ev->type() == (QEvent::Type)CustomQEvent::SessionWidgetCreated) {
ev->setAccepted(true);
this->addSessionWidget((CustomWidgetEvent<SessionHandler*>*) ev);
return;
} else if (ev->type() == (QEvent::Type)CustomQEvent::SessionWidgetObsolete) {
ev->setAccepted(true);
//this->addEndpointWidget((CustomWidgetEvent<EndpointHandler*>*)ev);
}
// Make sure the rest of events are handled
QWidget::customEvent(ev);
}
EndpointWidget::~EndpointWidget() {
timer->stop();
delete timer;
@ -280,17 +307,17 @@ EndpointWidget::~EndpointWidget() {
void MainWindow::customEvent(QEvent* ev) {
if (ev->type() == CustomQEvent::EndpointWidgetObsolete) {
ev->setAccepted(true);
this->removeEndpointWidget((EndpointWidgetEvent<uint64_t>*)ev);
this->removeEndpointWidget((CustomWidgetEvent<uint64_t>*)ev);
return;
} else if (ev->type() == (QEvent::Type)CustomQEvent::EndpointWidgetCreated) {
ev->setAccepted(true);
this->addEndpointWidget((EndpointWidgetEvent<EndpointHandler*>*)ev);
this->addEndpointWidget((CustomWidgetEvent<EndpointHandler*>*)ev);
}
// Make sure the rest of events are handled
QMainWindow::customEvent(ev);
}
void MainWindow::removeEndpointWidget(EndpointWidgetEvent<uint64_t>* ev){
void MainWindow::removeEndpointWidget(CustomWidgetEvent<uint64_t>* ev){
uint64_t i = ev->payload;
this->ews.at(i)->setParent(nullptr);
this->layout->removeWidget(ews.at(i));
@ -311,7 +338,7 @@ void MainWindow::removeEndpointWidget(EndpointWidgetEvent<uint64_t>* ev){
return;
}
void MainWindow::addEndpointWidget(EndpointWidgetEvent<EndpointHandler*>* ev){
void MainWindow::addEndpointWidget(CustomWidgetEvent<EndpointHandler*>* ev){
EndpointWidget* epw = new EndpointWidget(this->ews.size(), ev->payload, widget);
this->layout->addWidget(epw);
ews.push_back(epw);
@ -497,11 +524,11 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
});
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
QCoreApplication::instance()->postEvent(this, new EndpointWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<uint64_t>((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index));
});
osh->setAddEndpointWidgetFunction([this](EndpointHandler* eph) {
QCoreApplication::instance()->postEvent(this, new EndpointWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
QCoreApplication::instance()->postEvent(this, new CustomWidgetEvent<EndpointHandler*>((QEvent::Type)CustomQEvent::EndpointWidgetCreated, eph));
});
}