Add base widget class

This commit is contained in:
Alex Spataru 2021-09-28 18:13:18 -05:00
parent fbe50128bd
commit d755f44539
15 changed files with 274 additions and 305 deletions

View File

@ -170,8 +170,10 @@ HEADERS += \
src/Plugins/Bridge.h \
src/UI/Dashboard.h \
src/Widgets/Accelerometer.h \
src/Widgets/AnalogGauge.h \
src/Widgets/Bar.h \
src/Widgets/Common/AnalogGauge.h \
src/Widgets/Common/BaseWidget.h \
src/Widgets/Common/ExternalWindow.h \
src/Widgets/Compass.h \
src/Widgets/DataGroup.h \
src/Widgets/Gauge.h \
@ -183,11 +185,6 @@ HEADERS += \
src/Widgets/WidgetLoader.h
SOURCES += \
src/UI/Dashboard.cpp \
src/Widgets/AnalogGauge.cpp \
src/Widgets/MultiPlot.cpp \
src/Widgets/WidgetLoader.cpp \
src/main.cpp \
src/CSV/Export.cpp \
src/CSV/Player.cpp \
src/IO/Checksum.cpp \
@ -209,15 +206,23 @@ SOURCES += \
src/Misc/Translator.cpp \
src/Misc/Utilities.cpp \
src/Plugins/Bridge.cpp \
src/UI/Dashboard.cpp \
src/Widgets/Accelerometer.cpp \
src/Widgets/Bar.cpp \
src/Widgets/Common/AnalogGauge.cpp \
src/Widgets/Common/BaseWidget.cpp \
src/Widgets/Common/ExternalWindow.cpp \
src/Widgets/Compass.cpp \
src/Widgets/DataGroup.cpp \
src/Widgets/Gauge.cpp \
src/Widgets/Gyroscope.cpp \
src/Widgets/MultiPlot.cpp \
src/Widgets/Plot.cpp \
src/Widgets/Terminal.cpp \
src/Widgets/Thermometer.cpp
src/Widgets/Thermometer.cpp \
src/Widgets/WidgetLoader.cpp \
src/main.cpp
DISTFILES += \
assets/qml/Dashboard/DashboardTitle.qml \

View File

@ -53,46 +53,19 @@ Accelerometer::Accelerometer(const int index)
auto needle = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true,
QColor(needleColor), knobColor);
m_gauge.setNeedle(needle);
m_gauge.setFont(dash->monoFont());
// Set gauge scale & display angles
m_gauge.setScale(0, 12);
m_gauge.setScaleArc(90, 360);
// Set gauge palette
QPalette gaugePalette;
gaugePalette.setColor(QPalette::WindowText, theme->base());
gaugePalette.setColor(QPalette::Text, theme->widgetIndicator1());
m_gauge.setPalette(gaugePalette);
QPalette palette;
palette.setColor(QPalette::WindowText, theme->base());
palette.setColor(QPalette::Text, theme->widgetIndicator1());
m_gauge.setPalette(palette);
// Set window palette
QPalette windowPalette;
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
setPalette(windowPalette);
// Configure label style
QFont font = dash->monoFont();
font.setPixelSize(24);
m_label.setFont(font);
m_label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// Configure layout
m_layout.setSpacing(24);
m_layout.addWidget(&m_gauge);
m_layout.addWidget(&m_label);
m_layout.setContentsMargins(24, 24, 24, 24);
m_layout.setAlignment(&m_gauge, Qt::AlignHCenter);
setLayout(&m_layout);
// Set stylesheets
// clang-format off
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
theme->base(),
theme->widgetForegroundPrimary(),
theme->widgetIndicator1());
m_label.setStyleSheet(valueQSS);
// clang-format on
// Set widget pointer
setWidget(&m_gauge);
// React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(update()));
@ -134,33 +107,6 @@ void Accelerometer::update()
const double G = qSqrt(qPow(x, 2) + qPow(y, 2) + qPow(z, 2));
m_gauge.setValue(G);
m_label.setText(QString("%1 G").arg(QString::number(G, 'f', 2)));
setLabel(QString("%1 G").arg(QString::number(G, 'f', 2)));
}
}
void Accelerometer::resizeEvent(QResizeEvent *event)
{
// Get width & height (exluding layout margins & spacing)
auto width = event->size().width() - 72;
auto height = event->size().height() - 72;
// Get fonts & calculate size
auto labelFont = UI::Dashboard::getInstance()->monoFont();
auto gaugeFont = UI::Dashboard::getInstance()->monoFont();
labelFont.setPixelSize(width / 18);
gaugeFont.setPixelSize(width / 24);
// Set fonts
m_label.setFont(labelFont);
m_gauge.setFont(gaugeFont);
// Set widget sizes
m_label.setMinimumWidth(width * 0.4);
m_label.setMaximumWidth(width * 0.4);
m_gauge.setMinimumWidth(width * 0.6);
m_gauge.setMaximumWidth(width * 0.6);
m_label.setMaximumHeight(height * 0.4);
// Accept event
event->accept();
}

