This commit is contained in:
Nav
2021-06-21 00:14:31 +01:00
parent a9c6171ac2
commit 139e880646
20 changed files with 45 additions and 55 deletions

View File

@@ -47,12 +47,12 @@ namespace Bloom
* Insight consists of two threads - the main thread where the main Qt event loop runs (for the GUI), and * Insight consists of two threads - the main thread where the main Qt event loop runs (for the GUI), and
* a single worker thread to handle any blocking/time-expensive operations. * a single worker thread to handle any blocking/time-expensive operations.
*/ */
QThread* workerThread; QThread* workerThread = nullptr;
void startup(); void startup();
public: public:
Insight(EventManager& eventManager): eventManager(eventManager) {}; explicit Insight(EventManager& eventManager): eventManager(eventManager) {};
void setApplicationConfig(const ApplicationConfig& applicationConfig) { void setApplicationConfig(const ApplicationConfig& applicationConfig) {
this->applicationConfig = applicationConfig; this->applicationConfig = applicationConfig;

View File

@@ -40,7 +40,7 @@ namespace Bloom
void onTargetControllerStateReported(Events::EventPointer<Events::TargetControllerStateReported> event); void onTargetControllerStateReported(Events::EventPointer<Events::TargetControllerStateReported> event);
public: public:
InsightWorker(EventManager& eventManager): eventManager(eventManager) {}; explicit InsightWorker(EventManager& eventManager): eventManager(eventManager) {};
void dispatchEvents() { void dispatchEvents() {
this->eventListener->dispatchCurrentEvents(); this->eventListener->dispatchCurrentEvents();

View File

@@ -14,7 +14,7 @@ namespace Bloom
QWidget* windowWidget = nullptr; QWidget* windowWidget = nullptr;
public: public:
AboutWindow(QWidget* parent); explicit AboutWindow(QWidget* parent);
void show() { void show() {
if (this->windowWidget != nullptr) { if (this->windowWidget != nullptr) {

View File

@@ -1,5 +1,6 @@
#include <QtUiTools> #include <QtUiTools>
#include <QtSvg/QtSvg> #include <QtSvg/QtSvg>
#include <utility>
#include "InsightWindow.hpp" #include "InsightWindow.hpp"
#include "AboutWindow.hpp" #include "AboutWindow.hpp"
@@ -25,7 +26,7 @@ void InsightWindow::init(
QApplication& application, QApplication& application,
TargetDescriptor targetDescriptor TargetDescriptor targetDescriptor
) { ) {
this->targetDescriptor = targetDescriptor; this->targetDescriptor = std::move(targetDescriptor);
auto mainWindowUiFile = QFile( auto mainWindowUiFile = QFile(
QString::fromStdString(Paths::compiledResourcesPath() QString::fromStdString(Paths::compiledResourcesPath()
@@ -50,7 +51,7 @@ void InsightWindow::init(
this->mainWindowWidget = uiLoader.load(&mainWindowUiFile); this->mainWindowWidget = uiLoader.load(&mainWindowUiFile);
this->mainWindowWidget->setStyleSheet(mainWindowStylesheet.readAll()); this->mainWindowWidget->setStyleSheet(mainWindowStylesheet.readAll());
application.setWindowIcon(QIcon( QApplication::setWindowIcon(QIcon(
QString::fromStdString(Paths::compiledResourcesPath() QString::fromStdString(Paths::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Images/BloomIcon.svg" + "/src/Insight/UserInterfaces/InsightWindow/Images/BloomIcon.svg"
) )
@@ -166,7 +167,7 @@ void InsightWindow::activate() {
QString::fromStdString(targetVariant.name + " (" + targetVariant.packageName + ")") QString::fromStdString(targetVariant.name + " (" + targetVariant.packageName + ")")
); );
if (this->isVariantSupported(targetVariant)) { if (InsightWindow::isVariantSupported(targetVariant)) {
auto supportedVariantPtr = &(this->supportedVariantsByName.insert( auto supportedVariantPtr = &(this->supportedVariantsByName.insert(
std::pair(QString::fromStdString(targetVariant.name).toLower(), targetVariant) std::pair(QString::fromStdString(targetVariant.name).toLower(), targetVariant)
).first->second); ).first->second);

View File

@@ -48,7 +48,7 @@ namespace Bloom
const Targets::TargetVariant* selectedVariant = nullptr; const Targets::TargetVariant* selectedVariant = nullptr;
bool uiDisabled = false; bool uiDisabled = false;
bool isVariantSupported(const Targets::TargetVariant& variant); static bool isVariantSupported(const Targets::TargetVariant& variant);
void selectVariant(const Targets::TargetVariant* variant); void selectVariant(const Targets::TargetVariant* variant);
@@ -84,7 +84,7 @@ namespace Bloom
void onTargetIoPortsUpdate(); void onTargetIoPortsUpdate();
void close(); void close();
void openReportIssuesUrl(); void openReportIssuesUrl();
void openGettingStartedUrl(); static void openGettingStartedUrl();
void openAboutWindow(); void openAboutWindow();
void togglePinIoState(InsightTargetWidgets::TargetPinWidget* pinWidget); void togglePinIoState(InsightTargetWidgets::TargetPinWidget* pinWidget);

View File

@@ -32,7 +32,6 @@ void BodyWidget::drawWidget(QPainter& painter) {
painter.setPen(Qt::PenStyle::NoPen); painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(targetBodyColor); painter.setBrush(targetBodyColor);
auto parentContainerWidth = parentWidget->width(); auto parentContainerWidth = parentWidget->width();
// this->setFixedSize(parentContainerWidth, parentContainerHeight);
auto targetBodyHeight = 150; auto targetBodyHeight = 150;
auto targetBodyWidth = parentContainerWidth; auto targetBodyWidth = parentContainerWidth;

View File

@@ -16,23 +16,23 @@ namespace Bloom::InsightTargetWidgets::Dip
int disableAlphaLevel = 100; int disableAlphaLevel = 100;
protected: protected:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:
BodyWidget(QWidget* parent): QWidget(parent) { explicit BodyWidget(QWidget* parent): QWidget(parent) {
this->setObjectName("target-body"); this->setObjectName("target-body");
} }
QColor getBodyColor() const { [[nodiscard]] QColor getBodyColor() const {
return this->bodyColor; return this->bodyColor;
} }
void setBodyColor(QColor color) { void setBodyColor(const QColor& color) {
this->bodyColor = color; this->bodyColor = color;
} }
int getDisableAlphaLevel() const { [[nodiscard]] int getDisableAlphaLevel() const {
return this->disableAlphaLevel; return this->disableAlphaLevel;
} }

View File

@@ -25,8 +25,8 @@ namespace Bloom::InsightTargetWidgets::Dip
BodyWidget* bodyWidget = nullptr; BodyWidget* bodyWidget = nullptr;
protected: protected:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event) override;
void resizeEvent(QResizeEvent* event); void resizeEvent(QResizeEvent* event) override;
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:

View File

@@ -1,25 +1,21 @@
#include <QPainter> #include <QPainter>
#include <QLayout> #include <QLayout>
#include <cmath>
#include <QEvent> #include <QEvent>
#include <QMenu> #include <QMenu>
#include <QContextMenuEvent> #include <QContextMenuEvent>
#include "PinBodyWidget.hpp" #include "PinBodyWidget.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::InsightTargetWidgets::Dip; using namespace Bloom::InsightTargetWidgets::Dip;
using namespace Bloom::Targets; using namespace Bloom::Targets;
using namespace Bloom::Exceptions;
void PinBodyWidget::paintEvent(QPaintEvent* event) { void PinBodyWidget::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this); auto painter = QPainter(this);
this->drawWidget(painter); this->drawWidget(painter);
} }
bool PinBodyWidget::event(QEvent* event) bool PinBodyWidget::event(QEvent* event) {
{
if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) {
switch (event->type()) { switch (event->type()) {
case QEvent::Enter: { case QEvent::Enter: {

View File

@@ -2,6 +2,7 @@
#include <QWidget> #include <QWidget>
#include <QMouseEvent> #include <QMouseEvent>
#include <utility>
#include "src/Targets/TargetPinDescriptor.hpp" #include "src/Targets/TargetPinDescriptor.hpp"
@@ -38,8 +39,8 @@ namespace Bloom::InsightTargetWidgets::Dip
PinBodyWidget( PinBodyWidget(
QWidget* parent, QWidget* parent,
const Targets::TargetPinDescriptor& pinDescriptor Targets::TargetPinDescriptor pinDescriptor
): QWidget(parent), pinDescriptor(pinDescriptor) { ): QWidget(parent), pinDescriptor(std::move(pinDescriptor)) {
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT); this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
this->setObjectName("target-pin-body"); this->setObjectName("target-pin-body");
} }
@@ -52,7 +53,7 @@ namespace Bloom::InsightTargetWidgets::Dip
return this->bodyColor; return this->bodyColor;
} }
void setBodyColor(QColor color) { void setBodyColor(const QColor& color) {
this->bodyColor = color; this->bodyColor = color;
} }

View File

@@ -19,12 +19,8 @@ namespace Bloom::InsightTargetWidgets::Dip
QLabel* pinDirectionLabel = nullptr; QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr; PinBodyWidget* bodyWidget = nullptr;
void setLabelColor(QString hexColor) { void setLabelColor(const QString& hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }"); auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNumberLabel != nullptr) {
// this->pinNumberLabel->setStyleSheet(style);
}
if (this->pinNameLabel != nullptr) { if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style); this->pinNameLabel->setStyleSheet(style);
} }
@@ -43,7 +39,7 @@ namespace Bloom::InsightTargetWidgets::Dip
const Targets::TargetVariant& targetVariant const Targets::TargetVariant& targetVariant
); );
virtual void updatePinState(const Targets::TargetPinState& pinState) override { void updatePinState(const Targets::TargetPinState& pinState) override {
TargetPinWidget::updatePinState(pinState); TargetPinWidget::updatePinState(pinState);
if (pinState.ioDirection.has_value()) { if (pinState.ioDirection.has_value()) {

View File

@@ -1,5 +1,4 @@
#include <QPainter> #include <QPainter>
#include <cmath>
#include "BodyWidget.hpp" #include "BodyWidget.hpp"
#include "src/Logger/Logger.hpp" #include "src/Logger/Logger.hpp"
@@ -48,4 +47,3 @@ void BodyWidget::drawWidget(QPainter& painter) {
15 15
)); ));
} }

View File

@@ -16,15 +16,15 @@ namespace Bloom::InsightTargetWidgets::Qfp
int disableAlphaLevel = 100; int disableAlphaLevel = 100;
protected: protected:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:
BodyWidget(QWidget* parent): QWidget(parent) { explicit BodyWidget(QWidget* parent): QWidget(parent) {
this->setObjectName("target-body"); this->setObjectName("target-body");
} }
QColor getBodyColor() const { [[nodiscard]] QColor getBodyColor() const {
return this->bodyColor; return this->bodyColor;
} }
@@ -32,7 +32,7 @@ namespace Bloom::InsightTargetWidgets::Qfp
this->bodyColor = color; this->bodyColor = color;
} }
int getDisableAlphaLevel() const { [[nodiscard]] int getDisableAlphaLevel() const {
return this->disableAlphaLevel; return this->disableAlphaLevel;
} }

View File

@@ -15,8 +15,7 @@ void PinBodyWidget::paintEvent(QPaintEvent* event) {
this->drawWidget(painter); this->drawWidget(painter);
} }
bool PinBodyWidget::event(QEvent* event) bool PinBodyWidget::event(QEvent* event) {
{
if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) {
switch (event->type()) { switch (event->type()) {
case QEvent::Enter: { case QEvent::Enter: {
@@ -86,4 +85,4 @@ void PinBodyWidget::drawWidget(QPainter& painter) {
pinWidth, pinWidth,
pinHeight pinHeight
); );
} }

View File

@@ -2,6 +2,7 @@
#include <QWidget> #include <QWidget>
#include <QMouseEvent> #include <QMouseEvent>
#include <utility>
#include "src/Targets/TargetPinDescriptor.hpp" #include "src/Targets/TargetPinDescriptor.hpp"
@@ -38,8 +39,8 @@ namespace Bloom::InsightTargetWidgets::Qfp
static const int WIDTH = 30; static const int WIDTH = 30;
static const int HEIGHT = 40; static const int HEIGHT = 40;
PinBodyWidget(QWidget* parent, const Targets::TargetPinDescriptor& pinDescriptor, bool isVertical): PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical):
QWidget(parent), pinDescriptor(pinDescriptor), isVertical(isVertical) { QWidget(parent), pinDescriptor(std::move(pinDescriptor)), isVertical(isVertical) {
this->setObjectName("target-pin-body"); this->setObjectName("target-pin-body");
if (isVertical) { if (isVertical) {
@@ -58,7 +59,7 @@ namespace Bloom::InsightTargetWidgets::Qfp
return this->bodyColor; return this->bodyColor;
} }
void setBodyColor(QColor color) { void setBodyColor(const QColor& color) {
this->bodyColor = color; this->bodyColor = color;
} }

View File

@@ -24,11 +24,8 @@ namespace Bloom::InsightTargetWidgets::Qfp
bool isRightLayout = false; bool isRightLayout = false;
bool isTopLayout = false; bool isTopLayout = false;
void setLabelColor(QString hexColor) { void setLabelColor(const QString& hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }"); auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNumberLabel != nullptr) {
// this->pinNumberLabel->setStyleSheet(style);
}
if (this->pinNameLabel != nullptr) { if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style); this->pinNameLabel->setStyleSheet(style);
@@ -54,7 +51,7 @@ namespace Bloom::InsightTargetWidgets::Qfp
const Targets::TargetVariant& targetVariant const Targets::TargetVariant& targetVariant
); );
virtual void updatePinState(const Targets::TargetPinState& pinState) override { void updatePinState(const Targets::TargetPinState& pinState) override {
TargetPinWidget::updatePinState(pinState); TargetPinWidget::updatePinState(pinState);
if (pinState.ioDirection.has_value()) { if (pinState.ioDirection.has_value()) {

View File

@@ -28,7 +28,7 @@ namespace Bloom::InsightTargetWidgets::Qfp
BodyWidget* bodyWidget = nullptr; BodyWidget* bodyWidget = nullptr;
protected: protected:
void paintEvent(QPaintEvent* event); void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter); void drawWidget(QPainter& painter);
public: public:

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <utility>
#include <vector> #include <vector>
#include <map> #include <map>
@@ -21,8 +22,8 @@ namespace Bloom::InsightTargetWidgets
std::vector<TargetPinWidget*> pinWidgets; std::vector<TargetPinWidget*> pinWidgets;
public: public:
TargetPackageWidget(const Targets::TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent): TargetPackageWidget(Targets::TargetVariant targetVariant, QObject* insightWindowObj, QWidget* parent):
QWidget(parent), targetVariant(targetVariant) {}; QWidget(parent), targetVariant(std::move(targetVariant)) {};
virtual void updatePinStates(std::map<int, Targets::TargetPinState> pinStatesByNumber) { virtual void updatePinStates(std::map<int, Targets::TargetPinState> pinStatesByNumber) {
for (auto& pinWidget : this->pinWidgets) { for (auto& pinWidget : this->pinWidgets) {

View File

@@ -1,6 +1,7 @@
#pragma once #pragma once
#include <QWidget> #include <QWidget>
#include <utility>
#include "src/Targets/TargetVariant.hpp" #include "src/Targets/TargetVariant.hpp"
#include "src/Targets/TargetPinDescriptor.hpp" #include "src/Targets/TargetPinDescriptor.hpp"
@@ -19,9 +20,9 @@ namespace Bloom::InsightTargetWidgets
public: public:
TargetPinWidget( TargetPinWidget(
QWidget* parent, QWidget* parent,
const Targets::TargetPinDescriptor& pinDescriptor, Targets::TargetPinDescriptor pinDescriptor,
const Targets::TargetVariant& targetVariant Targets::TargetVariant targetVariant
): QWidget(parent), targetVariant(targetVariant), pinDescriptor(pinDescriptor) { ): QWidget(parent), targetVariant(std::move(targetVariant)), pinDescriptor(std::move(pinDescriptor)) {
this->setDisabled(false); this->setDisabled(false);
}; };

View File

@@ -29,7 +29,7 @@ namespace Bloom
LogEntry(std::string message, LogLevel logLevel): message(std::move(message)), logLevel(logLevel) { LogEntry(std::string message, LogLevel logLevel): message(std::move(message)), logLevel(logLevel) {
// Get thread name // Get thread name
std::array<char, 16> threadNameBuf; std::array<char, 16> threadNameBuf = {};
if (pthread_getname_np(pthread_self(), threadNameBuf.data(), threadNameBuf.size()) == 0) { if (pthread_getname_np(pthread_self(), threadNameBuf.data(), threadNameBuf.size()) == 0) {
/* /*