the status indicator widget
This commit is contained in:
parent
837bf1ad98
commit
ca75a9973c
|
@ -1,6 +1,7 @@
|
|||
#include "universewindow.h"
|
||||
#include "ui_universewindow.h"
|
||||
#include "universemodel.h"
|
||||
#include "statusindicatorwidget.h"
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QLabel>
|
||||
|
@ -49,6 +50,10 @@ UniverseWindow::UniverseWindow(QWidget *parent, QSacnUniverse *universe)
|
|||
prioritySpinBox->setEnabled(false);
|
||||
ui->toolBar->addWidget(prioritySpinBox);
|
||||
|
||||
// status indicator
|
||||
auto indicator = new StatusIndicatorWidget(this, mUniverse);
|
||||
ui->statusbar->addPermanentWidget(indicator);
|
||||
|
||||
update_status_();
|
||||
if (universe->isEditable())
|
||||
{
|
||||
|
|
|
@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21.1)
|
|||
|
||||
project(QsACN VERSION 0.3.1 LANGUAGES CXX)
|
||||
|
||||
find_package(Qt6 COMPONENTS Gui Network REQUIRED)
|
||||
find_package(Qt6 COMPONENTS Gui Network Widgets REQUIRED)
|
||||
|
||||
set(CMAKE_AUTOMOC ON)
|
||||
|
||||
|
@ -14,6 +14,7 @@ target_sources(${PROJECT_NAME}
|
|||
qsacnuniverse.h
|
||||
universemodel.h
|
||||
multiversemodel.h
|
||||
statusindicatorwidget.h
|
||||
PRIVATE
|
||||
qsacn_global.h
|
||||
qsacnnode.cpp
|
||||
|
@ -22,12 +23,14 @@ target_sources(${PROJECT_NAME}
|
|||
multiverseitem.h
|
||||
multiverseitem.cpp
|
||||
multiversemodel.cpp
|
||||
statusindicatorwidget.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
Qt::Gui
|
||||
Qt::Network
|
||||
Qt::Widgets
|
||||
LCP_sacn
|
||||
)
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
#include "multiverseitem.h"
|
||||
#include "multiversemodel.h"
|
||||
#include "statusindicatorwidget.h"
|
||||
|
||||
#include <QFont>
|
||||
#include <QMetaEnum>
|
||||
|
@ -19,11 +20,15 @@ MultiverseItem::MultiverseItem(MultiverseItem* parent,
|
|||
, discovery_(discovery)
|
||||
, parentItem_(parent)
|
||||
, override_data_(QVariant())
|
||||
, mIndicator(nullptr)
|
||||
{
|
||||
createChildren();
|
||||
|
||||
if(parent)
|
||||
parent->appendChild(this);
|
||||
|
||||
if (universe)
|
||||
mIndicator = new StatusIndicatorWidget(nullptr, universe);
|
||||
}
|
||||
|
||||
|
||||
|
@ -32,6 +37,7 @@ MultiverseItem::MultiverseItem(MultiverseItem* parent,
|
|||
*/
|
||||
MultiverseItem::~MultiverseItem()
|
||||
{
|
||||
delete mIndicator;
|
||||
qDeleteAll(childItems_);
|
||||
}
|
||||
|
||||
|
@ -169,24 +175,11 @@ QVariant MultiverseItem::data(int column, int role) const
|
|||
case MultiverseModel::Universe:
|
||||
return universe_->number();
|
||||
case MultiverseModel::Status:
|
||||
switch (universe_->status()) {
|
||||
case sACN::Universe::DMX_NULL:
|
||||
return QObject::tr("Pending");
|
||||
case sACN::Universe::DMX_ACTIVE:
|
||||
return QObject::tr("Active");
|
||||
case sACN::Universe::DMX_LOST:
|
||||
return QObject::tr("Lost");
|
||||
case sACN::Universe::sACN_TERMINATED:
|
||||
return QObject::tr("Terminated");
|
||||
default:
|
||||
return QVariant();
|
||||
}
|
||||
return mIndicator? mIndicator->toolTip() : QVariant();
|
||||
case MultiverseModel::Priority:
|
||||
{
|
||||
auto v = universe_->priority();
|
||||
if (v > 200)
|
||||
return QVariant();
|
||||
return v;
|
||||
auto priority = universe_->priority();
|
||||
return priority <= 200 ? priority : QVariant();
|
||||
}
|
||||
case MultiverseModel::Channels:
|
||||
{
|
||||
|
|
|
@ -42,4 +42,5 @@ private:
|
|||
QSacnDiscoveredUniverse* discovery_;
|
||||
MultiverseItem* parentItem_;
|
||||
QVariant override_data_;
|
||||
QWidget *mIndicator;
|
||||
};
|
||||
|
|
|
@ -0,0 +1,146 @@
|
|||
/*
|
||||
statusindicatorwidget.cpp
|
||||
|
||||
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.
|
||||
*/
|
||||
#include "statusindicatorwidget.h"
|
||||
#include <QPainter>
|
||||
|
||||
StatusIndicatorWidget::StatusIndicatorWidget(QWidget *parent, QSacnUniverse *universe)
|
||||
: QWidget{parent}
|
||||
, mUniverse(universe)
|
||||
, mBlinkState(true)
|
||||
{
|
||||
setMinimumWidth(16);
|
||||
setSizePolicy(QSizePolicy::Minimum, QSizePolicy::MinimumExpanding);
|
||||
|
||||
// initial state
|
||||
setToolTip(statusText());
|
||||
statusChanged();
|
||||
|
||||
// status feedback
|
||||
connect(mUniverse, &QSacnUniverse::statusChanged,
|
||||
this, [this](){setToolTip(statusText());});
|
||||
connect(mUniverse, &QSacnUniverse::statusChanged,
|
||||
this, &StatusIndicatorWidget::statusChanged);
|
||||
connect(mUniverse, &QSacnUniverse::dataChanged,
|
||||
this, &StatusIndicatorWidget::dataActivity);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief StatusIndicatorWidget::statusChanged
|
||||
*/
|
||||
void StatusIndicatorWidget::statusChanged()
|
||||
{
|
||||
switch (mUniverse->status()) {
|
||||
case sACN::Universe::DMX_LOST:
|
||||
{
|
||||
mBlinkState = !mBlinkState;
|
||||
QTimer::singleShot(250, this, [this]() {
|
||||
statusChanged();
|
||||
});
|
||||
break;
|
||||
}
|
||||
default:
|
||||
mBlinkState = true;;
|
||||
}
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief StatusIndicatorWidget::dataActivity
|
||||
*/
|
||||
void StatusIndicatorWidget::dataActivity()
|
||||
{
|
||||
if (!mBlinkState)
|
||||
return; // already in a blink state
|
||||
|
||||
QTimer::singleShot(150, this, [this]() {
|
||||
mBlinkState = true;
|
||||
update();
|
||||
});
|
||||
mBlinkState = false;
|
||||
update();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief StatusIndicatorWidget::statusText
|
||||
* @return
|
||||
*/
|
||||
const QString StatusIndicatorWidget::statusText() const
|
||||
{
|
||||
switch (mUniverse->status())
|
||||
{
|
||||
case sACN::Universe::DMX_NULL:
|
||||
return tr("Pending");
|
||||
case sACN::Universe::DMX_ACTIVE:
|
||||
return tr("Active");
|
||||
case sACN::Universe::DMX_LOST:
|
||||
return tr("Lost");
|
||||
case sACN::Universe::sACN_TERMINATED:
|
||||
return tr("Terminated");
|
||||
default:
|
||||
return tr("Undefined");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StatusIndicatorWidget::paintEvent(QPaintEvent *)
|
||||
{
|
||||
QColor stroke(127,127,127); // neutral
|
||||
QColor fill(64,64,64); // grey
|
||||
|
||||
switch (mUniverse->status()) {
|
||||
case sACN::Universe::DMX_NULL:
|
||||
fill.setRgb(250,250,250); // white
|
||||
break;
|
||||
case sACN::Universe::DMX_ACTIVE:
|
||||
fill.setRgb(32,255,64); // green
|
||||
break;
|
||||
case sACN::Universe::DMX_LOST:
|
||||
fill.setRgb(255,255,64); // amber
|
||||
break;
|
||||
case sACN::Universe::sACN_TERMINATED:
|
||||
fill.setRgb(255,32,32); // red
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fill.setAlpha(mBlinkState ? 255 : 42);
|
||||
|
||||
QPainter painter(this);
|
||||
painter.setRenderHint(QPainter::Antialiasing);
|
||||
painter.setPen(stroke);
|
||||
painter.setBrush(fill);
|
||||
|
||||
const int size = qMin(width(), height());
|
||||
switch (mUniverse->status()) {
|
||||
case sACN::Universe::DMX_NULL:
|
||||
case sACN::Universe::DMX_ACTIVE:
|
||||
case sACN::Universe::DMX_LOST:
|
||||
case sACN::Universe::sACN_TERMINATED:
|
||||
default:
|
||||
painter.drawEllipse((width()-size)/2, (height()-size)/2, size, size); // circle
|
||||
}
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
statusindicatorwidget.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.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <QStyledItemDelegate>
|
||||
#include "qsacnuniverse.h"
|
||||
|
||||
class StatusIndicatorWidget
|
||||
: public QWidget
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit StatusIndicatorWidget(QWidget *parent = nullptr,
|
||||
QSacnUniverse *universe = nullptr);
|
||||
const QString statusText() const;
|
||||
|
||||
protected:
|
||||
void paintEvent(QPaintEvent *) override;
|
||||
|
||||
private slots:
|
||||
void statusChanged();
|
||||
void dataActivity();
|
||||
|
||||
private:
|
||||
QSacnUniverse *mUniverse;
|
||||
bool mBlinkState;
|
||||
};
|
|
@ -295,9 +295,9 @@ void Universe::setStatus(uint8_t status)
|
|||
if (status == RX_TIMEOUT)
|
||||
status = sACN_TERMINATED;
|
||||
|
||||
tx_control_mutex_.lock();
|
||||
// tx_control_mutex_.lock();
|
||||
DMX::Universe::setStatus(status);
|
||||
tx_control_mutex_.unlock();
|
||||
// tx_control_mutex_.unlock();
|
||||
|
||||
// Reset sequencing on terminated universes. Results in faster reaquision
|
||||
// from the same source without waiting for the sequence to realign.
|
||||
|
|
Loading…
Reference in New Issue