View File

@ -23,15 +23,12 @@
#ifndef WIDGETS_ACCELEROMETER_H
#define WIDGETS_ACCELEROMETER_H
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include "AnalogGauge.h"
#include "Common/BaseWidget.h"
#include "Common/AnalogGauge.h"
namespace Widgets
{
class Accelerometer : public QWidget
class Accelerometer : public BaseWidget
{
Q_OBJECT
@ -41,14 +38,9 @@ public:
private slots:
void update();
protected:
void resizeEvent(QResizeEvent *event);
private:
int m_index;
QLabel m_label;
AnalogGauge m_gauge;
QHBoxLayout m_layout;
};
}

View File

@ -42,45 +42,16 @@ Bar::Bar(const int index)
if (m_index < 0 || m_index >= dash->barCount())
return;
// Configure label style
QFont font = dash->monoFont();
font.setPixelSize(24);
m_label.setFont(font);
m_label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// Configure layout
m_layout.setSpacing(24);
m_layout.addWidget(&m_thermo);
m_layout.addWidget(&m_label);
m_layout.setContentsMargins(24, 24, 24, 24);
m_layout.setAlignment(&m_thermo, Qt::AlignHCenter);
setLayout(&m_layout);
// Set stylesheets
// clang-format off
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
theme->base(),
theme->widgetForegroundPrimary(),
theme->widgetIndicator1());
m_label.setStyleSheet(valueQSS);
// clang-format on
// Set window palette
QPalette windowPalette;
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
setPalette(windowPalette);
// Set thermo palette
QPalette thermoPalette;
thermoPalette.setColor(QPalette::Base, theme->base());
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());
m_thermo.setPalette(thermoPalette);
QPalette palette;
palette.setColor(QPalette::Base, theme->base());
palette.setColor(QPalette::Highlight, QColor("#f00"));
palette.setColor(QPalette::Text, theme->widgetIndicator1());
palette.setColor(QPalette::Dark, theme->widgetIndicator1());
palette.setColor(QPalette::Light, theme->widgetIndicator1());
palette.setColor(QPalette::ButtonText, theme->widgetIndicator1());
palette.setColor(QPalette::WindowText, theme->widgetIndicator1());
m_thermo.setPalette(palette);
// Get thermo color
QString color;
@ -106,8 +77,12 @@ Bar::Bar(const int index)
}
#endif
// Set widget pointer & disable auto resize
setWidget(&m_thermo, Qt::AlignHCenter, false);
// React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(update()));
connect(this, SIGNAL(resized()), this, SLOT(onResized()));
}
/**
@ -134,36 +109,14 @@ void Bar::update()
#endif
auto value = dataset->value().toDouble();
m_thermo.setValue(value);
m_label.setText(
QString("%1 %2").arg(QString::number(value, 'f', 2), dataset->units()));
setLabel(QString("%1 %2").arg(QString::number(value, 'f', 2), dataset->units()));
}
}
/**
* Resizes the thermo and the value display label to fit the size
* of the parent window.
* Resizes the thermo to fit the size of the parent window.
*/
void Bar::resizeEvent(QResizeEvent *event)
void Bar::onResized()
{
// Get width & height (exluding layout margins & spacing)
auto width = event->size().width() - 72;
auto height = event->size().height() - 72;
// Get fonts & calculate size
auto labelFont = UI::Dashboard::getInstance()->monoFont();
auto thermoFont = UI::Dashboard::getInstance()->monoFont();
labelFont.setPixelSize(width / 18);
// Set fonts
m_label.setFont(labelFont);
m_thermo.setFont(thermoFont);
// Set widget sizes
m_thermo.setPipeWidth(width * 0.25);
m_label.setMinimumWidth(width * 0.4);
m_label.setMaximumWidth(width * 0.4);
m_label.setMaximumHeight(height * 0.4);
// Accept event
event->accept();
m_thermo.setPipeWidth(width() * 0.25);
}

