2023-04-16 11:51:11 -04:00
|
|
|
/*
|
|
|
|
universewindow.h
|
|
|
|
|
|
|
|
Copyright (c) 2022 Kevin Matz (kevin.matz@gmail.com)
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
SOFTWARE.
|
|
|
|
*/
|
2022-12-03 20:36:02 -05:00
|
|
|
#include "universewindow.h"
|
|
|
|
#include "ui_universewindow.h"
|
2022-11-16 09:28:08 -05:00
|
|
|
#include "universemodel.h"
|
2023-04-16 11:28:17 -04:00
|
|
|
#include "universestatuswidget.h"
|
2021-09-06 12:54:28 -04:00
|
|
|
|
2023-04-16 10:51:30 -04:00
|
|
|
#include <QActionGroup>
|
2021-09-06 12:54:28 -04:00
|
|
|
#include <QComboBox>
|
|
|
|
#include <QLabel>
|
|
|
|
#include <QMetaEnum>
|
|
|
|
|
|
|
|
/**
|
2022-12-03 23:28:24 -05:00
|
|
|
* @brief UniverseWindow::UniverseWindow
|
2021-09-06 12:54:28 -04:00
|
|
|
* @param parent
|
|
|
|
*/
|
2023-04-16 11:51:11 -04:00
|
|
|
UniverseWindow::UniverseWindow(QWidget *parent, std::shared_ptr<DMX::Universe> universe)
|
2021-09-06 12:54:28 -04:00
|
|
|
: QMainWindow(parent)
|
2022-12-03 21:21:08 -05:00
|
|
|
, ui(new Ui::UniverseWindow())
|
2023-04-16 11:51:11 -04:00
|
|
|
, universe_(universe)
|
2023-04-16 22:43:53 -04:00
|
|
|
, status_watchdog_(new QTimer(this))
|
2021-09-06 12:54:28 -04:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2023-04-16 22:43:53 -04:00
|
|
|
// set the status watchdog to update the status if the universe
|
|
|
|
// isn't showing frequent activity
|
|
|
|
status_watchdog_->callOnTimeout([this](){update_status_();});
|
|
|
|
status_watchdog_->setInterval(DMX::E111_DATA_LOSS_TIMEOUT / 10);
|
|
|
|
status_watchdog_->start();
|
|
|
|
|
2023-04-16 11:51:11 -04:00
|
|
|
auto model = new UniverseModel(this, universe);
|
2021-09-06 12:54:28 -04:00
|
|
|
ui->tableView->setModel(model);
|
|
|
|
|
|
|
|
// update the status bar whenever the universe refreshes
|
2023-04-16 10:51:30 -04:00
|
|
|
connect(model, &UniverseModel::dataChanged, this, [this]() {
|
|
|
|
update_status_();
|
2023-04-16 22:43:53 -04:00
|
|
|
status_watchdog_->start();
|
2023-04-16 10:51:30 -04:00
|
|
|
});
|
2021-09-06 12:54:28 -04:00
|
|
|
|
|
|
|
// add data format combobox to toolbar
|
2023-04-16 10:51:30 -04:00
|
|
|
auto formatLabel = new QLabel(ui->toolBarDMX);
|
|
|
|
ui->toolBarDMX->addWidget(formatLabel);
|
2021-09-06 12:54:28 -04:00
|
|
|
formatLabel->setText(tr("Data Format") + ": ");
|
2023-04-16 10:51:30 -04:00
|
|
|
|
|
|
|
auto dataModes = new QComboBox(ui->toolBarDMX);
|
|
|
|
ui->toolBarDMX->addWidget(dataModes);
|
2021-09-06 12:54:28 -04:00
|
|
|
const QMetaEnum types = QMetaEnum::fromType<UniverseModel::data_modes>();
|
|
|
|
for (int i=0; i < types.keyCount(); ++i)
|
|
|
|
dataModes->addItem(types.key(i));
|
2023-04-16 10:51:30 -04:00
|
|
|
|
|
|
|
auto formatGroup = new QActionGroup(ui->centralwidget);
|
|
|
|
formatGroup->addAction(ui->actionViewDecimal);
|
|
|
|
formatGroup->addAction(ui->actionViewHex);
|
|
|
|
formatGroup->addAction(ui->actionViewPercent);
|
|
|
|
|
2021-09-06 12:54:28 -04:00
|
|
|
connect(dataModes, &QComboBox::currentTextChanged,
|
2023-04-16 10:51:30 -04:00
|
|
|
this, [this, model, types, formatGroup](QString mode) {
|
|
|
|
auto data_mode = static_cast<UniverseModel::data_modes>(types.keyToValue(mode.toLocal8Bit()));
|
|
|
|
model->setDataMode(data_mode);
|
|
|
|
formatGroup->blockSignals(true);
|
|
|
|
switch (data_mode) {
|
|
|
|
case UniverseModel::Decimal:
|
|
|
|
ui->actionViewDecimal->setChecked(true);
|
|
|
|
break;
|
|
|
|
case UniverseModel::Hex:
|
|
|
|
ui->actionViewHex->setChecked(true);
|
|
|
|
break;
|
|
|
|
case UniverseModel::Percent:
|
|
|
|
ui->actionViewPercent->setChecked(true);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
formatGroup->blockSignals(false);
|
|
|
|
});
|
|
|
|
connect(ui->actionViewDecimal, &QAction::toggled, this, [dataModes](bool state) {
|
|
|
|
if (state)
|
|
|
|
dataModes->setCurrentIndex((int)UniverseModel::Decimal);
|
|
|
|
});
|
|
|
|
connect(ui->actionViewHex, &QAction::toggled, this, [dataModes](bool state) {
|
|
|
|
if (state)
|
|
|
|
dataModes->setCurrentIndex((int)UniverseModel::Hex);
|
|
|
|
});
|
|
|
|
connect(ui->actionViewPercent, &QAction::toggled, this, [dataModes](bool state) {
|
|
|
|
if (state)
|
|
|
|
dataModes->setCurrentIndex((int)UniverseModel::Percent);
|
|
|
|
});
|
2021-09-06 12:54:28 -04:00
|
|
|
|
2022-12-06 00:16:00 -05:00
|
|
|
// status indicator
|
2023-04-16 11:51:11 -04:00
|
|
|
auto indicator = new UniverseStatusWidget(this, universe_);
|
2022-12-06 00:16:00 -05:00
|
|
|
ui->statusbar->addPermanentWidget(indicator);
|
|
|
|
|
2022-12-03 21:12:31 -05:00
|
|
|
update_status_();
|
2021-09-06 12:54:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-03 23:28:24 -05:00
|
|
|
* @brief UniverseWindow::~UniverseWindow
|
2021-09-06 12:54:28 -04:00
|
|
|
*/
|
2022-12-03 21:21:08 -05:00
|
|
|
UniverseWindow::~UniverseWindow()
|
2021-09-06 12:54:28 -04:00
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2022-12-03 23:28:24 -05:00
|
|
|
* @brief UniverseWindow::updateStatusBar
|
2021-09-06 12:54:28 -04:00
|
|
|
*/
|
2022-12-03 21:21:08 -05:00
|
|
|
void UniverseWindow::update_status_()
|
2021-09-06 12:54:28 -04:00
|
|
|
{
|
2023-04-16 11:51:11 -04:00
|
|
|
if (!universe_->isEditable())
|
2021-09-06 12:54:28 -04:00
|
|
|
{
|
|
|
|
// status bar
|
|
|
|
ui->statusbar->clearMessage();
|
|
|
|
QString message = QString("%1 " + tr("Hz")).arg(
|
2023-04-16 11:51:11 -04:00
|
|
|
QString::number(universe_->rxRate()));
|
2021-09-06 12:54:28 -04:00
|
|
|
ui->statusbar->showMessage(message, 2500);
|
|
|
|
}
|
|
|
|
}
|