#include "qtclasses.h" /* * ToggleButton::ToggleButton(QWidget *parent) : QAbstractButton(parent) { * this->setCheckable(true); * } * * ToggleButton::~ToggleButton(){ * * } * * void ToggleButton::checkStateSet(){ } * * bool hitButton(const QPoint &pos) { * * } */ EndpointWidget::EndpointWidget(EndpointHandler* eph, QWidget *parent) : QWidget(parent){ this->eph = eph; layout = new QGridLayout(); this->setLayout(layout); log_debugcpp("olaW"); if (parent == nullptr) { log_debugcpp("owo?"); } muteButton = new QCheckBox(); mainLabel = new QLabel(QString::fromStdWString(eph->getName())); mainSlider = new QSlider(Qt::Horizontal); //muteButton->setStyleSheet("background-color: #A3C1DA; color: red"); 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->setText(eph->getMute() ? STRING_UNMUTE : STRING_MUTE); float volume = eph->getVolume(ENDPOINT_MASTER_VOLUME) * 100; mainSlider->setValue((int)volume); log_debugcpp("ENDPOINT SET WITH VOLUME " << volume); mainMuteLayout = new QGridLayout(); layout->addLayout(mainMuteLayout, 0, 0); mainMuteLayout->addWidget(mainLabel, 0, 0); mainMuteLayout->addWidget(muteButton, 0, 1); layout->addWidget(mainSlider, 0, 1); connect(mainSlider, &QSlider::valueChanged, this,&EndpointWidget::updateMainVolume); connect(muteButton, &QCheckBox::stateChanged, this, (&EndpointWidget::updateMute)); for(uint32_t i = 0; i < eph->getChannelCount(); i++){ QSlider* tmp = new QSlider(Qt::Horizontal); QLabel* tmpLb = new QLabel(""); tmp->setTickInterval(5); tmp->setSingleStep(1); tmp->setRange(0,100); volume = eph->getVolume(i) * 100; tmp->setValue((int) volume); tmpLb->setText(QString::number(volume)); this->channelSliders.push_back(tmp); this->channelLabels.push_back(tmpLb); layout->addWidget(tmp, 1, i); layout->addWidget(tmpLb, 2, i); connect(tmp, &QSlider::valueChanged, [this, i](int newValue){ this->eph->setVolume(osh->getGuid(), i, newValue); this->channelLabels.at(i)->setText(QString::number(newValue)); }); } layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 0); layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), 3, 1); log_debugcpp("ENDPOINT_WIDGETED"); } void EndpointWidget::updateMute(bool muted){ log_debugcpp("cliqui callboqui cloqui"); this->eph->setMute(osh->getGuid(), muted); this->muteButton->setChecked(eph->getMute() ? true : false); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); } void EndpointWidget::updateMute(int checked){ log_debugcpp("cliqui slOtty cloqui"); bool muted = (checked == 2 ? true : false); log_debugcpp("int: " << checked << " bool: " << muted); this->eph->setMute(osh->getGuid(), muted); //this->muteButton->setCheckState(); this->muteButton->setText(this->eph->getMute() ? STRING_UNMUTE : STRING_MUTE); } void EndpointWidget::updateMainVolume(int newValue){ log_debugcpp("updateMainVolume slot"); this->eph->setVolume(osh->getGuid(), ENDPOINT_MASTER_VOLUME, newValue); } void EndpointWidget::updateMainVolume(float newValue){ int newVal = newValue * 100; if(this->mainSlider->value() != newVal) { this->mainSlider->setValue(newVal); } } void EndpointWidget::updateChannelVolume(uint32_t channel, float newValue){ int newVal = newValue * 100; if(this->channelSliders.at(channel)->value() != newVal) { this->channelSliders.at(channel)->setValue(newVal); this->channelLabels.at(channel)->setText(QString::number((int)(newValue * 100))); } } void EndpointWidget::setIndex(uint64_t idx){ this->idx = idx; } uint64_t EndpointWidget::getIndex(){ return idx; } MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // setWindowState(Qt::WindowFullScreen); // setCentralWidget(centralWidget); widget = new QWidget(); layout = new QGridLayout(); widget->setLayout(layout); setCentralWidget(widget); //layout->addWidget(pintas, 0, 0); setWindowTitle("slidea resbala nu c"); reloadEndpointWidgets(); } void MainWindow::reloadEndpointWidgets() { unsigned int i = 0; for (; i < (osh->getEndpointHandlers().size()); i++) { log_debugcpp("EPWidget creation"); EndpointWidget *epw = new EndpointWidget(osh->getEndpointHandlers().at(i), widget); ews.push_back(epw); layout->addWidget(epw, i, 0); } osh->setEndpointWidgets(ews); layout->addItem(new QSpacerItem(1, 1, QSizePolicy::Minimum, QSizePolicy::MinimumExpanding), i, 0); } //#include "qtclosemwh.h" /* * void MainWindow::setPlotButton() { * button = new QPushButton("push"), * button->setCheckable(true); * connect(button, SIGNAL(toggled(bool)), this, SLOT(toggled(bool))) * QHBoxLayout *plotsLayout = new QHBoxLayout; * plotsLayout->setSpacing(10); * plotsLayout->addWidget(funPlot); * QHBoxLayout *buttonsLayout = new QHBoxLayout ; * buttonsLayout->addWidget(button); * QVBoxLayout *widgetLayout = new QVBoxLayout; * widgetLayout->addLayout(plotsLayout); * widgetLayout->addLayout(buttonsLayout); * setLayout(widgetLayout); * ... */