View File

@ -23,13 +23,12 @@
#ifndef WIDGETS_BAR_H
#define WIDGETS_BAR_H
#include <QLabel>
#include <QwtThermo>
#include <QHBoxLayout>
#include "Common/BaseWidget.h"
namespace Widgets
{
class Bar : public QWidget
class Bar : public BaseWidget
{
Q_OBJECT
@ -38,15 +37,11 @@ public:
private slots:
void update();
protected:
void resizeEvent(QResizeEvent *event);
void onResized();
private:
int m_index;
QwtThermo m_thermo;
QLabel m_label;
QHBoxLayout m_layout;
};
}

View File

@ -0,0 +1,116 @@
/*
* 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 "BaseWidget.h"
#include "UI/Dashboard.h"
#include "Misc/ThemeManager.h"
#include <QResizeEvent>
using namespace Widgets;
BaseWidget::BaseWidget()
: m_widget(nullptr)
, m_resizeWidget(true)
{
// Set window palette
QPalette palette;
auto theme = Misc::ThemeManager::getInstance();
palette.setColor(QPalette::Base, theme->datasetWindowBackground());
palette.setColor(QPalette::Window, theme->datasetWindowBackground());
setPalette(palette);
// Configure label style
QFont font = UI::Dashboard::getInstance()->monoFont();
font.setPixelSize(24);
m_label.setFont(font);
m_label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// Set stylesheets
// clang-format off
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
theme->base(),
theme->widgetForegroundPrimary(),
theme->widgetIndicator1());
m_label.setStyleSheet(valueQSS);
// clang-format on
}
void BaseWidget::setLabel(const QString &label)
{
if (m_label.text() != label)
m_label.setText(label);
}
void BaseWidget::setWidget(QWidget *widget, Qt::Alignment alignment, bool autoresize)
{
Q_ASSERT(widget != nullptr);
if (m_widget == nullptr)
{
m_widget = widget;
m_resizeWidget = autoresize;
m_layout.setSpacing(24);
m_layout.addWidget(m_widget);
m_layout.addWidget(&m_label);
m_layout.setAlignment(m_widget, alignment);
m_layout.setContentsMargins(24, 24, 24, 24);
setLayout(&m_layout);
}
}
void BaseWidget::resizeEvent(QResizeEvent *event)
{
// Get width & height (exluding layout margins & spacing)
auto width = event->size().width() - 72;
auto height = event->size().height() - 72;
// Get fonts & calculate size
auto labelFont = UI::Dashboard::getInstance()->monoFont();
auto gaugeFont = UI::Dashboard::getInstance()->monoFont();
labelFont.setPixelSize(width / 18);
gaugeFont.setPixelSize(width / 24);
// Set fonts
m_label.setFont(labelFont);
if (m_widget)
m_widget->setFont(gaugeFont);
// Set widget sizes
m_label.setMinimumWidth(width * 0.4);
m_label.setMaximumWidth(width * 0.4);
m_label.setMaximumHeight(height * 0.4);
// Set widget size
if (m_resizeWidget && m_widget)
{
m_widget->setMinimumWidth(width * 0.6);
m_widget->setMaximumWidth(width * 0.6);
}
// Accept event
event->accept();
// Emit resize signal
emit resized();
}

View File

@ -0,0 +1,58 @@
/*
* 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.
*/
#ifndef WIDGETS_COMMON_BASE_H
#define WIDGETS_COMMON_BASE_H
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
namespace Widgets
{
class BaseWidget : public QWidget
{
Q_OBJECT
signals:
void resized();
public:
BaseWidget();
void setLabel(const QString &label);
void setWidget(QWidget *widget, Qt::Alignment alignment = Qt::AlignHCenter,
bool autoresize = true);
protected:
void resizeEvent(QResizeEvent *event);
private:
int m_index;
QLabel m_label;
QWidget *m_widget;
bool m_resizeWidget;
QHBoxLayout m_layout;
};
}
#endif

