mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Finish implementing C++ bar widget
This commit is contained in:
parent
7fcaf5683d
commit
c747f6e53e
@ -72,6 +72,26 @@ CONFIG += c++11
|
|||||||
CONFIG += silent
|
CONFIG += silent
|
||||||
CONFIG += strict_c++
|
CONFIG += strict_c++
|
||||||
|
|
||||||
|
sanitize {
|
||||||
|
CONFIG += sanitizer
|
||||||
|
CONFIG += sanitize_address
|
||||||
|
CONFIG *= sanitize_undefined
|
||||||
|
}
|
||||||
|
|
||||||
|
QMAKE_CXXFLAGS *= -fno-math-errno
|
||||||
|
QMAKE_CXXFLAGS *= -funsafe-math-optimizations
|
||||||
|
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
# Serial Studio compile-time settings
|
||||||
|
#-----------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#DEFINES += DISABLE_QSU # If enabled, QSimpleUpdater shall not be used by the app.
|
||||||
|
# This is the default behaviour for MinGW.
|
||||||
|
|
||||||
|
DEFINES += LAZY_WIDGETS # Compile-time option to reduce the CPU usage of the widgets.
|
||||||
|
# If disabled, widgets shall update title, units, value, etc.
|
||||||
|
# If enabled, widgets shall only update their value.
|
||||||
|
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
# Libraries
|
# Libraries
|
||||||
#-----------------------------------------------------------------------------------------
|
#-----------------------------------------------------------------------------------------
|
||||||
|
@ -151,7 +151,6 @@ Widgets.Window {
|
|||||||
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
visible: widget.currentIndex == 1 || widget.currentIndex == 2
|
||||||
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMin(group, dataset, text)
|
onTextChanged: Cpp_JSON_Editor.setDatasetWidgetMin(group, dataset, text)
|
||||||
validator: DoubleValidator {
|
validator: DoubleValidator {
|
||||||
bottom: 0
|
|
||||||
top: parseFloat(max.text)
|
top: parseFloat(max.text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -165,6 +165,9 @@ void ModuleManager::initializeQmlInterface()
|
|||||||
auto ioNetwork = IO::DataSources::Network::getInstance();
|
auto ioNetwork = IO::DataSources::Network::getInstance();
|
||||||
auto miscThemeManager = Misc::ThemeManager::getInstance();
|
auto miscThemeManager = Misc::ThemeManager::getInstance();
|
||||||
|
|
||||||
|
// Start common event timers
|
||||||
|
miscTimerEvents->startTimers();
|
||||||
|
|
||||||
// Retranslate the QML interface automagically
|
// Retranslate the QML interface automagically
|
||||||
connect(miscTranslator, SIGNAL(languageChanged()), engine(), SLOT(retranslate()));
|
connect(miscTranslator, SIGNAL(languageChanged()), engine(), SLOT(retranslate()));
|
||||||
|
|
||||||
@ -202,9 +205,6 @@ void ModuleManager::initializeQmlInterface()
|
|||||||
engine()->load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
engine()->load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
|
||||||
|
|
||||||
// Warning! Do not call setSplashScreenMessage() after loading QML user interface
|
// Warning! Do not call setSplashScreenMessage() after loading QML user interface
|
||||||
|
|
||||||
// Start common event timers
|
|
||||||
QTimer::singleShot(500, miscTimerEvents, SLOT(startTimers()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,18 +42,6 @@ Bar::Bar(const int index)
|
|||||||
if (m_index < 0 || m_index >= dash->barCount())
|
if (m_index < 0 || m_index >= dash->barCount())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Get thermo color
|
|
||||||
QString color;
|
|
||||||
auto barcl = theme->barWidgetColors();
|
|
||||||
if (barcl.count() > m_index)
|
|
||||||
color = barcl.at(m_index);
|
|
||||||
else
|
|
||||||
color = barcl.at(barcl.count() % m_index);
|
|
||||||
|
|
||||||
// Configure thermo style
|
|
||||||
m_thermo.setPipeWidth(64);
|
|
||||||
m_thermo.setFillBrush(QBrush(QColor(color)));
|
|
||||||
|
|
||||||
// Configure label style
|
// Configure label style
|
||||||
QFont font = dash->monoFont();
|
QFont font = dash->monoFont();
|
||||||
font.setPixelSize(24);
|
font.setPixelSize(24);
|
||||||
@ -69,18 +57,55 @@ Bar::Bar(const int index)
|
|||||||
m_layout.setContentsMargins(24, 24, 24, 24);
|
m_layout.setContentsMargins(24, 24, 24, 24);
|
||||||
setLayout(&m_layout);
|
setLayout(&m_layout);
|
||||||
|
|
||||||
// Generate stylesheets
|
// Set stylesheets
|
||||||
// clang-format off
|
// clang-format off
|
||||||
auto labelQss = QSS("color:%1; border:1px solid %2;",
|
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
|
||||||
theme->datasetValue(),
|
theme->widgetAlternativeBackground(),
|
||||||
theme->datasetWindowBorder());
|
theme->widgetForegroundPrimary(),
|
||||||
auto windowQss = QSS("background-color:%1",
|
theme->widgetIndicator1());
|
||||||
theme->datasetWindowBackground());
|
m_label.setStyleSheet(valueQSS);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
// Set stylesheets
|
// Set window palette
|
||||||
setStyleSheet(windowQss);
|
QPalette windowPalette;
|
||||||
m_label.setStyleSheet(labelQss);
|
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
|
||||||
|
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
|
||||||
|
setPalette(windowPalette);
|
||||||
|
|
||||||
|
// Set thermo palette
|
||||||
|
QPalette thermoPalette;
|
||||||
|
thermoPalette.setColor(QPalette::Highlight, QColor("#f00"));
|
||||||
|
thermoPalette.setColor(QPalette::Text, theme->widgetIndicator1());
|
||||||
|
thermoPalette.setColor(QPalette::Dark, theme->widgetIndicator1());
|
||||||
|
thermoPalette.setColor(QPalette::Light, theme->widgetIndicator1());
|
||||||
|
thermoPalette.setColor(QPalette::ButtonText, theme->widgetIndicator1());
|
||||||
|
thermoPalette.setColor(QPalette::WindowText, theme->widgetIndicator1());
|
||||||
|
thermoPalette.setColor(QPalette::Base, theme->widgetAlternativeBackground());
|
||||||
|
m_thermo.setPalette(thermoPalette);
|
||||||
|
|
||||||
|
// Get thermo color
|
||||||
|
QString color;
|
||||||
|
auto barcl = theme->barWidgetColors();
|
||||||
|
if (barcl.count() > m_index)
|
||||||
|
color = barcl.at(m_index);
|
||||||
|
else
|
||||||
|
color = barcl.at(barcl.count() % m_index);
|
||||||
|
|
||||||
|
// Configure thermo style
|
||||||
|
m_thermo.setPipeWidth(64);
|
||||||
|
m_thermo.setBorderWidth(1);
|
||||||
|
m_thermo.setFillBrush(QBrush(QColor(color)));
|
||||||
|
|
||||||
|
// Lazy widgets, get initial properties from dataset
|
||||||
|
#ifdef LAZY_WIDGETS
|
||||||
|
auto dataset = UI::Dashboard::getInstance()->getBar(m_index);
|
||||||
|
if (dataset)
|
||||||
|
{
|
||||||
|
m_thermo.setAlarmLevel(dataset->alarm());
|
||||||
|
m_thermo.setAlarmEnabled(m_thermo.alarmLevel() > 0);
|
||||||
|
m_thermo.setScale(dataset->min(), dataset->max());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// React to dashboard events
|
// React to dashboard events
|
||||||
connect(dash, SIGNAL(updated()), this, SLOT(update()));
|
connect(dash, SIGNAL(updated()), this, SLOT(update()));
|
||||||
@ -99,9 +124,11 @@ void Bar::update()
|
|||||||
auto dataset = UI::Dashboard::getInstance()->getBar(m_index);
|
auto dataset = UI::Dashboard::getInstance()->getBar(m_index);
|
||||||
if (dataset)
|
if (dataset)
|
||||||
{
|
{
|
||||||
|
#ifndef LAZY_WIDGETS
|
||||||
m_thermo.setAlarmLevel(dataset->alarm());
|
m_thermo.setAlarmLevel(dataset->alarm());
|
||||||
m_thermo.setAlarmEnabled(m_thermo.alarmLevel() > 0);
|
m_thermo.setAlarmEnabled(m_thermo.alarmLevel() > 0);
|
||||||
m_thermo.setScale(dataset->min(), dataset->max());
|
m_thermo.setScale(dataset->min(), dataset->max());
|
||||||
|
#endif
|
||||||
m_thermo.setValue(dataset->value().toDouble());
|
m_thermo.setValue(dataset->value().toDouble());
|
||||||
m_label.setText(QString("%1 %2").arg(dataset->value(), dataset->units()));
|
m_label.setText(QString("%1 %2").arg(dataset->value(), dataset->units()));
|
||||||
}
|
}
|
||||||
@ -117,5 +144,6 @@ void Bar::resizeEvent(QResizeEvent *event)
|
|||||||
QFont font = m_label.font();
|
QFont font = m_label.font();
|
||||||
font.setPixelSize(width / 16);
|
font.setPixelSize(width / 16);
|
||||||
m_label.setFont(font);
|
m_label.setFont(font);
|
||||||
|
m_label.setMaximumHeight(event->size().height() * 0.4);
|
||||||
event->accept();
|
event->accept();
|
||||||
}
|
}
|
||||||
|
@ -48,13 +48,16 @@ DataGroup::DataGroup(const int index)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
// Generate widget stylesheets
|
// Generate widget stylesheets
|
||||||
auto font = dash->monoFont();
|
|
||||||
font.setBold(true);
|
|
||||||
auto valueQSS = QSS("color:%1", theme->datasetValue());
|
auto valueQSS = QSS("color:%1", theme->datasetValue());
|
||||||
auto titleQSS = QSS("color:%1", theme->datasetTextPrimary());
|
auto titleQSS = QSS("color:%1", theme->datasetTextPrimary());
|
||||||
auto unitsQSS = QSS("color:%1", theme->datasetTextSecondary());
|
auto unitsQSS = QSS("color:%1", theme->datasetTextSecondary());
|
||||||
auto iconsQSS = QSS("color:%1; font-weight:600;", theme->datasetTextSecondary());
|
auto iconsQSS = QSS("color:%1; font-weight:600;", theme->datasetTextSecondary());
|
||||||
auto windwQSS = QSS("background-color:%1", theme->datasetWindowBackground());
|
|
||||||
|
// Set window palette
|
||||||
|
QPalette windowPalette;
|
||||||
|
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
|
||||||
|
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
|
||||||
|
setPalette(windowPalette);
|
||||||
|
|
||||||
// Configure scroll area container
|
// Configure scroll area container
|
||||||
m_dataContainer = new QWidget(this);
|
m_dataContainer = new QWidget(this);
|
||||||
@ -92,12 +95,16 @@ DataGroup::DataGroup(const int index)
|
|||||||
|
|
||||||
// Configure elide modes
|
// Configure elide modes
|
||||||
|
|
||||||
// Set label data
|
// Lazy widgets, set label initial data
|
||||||
|
#ifdef LAZY_WIDGETS
|
||||||
auto set = group->getDataset(dataset);
|
auto set = group->getDataset(dataset);
|
||||||
title->setText(set->title());
|
if (set)
|
||||||
value->setText(set->value());
|
{
|
||||||
if (!set->units().isEmpty())
|
title->setText(set->title());
|
||||||
units->setText(QString("[%1]").arg(set->units()));
|
if (!set->units().isEmpty())
|
||||||
|
units->setText(QString("[%1]").arg(set->units()));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Set icon text
|
// Set icon text
|
||||||
dicon->setText("⤑");
|
dicon->setText("⤑");
|
||||||
@ -130,9 +137,6 @@ DataGroup::DataGroup(const int index)
|
|||||||
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
m_mainLayout->setContentsMargins(0, 0, 0, 0);
|
||||||
setLayout(m_mainLayout);
|
setLayout(m_mainLayout);
|
||||||
|
|
||||||
// Set background color
|
|
||||||
m_dataContainer->setStyleSheet(windwQSS);
|
|
||||||
|
|
||||||
// React to dashboard events
|
// React to dashboard events
|
||||||
connect(dash, SIGNAL(updated()), this, SLOT(update()));
|
connect(dash, SIGNAL(updated()), this, SLOT(update()));
|
||||||
}
|
}
|
||||||
@ -176,10 +180,15 @@ void DataGroup::update()
|
|||||||
for (int i = 0; i < group->datasetCount(); ++i)
|
for (int i = 0; i < group->datasetCount(); ++i)
|
||||||
{
|
{
|
||||||
set = group->getDataset(i);
|
set = group->getDataset(i);
|
||||||
m_titles.at(i)->setText(set->title());
|
if (set)
|
||||||
m_values.at(i)->setText(set->value());
|
{
|
||||||
if (!set->units().isEmpty())
|
#ifndef LAZY_WIDGETS
|
||||||
m_units.at(i)->setText(QString("[%1]").arg(set->units()));
|
m_titles.at(i)->setText(set->title());
|
||||||
|
if (!set->units().isEmpty())
|
||||||
|
m_units.at(i)->setText(QString("[%1]").arg(set->units()));
|
||||||
|
#endif
|
||||||
|
m_values.at(i)->setText(set->value());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,13 +56,12 @@ WidgetLoader::WidgetLoader(QQuickItem *parent)
|
|||||||
m_window.setMinimumWidth(640);
|
m_window.setMinimumWidth(640);
|
||||||
m_window.setMinimumHeight(480);
|
m_window.setMinimumHeight(480);
|
||||||
|
|
||||||
// Configure window style sheet
|
// Set window palette
|
||||||
// clang-format off
|
QPalette windowPalette;
|
||||||
auto theme = Misc::ThemeManager::getInstance();
|
auto theme = Misc::ThemeManager::getInstance();
|
||||||
auto qss = QString("background-color: %1;").arg(
|
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
|
||||||
theme->datasetWindowBackground().name());
|
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
|
||||||
m_window.setStyleSheet(qss);
|
m_window.setPalette(windowPalette);
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
// Resize widget to fit QML item size
|
// Resize widget to fit QML item size
|
||||||
connect(this, &QQuickPaintedItem::widthChanged, this,
|
connect(this, &QQuickPaintedItem::widthChanged, this,
|
||||||
@ -367,6 +366,8 @@ void WidgetLoader::processMouseEvents(QMouseEvent *event)
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -384,4 +385,5 @@ void WidgetLoader::processWheelEvents(QWheelEvent *event)
|
|||||||
};
|
};
|
||||||
|
|
||||||
static_cast<Hack *>(m_widget)->wheelEvent(event);
|
static_cast<Hack *>(m_widget)->wheelEvent(event);
|
||||||
|
update();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user