mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Add delay while displaying the dashboard
This commit is contained in:
parent
4543d556d4
commit
76d445cd56
@ -171,6 +171,7 @@ HEADERS += \
|
||||
src/Widgets/Common/AnalogGauge.h \
|
||||
src/Widgets/Common/AttitudeIndicator.h \
|
||||
src/Widgets/Common/BaseWidget.h \
|
||||
src/Widgets/Common/ElidedLabel.h \
|
||||
src/Widgets/Common/KLed.h \
|
||||
src/Widgets/Compass.h \
|
||||
src/Widgets/DataGroup.h \
|
||||
@ -212,6 +213,7 @@ SOURCES += \
|
||||
src/Widgets/Common/AnalogGauge.cpp \
|
||||
src/Widgets/Common/AttitudeIndicator.cpp \
|
||||
src/Widgets/Common/BaseWidget.cpp \
|
||||
src/Widgets/Common/ElidedLabel.cpp \
|
||||
src/Widgets/Common/KLed.cpp \
|
||||
src/Widgets/Compass.cpp \
|
||||
src/Widgets/DataGroup.cpp \
|
||||
|
@ -26,13 +26,11 @@ import QtQuick.Controls 2.12
|
||||
|
||||
import SerialStudio 1.0
|
||||
import "../Widgets" as Widgets
|
||||
import "../FramelessWindow" as FramelessWindow
|
||||
|
||||
Item {
|
||||
id: root
|
||||
|
||||
property int widgetIndex: -1
|
||||
property FramelessWindow.CustomWindow externalWindow: null
|
||||
|
||||
Widgets.Window {
|
||||
id: window
|
||||
@ -41,17 +39,11 @@ Item {
|
||||
icon.source: loader.widgetIcon
|
||||
headerDoubleClickEnabled: true
|
||||
borderColor: Cpp_ThemeManager.widgetWindowBorder
|
||||
onHeaderDoubleClicked: {
|
||||
if (root.externalWindow !== null)
|
||||
root.externalWindow.showNormal()
|
||||
else
|
||||
externalWindowLoader.active = true
|
||||
}
|
||||
onHeaderDoubleClicked: loader.showExternalWindow()
|
||||
|
||||
WidgetLoader {
|
||||
id: loader
|
||||
widgetIndex: root.widgetIndex
|
||||
renderTarget: PaintedItem.FramebufferObject
|
||||
anchors {
|
||||
fill: parent
|
||||
leftMargin: window.borderWidth
|
||||
@ -60,69 +52,4 @@ Item {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loader {
|
||||
id: externalWindowLoader
|
||||
|
||||
active: false
|
||||
asynchronous: true
|
||||
|
||||
sourceComponent: FramelessWindow.CustomWindow {
|
||||
id: _window
|
||||
minimumWidth: 640 + shadowMargin
|
||||
minimumHeight: 480 + shadowMargin
|
||||
title: externalLoader.widgetTitle
|
||||
extraFlags: Qt.WindowStaysOnTopHint
|
||||
titlebarText: Cpp_ThemeManager.text
|
||||
titlebarColor: Cpp_ThemeManager.widgetWindowBackground
|
||||
backgroundColor: Cpp_ThemeManager.widgetWindowBackground
|
||||
borderColor: isMaximized ? backgroundColor : Cpp_ThemeManager.highlight
|
||||
|
||||
Timer {
|
||||
id: timer
|
||||
interval: 200
|
||||
onTriggered: _window.showNormal()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.externalWindow = this
|
||||
timer.start()
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
clip: true
|
||||
anchors.fill: parent
|
||||
radius: _window.radius
|
||||
anchors.margins: _window.shadowMargin
|
||||
color: Cpp_ThemeManager.widgetWindowBackground
|
||||
anchors.topMargin: _window.titlebar.height + _window.shadowMargin
|
||||
|
||||
Rectangle {
|
||||
height: _window.radius
|
||||
color: Cpp_ThemeManager.widgetWindowBackground
|
||||
anchors {
|
||||
top: parent.top
|
||||
left: parent.left
|
||||
right: parent.right
|
||||
}
|
||||
}
|
||||
|
||||
WidgetLoader {
|
||||
id: externalLoader
|
||||
anchors.fill: parent
|
||||
isExternalWindow: true
|
||||
widgetIndex: root.widgetIndex
|
||||
widgetVisible: _window.visible
|
||||
anchors.margins: _window.radius
|
||||
renderTarget: PaintedItem.FramebufferObject
|
||||
}
|
||||
}
|
||||
|
||||
FramelessWindow.ResizeHandles {
|
||||
window: _window
|
||||
anchors.fill: parent
|
||||
handleSize: _window.handleSize
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -117,21 +117,6 @@ Control {
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Move window while dragging over the toolbar
|
||||
//
|
||||
Item {
|
||||
anchors.fill: parent
|
||||
|
||||
DragHandler {
|
||||
grabPermissions: TapHandler.CanTakeOverFromAnything
|
||||
onActiveChanged: {
|
||||
if (active)
|
||||
window.startSystemMove()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Toolbar icons
|
||||
//
|
||||
|
@ -69,7 +69,17 @@ FramelessWindow.CustomWindow {
|
||||
//
|
||||
function showSetup() { toolbar.setupClicked() }
|
||||
function showConsole() { toolbar.consoleClicked() }
|
||||
function showDashboard() { toolbar.dashboardClicked() }
|
||||
function showDashboard() { dbTimer.start() }
|
||||
|
||||
//
|
||||
// Wait a little before showing the dashboard to avoid UI glitches and/or overloading
|
||||
// the rendering engine
|
||||
//
|
||||
Timer {
|
||||
id: dbTimer
|
||||
interval: 500
|
||||
onTriggered: toolbar.dashboardClicked()
|
||||
}
|
||||
|
||||
//
|
||||
// Console-related functions
|
||||
|
@ -365,21 +365,12 @@ void Generator::processFrame(const QByteArray &data, const quint64 frame,
|
||||
auto datasets = JFI_Value(group, "datasets", "d").toArray();
|
||||
for (int j = 0; j < datasets.count(); ++j)
|
||||
{
|
||||
// Get dataset object & value
|
||||
auto dataset = datasets.at(j).toObject();
|
||||
auto value = JFI_Value(dataset, "value", "v").toString();
|
||||
|
||||
// Evaluate code in dataset value (if any)
|
||||
auto jsValue = m_engine.evaluate(value);
|
||||
|
||||
// Code execution correct, replace value in JSON
|
||||
if (!jsValue.isError())
|
||||
{
|
||||
dataset.remove("v");
|
||||
dataset.remove("value");
|
||||
dataset.insert("value", jsValue.toString());
|
||||
datasets.replace(j, dataset);
|
||||
}
|
||||
dataset.remove("v");
|
||||
dataset.remove("value");
|
||||
dataset.insert("value", value);
|
||||
datasets.replace(j, dataset);
|
||||
}
|
||||
|
||||
// Replace group datasets
|
||||
@ -415,7 +406,6 @@ JSONWorker::JSONWorker(const QByteArray &data, const quint64 frame, const QDateT
|
||||
: m_time(time)
|
||||
, m_data(data)
|
||||
, m_frame(frame)
|
||||
, m_engine(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
@ -441,9 +431,6 @@ void JSONWorker::process()
|
||||
if (generator->jsonMapData().isEmpty())
|
||||
return;
|
||||
|
||||
// Initialize javscript engine
|
||||
m_engine = new QJSEngine(this);
|
||||
|
||||
// Separate incoming data & add it to the JSON map
|
||||
auto json = generator->jsonMapData();
|
||||
auto sepr = IO::Manager::getInstance()->separatorSequence();
|
||||
@ -467,21 +454,12 @@ void JSONWorker::process()
|
||||
auto datasets = JFI_Value(group, "datasets", "d").toArray();
|
||||
for (int j = 0; j < datasets.count(); ++j)
|
||||
{
|
||||
// Get dataset object & value
|
||||
auto dataset = datasets.at(j).toObject();
|
||||
auto value = JFI_Value(dataset, "value", "v").toString();
|
||||
|
||||
// Evaluate code in dataset value (if any)
|
||||
auto jsValue = m_engine->evaluate(value);
|
||||
|
||||
// Code execution correct, replace value in JSON
|
||||
if (!jsValue.isError())
|
||||
{
|
||||
dataset.remove("v");
|
||||
dataset.remove("value");
|
||||
dataset.insert("value", jsValue.toString());
|
||||
datasets.replace(j, dataset);
|
||||
}
|
||||
dataset.remove("v");
|
||||
dataset.remove("value");
|
||||
dataset.insert("value", value);
|
||||
datasets.replace(j, dataset);
|
||||
}
|
||||
|
||||
// Replace group datasets
|
||||
@ -498,9 +476,6 @@ void JSONWorker::process()
|
||||
|
||||
// Create JSON document
|
||||
document = QJsonDocument(root);
|
||||
|
||||
// Delete javacript engine
|
||||
delete m_engine;
|
||||
}
|
||||
|
||||
// No parse error, update UI & reset error counter
|
||||
|
@ -25,8 +25,6 @@
|
||||
#include <QFile>
|
||||
#include <QObject>
|
||||
#include <QThread>
|
||||
#include <QJSValue>
|
||||
#include <QJSEngine>
|
||||
#include <QSettings>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonValue>
|
||||
@ -63,7 +61,6 @@ private:
|
||||
QDateTime m_time;
|
||||
QByteArray m_data;
|
||||
quint64 m_frame;
|
||||
QJSEngine *m_engine;
|
||||
};
|
||||
|
||||
/**
|
||||
@ -153,7 +150,6 @@ private slots:
|
||||
|
||||
private:
|
||||
QFile m_jsonMap;
|
||||
QJSEngine m_engine;
|
||||
quint64 m_frameCount;
|
||||
QSettings m_settings;
|
||||
QString m_jsonMapData;
|
||||
|
@ -49,11 +49,7 @@ TimerEvents::TimerEvents()
|
||||
{
|
||||
// Configure timeout intevals
|
||||
m_timerLowFreq.setInterval(HZ_TO_MS(1));
|
||||
m_timerHighFreq.setInterval(HZ_TO_MS(30));
|
||||
|
||||
// Configure timer precision
|
||||
m_timerLowFreq.setTimerType(Qt::PreciseTimer);
|
||||
m_timerHighFreq.setTimerType(Qt::PreciseTimer);
|
||||
m_timerHighFreq.setInterval(HZ_TO_MS(20));
|
||||
|
||||
// Configure signals/slots
|
||||
connect(&m_timerLowFreq, &QTimer::timeout, this, &TimerEvents::lowFreqTimeout);
|
||||
|
@ -967,7 +967,7 @@ QVector<JSON::Group *> Dashboard::getWidgetGroups(const QString &handle) const
|
||||
QVector<JSON::Group *> widgets;
|
||||
foreach (auto group, m_latestFrame.groups())
|
||||
{
|
||||
if (group->widget().toLower() == handle)
|
||||
if (group->widget() == handle)
|
||||
widgets.append(group);
|
||||
}
|
||||
|
||||
|
@ -49,27 +49,37 @@ WidgetLoader::WidgetLoader(QQuickItem *parent)
|
||||
, m_index(-1)
|
||||
, m_widget(nullptr)
|
||||
, m_widgetVisible(false)
|
||||
, m_isExternalWindow(false)
|
||||
{
|
||||
// Set render flags
|
||||
setAntialiasing(true);
|
||||
setOpaquePainting(true);
|
||||
setAcceptHoverEvents(true);
|
||||
setRenderTarget(FramebufferObject);
|
||||
setImplicitSize(100, 100);
|
||||
setPerformanceHints(FastFBOResizing);
|
||||
setAcceptedMouseButtons(Qt::AllButtons);
|
||||
|
||||
// Configure external window
|
||||
m_window.setMinimumWidth(640);
|
||||
m_window.setMinimumHeight(480);
|
||||
|
||||
// Set window palette
|
||||
QPalette palette;
|
||||
auto theme = Misc::ThemeManager::getInstance();
|
||||
palette.setColor(QPalette::Base, theme->widgetWindowBackground());
|
||||
palette.setColor(QPalette::Window, theme->widgetWindowBackground());
|
||||
m_window.setPalette(palette);
|
||||
|
||||
// Resize widget to fit QML item size
|
||||
connect(this, &QQuickPaintedItem::widthChanged, this,
|
||||
&WidgetLoader::updateWidgetSize);
|
||||
connect(this, &QQuickPaintedItem::heightChanged, this,
|
||||
&WidgetLoader::updateWidgetSize);
|
||||
|
||||
// Enable/disable the external window widget automatically
|
||||
connect(&m_window, SIGNAL(visibleChanged()), this, SLOT(updateExternalWindow()));
|
||||
|
||||
// Automatically update the widget's visibility
|
||||
connect(Dashboard::getInstance(), &Dashboard::widgetVisibilityChanged, this,
|
||||
&WidgetLoader::updateWidgetVisible);
|
||||
|
||||
// Draw widget
|
||||
QTimer::singleShot(0, this, SLOT(update()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,36 +96,30 @@ WidgetLoader::~WidgetLoader()
|
||||
*/
|
||||
bool WidgetLoader::event(QEvent *event)
|
||||
{
|
||||
// Check that widget exists
|
||||
if (!m_widget)
|
||||
return false;
|
||||
|
||||
// Process focus, wheel & mouse click/release events
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::FocusIn:
|
||||
forceActiveFocus();
|
||||
return QQuickPaintedItem::event(event);
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
processWheelEvents(static_cast<QWheelEvent *>(event));
|
||||
return true;
|
||||
break;
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
case QEvent::MouseMove:
|
||||
processMouseEvents(static_cast<QMouseEvent *>(event));
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::FocusIn:
|
||||
forceActiveFocus();
|
||||
return QQuickPaintedItem::event(event);
|
||||
break;
|
||||
case QEvent::Wheel:
|
||||
processWheelEvents(static_cast<QWheelEvent *>(event));
|
||||
return true;
|
||||
break;
|
||||
case QEvent::MouseButtonPress:
|
||||
case QEvent::MouseButtonRelease:
|
||||
case QEvent::MouseButtonDblClick:
|
||||
case QEvent::MouseMove:
|
||||
processMouseEvents(static_cast<QMouseEvent *>(event));
|
||||
return true;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
// Note: mouse enter/leave events must be processed directly with
|
||||
// the help of a QML MouseArea
|
||||
//
|
||||
return QApplication::sendEvent(m_widget, event);
|
||||
}
|
||||
|
||||
@ -140,12 +144,12 @@ bool WidgetLoader::eventFilter(QObject *watched, QEvent *event)
|
||||
{
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::Paint:
|
||||
case QEvent::UpdateRequest:
|
||||
update();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::Paint:
|
||||
case QEvent::UpdateRequest:
|
||||
update();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -201,18 +205,6 @@ QString WidgetLoader::widgetTitle() const
|
||||
return tr("Invalid");
|
||||
}
|
||||
|
||||
/**
|
||||
* If set to @c true, then the widget visibility shall be controlled
|
||||
* directly by the QML interface.
|
||||
*
|
||||
* If set to @c false, then the widget visbility shall be controlled
|
||||
* by the UI::Dashboard class via the SIGNAL/SLOT system.
|
||||
*/
|
||||
bool WidgetLoader::isExternalWindow() const
|
||||
{
|
||||
return m_isExternalWindow;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the type of the current widget (e.g. group, plot, bar, gauge, etc...)
|
||||
*/
|
||||
@ -221,6 +213,15 @@ UI::Dashboard::WidgetType WidgetLoader::widgetType() const
|
||||
return UI::Dashboard::getInstance()->widgetType(widgetIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the external window
|
||||
*/
|
||||
void WidgetLoader::showExternalWindow()
|
||||
{
|
||||
if (m_window.centralWidget())
|
||||
m_window.showNormal();
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the visibility & enabled status of the widget
|
||||
*/
|
||||
@ -250,69 +251,71 @@ void WidgetLoader::setWidgetIndex(const int index)
|
||||
// Construct new widget
|
||||
switch (widgetType())
|
||||
{
|
||||
case UI::Dashboard::WidgetType::Group:
|
||||
m_widget = new Widgets::DataGroup(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::MultiPlot:
|
||||
m_widget = new Widgets::MultiPlot(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::FFT:
|
||||
m_widget = new Widgets::FFTPlot(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Plot:
|
||||
m_widget = new Widgets::Plot(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Bar:
|
||||
m_widget = new Widgets::Bar(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Gauge:
|
||||
m_widget = new Widgets::Gauge(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Compass:
|
||||
m_widget = new Widgets::Compass(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Gyroscope:
|
||||
m_widget = new Widgets::Gyroscope(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Accelerometer:
|
||||
m_widget = new Widgets::Accelerometer(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::GPS:
|
||||
m_widget = new Widgets::GPS(relativeIndex());
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::LED:
|
||||
m_widget = new Widgets::LEDPanel(relativeIndex());
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Group:
|
||||
m_widget = new Widgets::DataGroup(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::DataGroup(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::MultiPlot:
|
||||
m_widget = new Widgets::MultiPlot(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::MultiPlot(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::FFT:
|
||||
m_widget = new Widgets::FFTPlot(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::FFTPlot(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Plot:
|
||||
m_widget = new Widgets::Plot(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Plot(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Bar:
|
||||
m_widget = new Widgets::Bar(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Bar(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Gauge:
|
||||
m_widget = new Widgets::Gauge(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Gauge(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Compass:
|
||||
m_widget = new Widgets::Compass(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Compass(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Gyroscope:
|
||||
m_widget = new Widgets::Gyroscope(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Gyroscope(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::Accelerometer:
|
||||
m_widget = new Widgets::Accelerometer(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::Accelerometer(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::GPS:
|
||||
m_widget = new Widgets::GPS(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::GPS(relativeIndex()));
|
||||
break;
|
||||
case UI::Dashboard::WidgetType::LED:
|
||||
m_widget = new Widgets::LEDPanel(relativeIndex());
|
||||
m_window.setCentralWidget(new Widgets::LEDPanel(relativeIndex()));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
// Configure external window
|
||||
if (m_window.centralWidget())
|
||||
{
|
||||
m_window.setWindowTitle(widgetTitle());
|
||||
m_window.centralWidget()->setEnabled(false);
|
||||
}
|
||||
|
||||
// Allow widget to receive events from the QML interface
|
||||
if (m_widget)
|
||||
{
|
||||
m_widget->setEnabled(true);
|
||||
m_widget->installEventFilter(this);
|
||||
QTimer::singleShot(100, this, SLOT(updateWidgetVisible()));
|
||||
emit widgetIndexChanged();
|
||||
updateWidgetVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the widget visibility controller source.
|
||||
*
|
||||
* If set to @c true, then the widget visibility shall be controlled
|
||||
* directly by the QML interface.
|
||||
*
|
||||
* If set to @c false, then the widget visbility shall be controlled
|
||||
* by the UI::Dashboard class via the SIGNAL/SLOT system.
|
||||
*/
|
||||
void WidgetLoader::setIsExternalWindow(const bool isWindow)
|
||||
{
|
||||
m_isExternalWindow = isWindow;
|
||||
emit isExternalWindowChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Resizes the widget to fit inside the QML item.
|
||||
*/
|
||||
@ -333,7 +336,7 @@ void WidgetLoader::updateWidgetVisible()
|
||||
{
|
||||
bool visible = UI::Dashboard::getInstance()->widgetVisible(widgetIndex());
|
||||
|
||||
if (widgetVisible() != visible && !isExternalWindow())
|
||||
if (widgetVisible() != visible)
|
||||
{
|
||||
m_widgetVisible = visible;
|
||||
|
||||
@ -344,6 +347,16 @@ void WidgetLoader::updateWidgetVisible()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Enables/disables the widget updates of the external window when the window
|
||||
* is shown or hidden.
|
||||
*/
|
||||
void WidgetLoader::updateExternalWindow()
|
||||
{
|
||||
if (m_window.centralWidget())
|
||||
m_window.centralWidget()->setEnabled(m_window.isVisible());
|
||||
}
|
||||
|
||||
/**
|
||||
* Hack: calls the appropiate protected mouse event handler function of the widget item
|
||||
*/
|
||||
@ -364,20 +377,20 @@ void WidgetLoader::processMouseEvents(QMouseEvent *event)
|
||||
auto hack = static_cast<Hack *>(m_widget);
|
||||
switch (event->type())
|
||||
{
|
||||
case QEvent::MouseButtonPress:
|
||||
hack->mousePressEvent(event);
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
hack->mouseMoveEvent(event);
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
hack->mouseReleaseEvent(event);
|
||||
break;
|
||||
case QEvent::MouseButtonDblClick:
|
||||
hack->mouseDoubleClickEvent(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
case QEvent::MouseButtonPress:
|
||||
hack->mousePressEvent(event);
|
||||
break;
|
||||
case QEvent::MouseMove:
|
||||
hack->mouseMoveEvent(event);
|
||||
break;
|
||||
case QEvent::MouseButtonRelease:
|
||||
hack->mouseReleaseEvent(event);
|
||||
break;
|
||||
case QEvent::MouseButtonDblClick:
|
||||
hack->mouseDoubleClickEvent(event);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
update();
|
||||
|
@ -25,12 +25,34 @@
|
||||
#include <QWidget>
|
||||
#include <QObject>
|
||||
#include <QPainter>
|
||||
#include <QMainWindow>
|
||||
#include <QQuickPaintedItem>
|
||||
|
||||
#include <UI/Dashboard.h>
|
||||
|
||||
namespace UI
|
||||
{
|
||||
class WidgetWindow : public QMainWindow
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
signals:
|
||||
void visibleChanged();
|
||||
|
||||
private:
|
||||
void showEvent(QShowEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
emit visibleChanged();
|
||||
}
|
||||
|
||||
void hideEvent(QHideEvent *event)
|
||||
{
|
||||
event->accept();
|
||||
emit visibleChanged();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief The WidgetLoader class
|
||||
*
|
||||
@ -76,10 +98,6 @@ class WidgetLoader : public QQuickPaintedItem
|
||||
Q_PROPERTY(QString widgetTitle
|
||||
READ widgetTitle
|
||||
NOTIFY widgetIndexChanged)
|
||||
Q_PROPERTY(bool isExternalWindow
|
||||
READ isExternalWindow
|
||||
WRITE setIsExternalWindow
|
||||
NOTIFY isExternalWindowChanged)
|
||||
Q_PROPERTY(bool widgetVisible
|
||||
READ widgetVisible
|
||||
WRITE setVisible
|
||||
@ -89,7 +107,6 @@ class WidgetLoader : public QQuickPaintedItem
|
||||
signals:
|
||||
void widgetIndexChanged();
|
||||
void widgetVisibleChanged();
|
||||
void isExternalWindowChanged();
|
||||
|
||||
public:
|
||||
WidgetLoader(QQuickItem *parent = 0);
|
||||
@ -104,17 +121,17 @@ public:
|
||||
bool widgetVisible() const;
|
||||
QString widgetIcon() const;
|
||||
QString widgetTitle() const;
|
||||
bool isExternalWindow() const;
|
||||
UI::Dashboard::WidgetType widgetType() const;
|
||||
|
||||
public slots:
|
||||
void showExternalWindow();
|
||||
void setVisible(const bool visible);
|
||||
void setWidgetIndex(const int index);
|
||||
void setIsExternalWindow(const bool isWindow);
|
||||
|
||||
private slots:
|
||||
void updateWidgetSize();
|
||||
void updateWidgetVisible();
|
||||
void updateExternalWindow();
|
||||
|
||||
protected:
|
||||
void processMouseEvents(QMouseEvent *event);
|
||||
@ -124,6 +141,6 @@ private:
|
||||
int m_index;
|
||||
QWidget *m_widget;
|
||||
bool m_widgetVisible;
|
||||
bool m_isExternalWindow;
|
||||
WidgetWindow m_window;
|
||||
};
|
||||
}
|
||||
|
78
src/Widgets/Common/ElidedLabel.cpp
Normal file
78
src/Widgets/Common/ElidedLabel.cpp
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
|
||||
*
|
||||
* 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 <QTimer>
|
||||
#include <QResizeEvent>
|
||||
|
||||
#include "ElidedLabel.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
ElidedLabel::ElidedLabel(QWidget *parent, Qt::WindowFlags flags)
|
||||
: QLabel(parent, flags)
|
||||
, m_eliding(false)
|
||||
, m_originalText("")
|
||||
, m_elideMode(Qt::ElideNone)
|
||||
{
|
||||
}
|
||||
|
||||
ElidedLabel::ElidedLabel(const QString &text, QWidget *parent, Qt::WindowFlags flags)
|
||||
: QLabel(text, parent, flags)
|
||||
, m_eliding(false)
|
||||
, m_originalText("")
|
||||
, m_elideMode(Qt::ElideNone)
|
||||
{
|
||||
setText(text);
|
||||
}
|
||||
|
||||
void ElidedLabel::setType(const Qt::TextElideMode type)
|
||||
{
|
||||
m_elideMode = type;
|
||||
elide();
|
||||
}
|
||||
|
||||
void ElidedLabel::resizeEvent(QResizeEvent *event)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
QTimer::singleShot(50, this, SLOT(elide()));
|
||||
}
|
||||
|
||||
void ElidedLabel::setText(const QString &text)
|
||||
{
|
||||
m_originalText = text;
|
||||
QLabel::setText(text);
|
||||
elide();
|
||||
}
|
||||
|
||||
void ElidedLabel::elide()
|
||||
{
|
||||
if (m_eliding == false)
|
||||
{
|
||||
m_eliding = true;
|
||||
|
||||
QFontMetrics metrics(font());
|
||||
QLabel::setText(metrics.elidedText(m_originalText, m_elideMode, width()));
|
||||
|
||||
m_eliding = false;
|
||||
}
|
||||
}
|
||||
}
|
52
src/Widgets/Common/ElidedLabel.h
Normal file
52
src/Widgets/Common/ElidedLabel.h
Normal file
@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Alex Spataru <https://github.com/alex-spataru>
|
||||
*
|
||||
* 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 <QLabel>
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
class ElidedLabel : public QLabel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
explicit ElidedLabel(QWidget *parent = Q_NULLPTR,
|
||||
Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
explicit ElidedLabel(const QString &text, QWidget *parent = Q_NULLPTR,
|
||||
Qt::WindowFlags flags = Qt::WindowFlags());
|
||||
void setType(const Qt::TextElideMode type);
|
||||
|
||||
public slots:
|
||||
void setText(const QString &text);
|
||||
void elide();
|
||||
|
||||
protected:
|
||||
void resizeEvent(QResizeEvent *event);
|
||||
|
||||
private:
|
||||
bool m_eliding;
|
||||
QString m_originalText;
|
||||
Qt::TextElideMode m_elideMode;
|
||||
};
|
||||
}
|
@ -79,8 +79,8 @@ DataGroup::DataGroup(const int index)
|
||||
// Create labels
|
||||
m_units.append(new QLabel(m_dataContainer));
|
||||
m_icons.append(new QLabel(m_dataContainer));
|
||||
m_titles.append(new QLabel(m_dataContainer));
|
||||
m_values.append(new QLabel(m_dataContainer));
|
||||
m_titles.append(new ElidedLabel(m_dataContainer));
|
||||
m_values.append(new ElidedLabel(m_dataContainer));
|
||||
|
||||
// Get pointers to labels
|
||||
auto dicon = m_icons.last();
|
||||
@ -88,6 +88,10 @@ DataGroup::DataGroup(const int index)
|
||||
auto title = m_titles.last();
|
||||
auto value = m_values.last();
|
||||
|
||||
// Set elide modes for title & value fields
|
||||
title->setType(Qt::ElideRight);
|
||||
value->setType(Qt::ElideRight);
|
||||
|
||||
// Set label alignments
|
||||
units->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
|
||||
value->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
|
||||
|
@ -22,12 +22,13 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QLabel>
|
||||
#include <QWidget>
|
||||
#include <QGridLayout>
|
||||
#include <QVBoxLayout>
|
||||
#include <QScrollArea>
|
||||
|
||||
#include "Common/ElidedLabel.h"
|
||||
|
||||
namespace Widgets
|
||||
{
|
||||
class DataGroup : public QWidget
|
||||
@ -54,8 +55,8 @@ private:
|
||||
|
||||
QVector<QLabel *> m_icons;
|
||||
QVector<QLabel *> m_units;
|
||||
QVector<QLabel *> m_titles;
|
||||
QVector<QLabel *> m_values;
|
||||
QVector<ElidedLabel *> m_titles;
|
||||
QVector<ElidedLabel *> m_values;
|
||||
|
||||
QWidget *m_dataContainer;
|
||||
QVBoxLayout *m_mainLayout;
|
||||
|
@ -146,9 +146,8 @@ void MultiPlot::updateData()
|
||||
continue;
|
||||
|
||||
// Add point to plot data
|
||||
auto data = m_yData[i].data();
|
||||
auto count = m_yData[i].count();
|
||||
memmove(data, data + 1, count * sizeof(double));
|
||||
memmove(m_yData[i].data(), m_yData[i].data() + 1, count * sizeof(double));
|
||||
|
||||
// Normalize dataset value
|
||||
if (dataset->max() > dataset->min())
|
||||
|
@ -60,7 +60,6 @@ Terminal::Terminal(QQuickItem *parent)
|
||||
// Set render flags
|
||||
setAntialiasing(true);
|
||||
setOpaquePainting(true);
|
||||
setAcceptHoverEvents(true);
|
||||
setRenderTarget(FramebufferObject);
|
||||
setPerformanceHints(FastFBOResizing);
|
||||
setAcceptedMouseButtons(Qt::AllButtons);
|
||||
|
Loading…
x
Reference in New Issue
Block a user