View File

@ -0,0 +1,21 @@
/*
* 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.
*/

View File

@ -0,0 +1,21 @@
/*
* 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.
*/

View File

@ -65,34 +65,8 @@ Compass::Compass(const int index)
palette.setColor(QPalette::Text, theme->widgetIndicator1());
m_compass.setPalette(palette);
// Set window palette
QPalette windowPalette;
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
setPalette(windowPalette);
// Configure label style
QFont font = dash->monoFont();
font.setPixelSize(24);
m_label.setFont(font);
m_label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// Configure layout
m_layout.setSpacing(24);
m_layout.addWidget(&m_compass);
m_layout.addWidget(&m_label);
m_layout.setContentsMargins(24, 24, 24, 24);
m_layout.setAlignment(&m_compass, Qt::AlignHCenter);
setLayout(&m_layout);
// Set stylesheets
// clang-format off
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
theme->base(),
theme->widgetForegroundPrimary(),
theme->widgetIndicator1());
m_label.setStyleSheet(valueQSS);
// clang-format on
// Set widget pointer
setWidget(&m_compass);
// React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(update()));
@ -124,36 +98,6 @@ void Compass::update()
else if (text.length() == 3)
text.prepend("0");
m_label.setText(text);
setLabel(text);
}
}
/**
* Changes the size of the labels when the widget is resized
*/
void Compass::resizeEvent(QResizeEvent *event)
{
// Get width & height (exluding layout margins & spacing)
auto width = event->size().width() - 72;
auto height = event->size().height() - 72;
// Get fonts & calculate size
auto labelFont = UI::Dashboard::getInstance()->monoFont();
auto compassFont = UI::Dashboard::getInstance()->monoFont();
labelFont.setPixelSize(width / 18);
compassFont.setPixelSize(width / 24);
// Set fonts
m_label.setFont(labelFont);
m_compass.setFont(compassFont);
// Set widget sizes
m_label.setMinimumWidth(width * 0.4);
m_label.setMaximumWidth(width * 0.4);
m_label.setMaximumHeight(height * 0.4);
m_compass.setMinimumWidth(width * 0.6);
m_compass.setMaximumWidth(width * 0.6);
// Accept event
event->accept();
}

View File

@ -23,14 +23,13 @@
#ifndef WIDGETS_COMPASS_H
#define WIDGETS_COMPASS_H
#include <QLabel>
#include <QWidget>
#include <QwtCompass>
#include <QVBoxLayout>
#include "Common/BaseWidget.h"
namespace Widgets
{
class Compass : public QWidget
class Compass : public BaseWidget
{
Q_OBJECT
@ -40,14 +39,9 @@ public:
private slots:
void update();
protected:
void resizeEvent(QResizeEvent *event);
private:
int m_index;
QLabel m_label;
QwtCompass m_compass;
QHBoxLayout m_layout;
};
}

View File

