wip chex still buggy + customEvent
This commit is contained in:
parent
1ec8897430
commit
80327f5bcc
6 changed files with 145 additions and 28 deletions
|
|
@ -1,9 +1,12 @@
|
|||
#include "qtclasses.h"
|
||||
|
||||
|
||||
EndpointWidgetEvent::EndpointWidgetEvent(QEvent::Type type, int idx) : QEvent(type){
|
||||
this->idx = idx;
|
||||
}
|
||||
|
||||
bool ExtendedCheckBox::event(QEvent* ev) {
|
||||
if (ev->type() == QEvent::User) {
|
||||
//todo: still prone to bugs; whack-a-mole to come
|
||||
this->blockSignals(true);
|
||||
if (this->isEnabled()) {
|
||||
this->setCheckState(Qt::Checked);
|
||||
|
|
@ -19,11 +22,11 @@ bool ExtendedCheckBox::event(QEvent* ev) {
|
|||
return QCheckBox::event(ev);
|
||||
}
|
||||
|
||||
|
||||
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
|
||||
this->idx = idx;
|
||||
this->eph = eph;
|
||||
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, idx);
|
||||
layout = new QGridLayout(this);
|
||||
//this->setLayout(layout);
|
||||
log_debugcpp("epw main layout parent: "<< layout->parent());
|
||||
|
|
@ -178,6 +181,31 @@ EndpointWidget::EndpointWidget(uint64_t idx, EndpointHandler* eph, QWidget *pare
|
|||
log_debugcpp("ENDPOINT_WIDGETED");
|
||||
}
|
||||
|
||||
void MainWindow::customEvent(QEvent* ev) {
|
||||
if (ev->type() == (QEvent::Type)CustomQEvent::EndpointWidgetObsolete) {
|
||||
this->removeEndpointWidget((EndpointWidgetEvent*)ev);
|
||||
return;
|
||||
}
|
||||
// Make sure the rest of events are handled
|
||||
return QMainWindow::customEvent(ev);
|
||||
}
|
||||
|
||||
void MainWindow::removeEndpointWidget(EndpointWidgetEvent* ev){
|
||||
uint64_t i = ev->idx;
|
||||
this->ews.at(i)->setParent(nullptr);
|
||||
this->layout->removeWidget(ews.at(i));
|
||||
uint64_t saisu = ews.size();
|
||||
//delete ews.at(index);
|
||||
while ((i + 1) < ews.size()) {
|
||||
ews.at(i) = ews.at(i + 1);
|
||||
ews.at(i)->updateEndpointHandlerFrontInfo(i);
|
||||
i++;
|
||||
}
|
||||
ews.pop_back();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void EndpointWidget::updateMute(int checked){
|
||||
bool muted = (checked == 2 ? true : false);
|
||||
this->eph->setMute(osh->getGuid(), muted);
|
||||
|
|
@ -223,6 +251,11 @@ EndpointHandler* EndpointWidget::getEndpointHandler(){
|
|||
return this->eph;
|
||||
}
|
||||
|
||||
void EndpointWidget::updateEndpointHandlerFrontInfo(uint64_t index){
|
||||
this->eph->setFrontVisibilityInfo(EndpointState::ENDPOINT_ACTIVE, index);
|
||||
}
|
||||
|
||||
|
||||
void EndpointWidget::setIndex(uint64_t idx){
|
||||
this->idx = idx;
|
||||
}
|
||||
|
|
@ -234,18 +267,24 @@ uint64_t EndpointWidget::getIndex(){
|
|||
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
||||
// setWindowState(Qt::WindowFullScreen);
|
||||
// setCentralWidget(centralWidget);
|
||||
|
||||
/*
|
||||
* Registering needed custom events
|
||||
*/
|
||||
QEvent::registerEventType(CustomQEvent::EndpointWidgetObsolete);
|
||||
|
||||
widget = new QWidget();
|
||||
layout = new QGridLayout();
|
||||
trayIcon = new QSystemTrayIcon();
|
||||
trayIconMenu = new QMenu();
|
||||
trayIconMenuQuit = new QAction(STRING_QUIT);
|
||||
|
||||
changeDefaultCheckboxEnablement = new QEvent(QEvent::User);
|
||||
changeDefaultCheckboxEnablement->setAccepted(true);
|
||||
|
||||
widget->setLayout(layout);
|
||||
setCentralWidget(widget);
|
||||
//layout->addWidget(pintas, 0, 0);
|
||||
|
||||
setWindowTitle(STRING_TITLE);
|
||||
|
||||
reloadEndpointWidgets();
|
||||
|
|
@ -266,7 +305,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
connect(trayIcon, &QSystemTrayIcon::activated, this, &MainWindow::trayIconActivated);
|
||||
|
||||
/*
|
||||
* Set of function callback definitinos for EndpointSituationCallback
|
||||
* Set of function callback definitons for EndpointSituationCallback
|
||||
*/
|
||||
osh->setChangeFrontDefaultsFunction([this](Roles role, std::wstring endpointId) {
|
||||
for (auto epw : this->ews) {
|
||||
|
|
@ -306,8 +345,23 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) {
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
osh->setRemoveEndpointWidgetFunction([this](uint64_t index) {
|
||||
EndpointWidgetEvent removeObsoleteEndpointWidget((QEvent::Type)CustomQEvent::EndpointWidgetObsolete, index);
|
||||
removeObsoleteEndpointWidget.setAccepted(true);
|
||||
QCoreApplication::instance()->postEvent(this, &removeObsoleteEndpointWidget);
|
||||
});
|
||||
|
||||
/*
|
||||
* osh->setReviseEndpointShowingFunction([this](std::wstring endpointId, Roles role){
|
||||
*
|
||||
*
|
||||
* });
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::closeEvent(QCloseEvent *event) {
|
||||
if (!event->spontaneous() || !isVisible()) return;
|
||||
|
||||
|
|
@ -338,7 +392,7 @@ void MainWindow::reloadEndpointWidgets() {
|
|||
osh->getEndpointHandlers().at(i)->getCallbackInfo()->caller = osh->getGuid();
|
||||
EndpointWidget *epw = new EndpointWidget(epwIndex, osh->getEndpointHandlers().at(i), widget);
|
||||
epwIndex++;
|
||||
//TODO: ALWAYS PUSH BACK??? PSZ CHANGE DIS WHEN IMPLEMENTING DYN ENDPOINT DET
|
||||
//alfinal estoes solopara inicializarlmao
|
||||
ews.push_back(epw);
|
||||
layout->addWidget(epw, i, 0);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue