session baby steps

This commit is contained in:
Hane 2023-09-18 23:37:06 +02:00
commit 7eb6e29ee6
14 changed files with 393 additions and 87 deletions

View file

@ -25,8 +25,56 @@ void ExtendedCheckBox::customEvent(QEvent* ev) {
QCheckBox::customEvent(ev);
}
SessionWidget::SessionWidget(uint64_t idx, SessionHandler* sh, QWidget *parent) : QWidget(parent){
//todo: based on qgridlayout, name+mute should be its own widget, same with channels
this->idx = idx;
this->sh = sh;
layout = new QGridLayout(this);
//this->setLayout(
muteButton = new QCheckBox(this);
mainLabel = new QLabel(QString::fromStdWString(sh->getName()), this);
mainSlider = new QSlider(Qt::Horizontal, this);
mainSlider->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
mainSlider->setFocusPolicy(Qt::StrongFocus);
mainSlider->setTickPosition(QSlider::TicksBothSides);
mainSlider->setTickInterval(5);
mainSlider->setSingleStep(1);
mainSlider->setRange(0,100);
muteButton->setCheckState((sh->getMute() == false ? Qt::Unchecked : Qt::Checked));
muteButton->setText(sh->getMute() ? STRING_UNMUTE : STRING_MUTE);
float volume = sh->getVolume(AudioChannel::CHANNEL_MAIN) * 100;
mainSlider->setValue((int)volume);
log_debugcpp("SESSION SET WITH VOLUME " + std::to_string(volume));
//tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout();
layout->addWidget(mainLabel, 0, 0, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(muteButton, 0, 1, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(mainSlider, 0, 2, 1, 2);
//TODO:0 = mute and muted, change volume = unmuted are client side tricks = 2 callbacks, one for volume, one for mute state. Implement as an user selectable option?
connect<void(QSlider::*)(int), void(SessionWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&SessionWidget::updateMainVolume);
connect<void(QCheckBox::*)(int), void(SessionWidget::*)(int)>(muteButton, &QCheckBox::stateChanged, this, (&SessionWidget::updateMute));
}
void SessionWidget::updateMute(int checked){
bool muted = (checked == 2 ? true : false);
this->sh->setMute(osh->getGuid(), muted);
this->muteButton->setText(this->sh->getMute() ? STRING_UNMUTE : STRING_MUTE);
}
void SessionWidget::updateMainVolume(int newValue){
this->sh->setVolume(osh->getGuid(), AudioChannel::CHANNEL_MAIN, 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;
this->idx = idx;
this->eph = eph;
//todo: sussy
@ -52,7 +100,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
mainSlider = new QSlider(Qt::Horizontal, this);
if (this->eph->getState() != EndpointState::ENDPOINT_ACTIVE) {
layout->addWidget(mainLabel, 0, 0);
layout->addWidget(mainLabel, row, 0);
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);
return;
}
@ -73,9 +121,10 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
//tip: would need to be new widget with layout in it
//mainMuteLayout = new QGridLayout();
layout->addWidget(mainLabel, 0, 0, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(muteButton, 0, 1, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(mainSlider, 0, 2, 1, 2);
layout->addWidget(mainLabel, row, 0, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(muteButton, row, 1, Qt::AlignLeft | Qt::AlignBottom);
layout->addWidget(mainSlider, row, 2, 1, 2);
row++;
//TODO:0 = mute and muted, change volume = unmuted are client side tricks = 2 callbacks, one for volume, one for mute state. Implement as an user selectable option?
connect<void(QSlider::*)(int), void(EndpointWidget::*)(int)>(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume);
@ -99,8 +148,9 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
tmpLb->setText(QString::number(volume));
this->channelSliders.push_back(tmp);
this->channelLabels.push_back(tmpLb);
layout->addWidget(tmp, 2, i);
layout->addWidget(tmpLb, 3, i);
layout->addWidget(tmp, row + 1, i);
layout->addWidget(tmpLb, row + 2, i);
//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){
@ -108,6 +158,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
this->channelLabels.at(i)->setText(QString::number(newValue));
});
}
row += 3;
/*
* Role ExtendedCheckBoxes setup
@ -145,11 +196,11 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
this->eph->setRoles(Roles::ROLE_COMMUNICATIONS);
});
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_ALL), 5, 0);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE), 5, 1);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA), 5, 2);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS), 5, 3);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_ALL), row, 0);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_CONSOLE), row, 1);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_MULTIMEDIA), row, 2);
layout->addWidget(defaultRolesCheckBoxes.at(Roles::ROLE_COMMUNICATIONS), row, 3);
row++;
/* ----------------------------------------------------------- */
/*
@ -158,6 +209,7 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
timer = new QTimer();
connect(timer, &QTimer::timeout, [this, eph](){
//if (memcmp(osh->callbackInfo[idx]->caller, osh->getGuid(), sizeof(NGuid)) == 0) return; CHECK IF THIS PROGRAM GENERATED THE FUNSIES IS NO LONGER IN USE FOR NOW.
//todo: global + constexpr + ratio
const float roundingFactor = 0.005;
mainSlider->blockSignals(true);
muteButton->blockSignals(true);
@ -179,6 +231,14 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
muteButton->blockSignals(false);
});
timer->start(10);
/* sessions */
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);
}
//todo parent?
layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::Minimum), 1, 0);