@ -24,10 +24,6 @@
#include "UI/Dashboard.h"
#include "Misc/ThemeManager.h"
#include <QMouseEvent>
#include <QWheelEvent>
#include <QResizeEvent>
using namespace Widgets;
/**
@ -67,39 +63,13 @@ Gauge::Gauge(const int index)
#endif
// Set gauge palette
QPalette gaugePalette;
gaugePalette.setColor(QPalette::WindowText, theme->base());
gaugePalette.setColor(QPalette::Text, theme->widgetIndicator1());
m_gauge.setPalette(gaugePalette);
QPalette palette;
palette.setColor(QPalette::WindowText, theme->base());
palette.setColor(QPalette::Text, theme->widgetIndicator1());
m_gauge.setPalette(palette);
// Set window palette
QPalette windowPalette;
windowPalette.setColor(QPalette::Base, theme->datasetWindowBackground());
windowPalette.setColor(QPalette::Window, theme->datasetWindowBackground());
setPalette(windowPalette);
// Configure label style
QFont font = dash->monoFont();
font.setPixelSize(24);
m_label.setFont(font);
m_label.setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
// Configure layout
m_layout.setSpacing(24);
m_layout.addWidget(&m_gauge);
m_layout.addWidget(&m_label);
m_layout.setContentsMargins(24, 24, 24, 24);
m_layout.setAlignment(&m_gauge, Qt::AlignHCenter);
setLayout(&m_layout);
// Set stylesheets
// clang-format off
auto valueQSS = QSS("background-color:%1; color:%2; border:1px solid %3;",
theme->base(),
theme->widgetForegroundPrimary(),
theme->widgetIndicator1());
m_label.setStyleSheet(valueQSS);
// clang-format on
// Set widget pointer
setWidget(&m_gauge);
// React to dashboard events
connect(dash, SIGNAL(updated()), this, SLOT(updateData()));
@ -127,43 +97,6 @@ void Gauge::updateData()
#endif
auto value = dataset->value().toDouble();
m_gauge.setValue(dataset->value().toDouble());
m_label.setText(
QString("%1 %2").arg(QString::number(value, 'f', 2), dataset->units()));
setLabel(QString("%1 %2").arg(QString::number(value, 'f', 2), dataset->units()));
}
}
/**
* Changes the size of the labels when the widget is resized
*/
void Gauge::resizeEvent(QResizeEvent *event)
{
// Get width & height (exluding layout margins & spacing)
auto width = event->size().width() - 72;
auto height = event->size().height() - 72;
// Get fonts & calculate size
auto labelFont = UI::Dashboard::getInstance()->monoFont();
auto gaugeFont = UI::Dashboard::getInstance()->monoFont();
labelFont.setPixelSize(width / 18);
gaugeFont.setPixelSize(width / 24);
// Set fonts
m_label.setFont(labelFont);
m_gauge.setFont(gaugeFont);
// Set widget sizes
m_label.setMinimumWidth(width * 0.4);
m_label.setMaximumWidth(width * 0.4);
m_gauge.setMinimumWidth(width * 0.6);
m_gauge.setMaximumWidth(width * 0.6);
m_label.setMaximumHeight(height * 0.4);
// Accept event
event->accept();
}
void Gauge::mousePressEvent(QMouseEvent *event)
{
qDebug() << "Clicked";
event->ignore();
}

View File

@ -23,15 +23,12 @@
#ifndef WIDGETS_GAUGE_H
#define WIDGETS_GAUGE_H
#include <QLabel>
#include <QWidget>
#include <QHBoxLayout>
#include "AnalogGauge.h"
#include "Common/BaseWidget.h"
#include "Common/AnalogGauge.h"
namespace Widgets
{
class Gauge : public QWidget
class Gauge : public BaseWidget
{
Q_OBJECT
@ -41,15 +38,9 @@ public:
private slots:
void updateData();
protected:
void resizeEvent(QResizeEvent *event);
void mousePressEvent(QMouseEvent *event);
private:
int m_index;
QLabel m_label;
AnalogGauge m_gauge;
QHBoxLayout m_layout;
};
}