diff --git a/CMakeLists.txt b/CMakeLists.txt index e6182ade..fc4bb065 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,7 @@ add_executable(Bloom src/Insight/UserInterfaces/InsightWindow/AboutWindow.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPackageWidget.hpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp + src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp index ba276790..011ace3c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.cpp @@ -15,28 +15,6 @@ void PinBodyWidget::paintEvent(QPaintEvent* event) { this->drawWidget(painter); } -bool PinBodyWidget::event(QEvent* event) { - if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { - switch (event->type()) { - case QEvent::Enter: { - this->hoverActive = true; - this->repaint(); - break; - } - case QEvent::Leave: { - this->hoverActive = false; - this->repaint(); - break; - } - default: { - break; - } - } - } - - return QWidget::event(event); -} - void PinBodyWidget::drawWidget(QPainter& painter) { auto parentWidget = this->parentWidget(); @@ -51,31 +29,6 @@ void PinBodyWidget::drawWidget(QPainter& painter) { auto pinColor = this->getBodyColor(); - if (this->pinDescriptor.type == TargetPinType::VCC) { - pinColor = QColor("#ff3d43"); - - } else if (this->pinDescriptor.type == TargetPinType::GND) { - pinColor = QColor("#575757"); - } - - if (this->pinState.has_value()) { - if (this->pinState->ioState.has_value() - && this->pinState->ioDirection.has_value() - && this->pinState->ioState.value() == TargetPinState::IoState::HIGH - ) { - pinColor = this->pinState->ioDirection.value() == TargetPinState::IoDirection::OUTPUT ? - QColor("#3D7F96") : QColor("#A47E3E"); - } - } - - if (!this->hoverActive) { - pinColor.setAlpha(225); - } - - if (!this->isEnabled()) { - pinColor.setAlpha(this->getDisableAlphaLevel()); - } - painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(pinColor); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp index a3f78689..382642ee 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp @@ -4,34 +4,16 @@ #include #include +#include "../TargetPinBodyWidget.hpp" #include "src/Targets/TargetPinDescriptor.hpp" namespace Bloom::Widgets::InsightTargetWidgets::Dip { - class PinBodyWidget: public QWidget + class PinBodyWidget: public TargetPinBodyWidget { - Q_OBJECT - Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true) - Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true) - - private: - Targets::TargetPinDescriptor pinDescriptor; - std::optional pinState; - QColor bodyColor = QColor("#AFB1B3"); - int disableAlphaLevel = 100; - protected: - bool hoverActive = false; void paintEvent(QPaintEvent* event) override; void drawWidget(QPainter& painter); - bool event(QEvent* event) override; - - void mouseReleaseEvent(QMouseEvent* event) override { - if (event->button() == Qt::MouseButton::LeftButton) { - emit this->clicked(); - } - QWidget::mouseReleaseEvent(event); - } public: static const int WIDTH = 30; @@ -40,32 +22,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip PinBodyWidget( QWidget* parent, Targets::TargetPinDescriptor pinDescriptor - ): QWidget(parent), pinDescriptor(std::move(pinDescriptor)) { + ): TargetPinBodyWidget(parent, std::move(pinDescriptor)) { this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT); this->setObjectName("target-pin-body"); } - - void setPinState(const Targets::TargetPinState& pinState) { - this->pinState = pinState; - } - - QColor getBodyColor() const { - return this->bodyColor; - } - - void setBodyColor(const QColor& color) { - this->bodyColor = color; - } - - int getDisableAlphaLevel() const { - return this->disableAlphaLevel; - } - - void setDisableAlphaLevel(int level) { - this->disableAlphaLevel = level; - } - - signals: - void clicked(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss index 153ad9eb..4ee46b8f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss @@ -16,15 +16,6 @@ color: #8a8a8d; } -#target-pin-number-top { -} - -#target-body { - qproperty-bodyColor: #A6A8AB; - qproperty-disableAlphaLevel: 100; -} - #target-pin-body { - qproperty-bodyColor: #A6A8AB; qproperty-disableAlphaLevel: 100; -} \ No newline at end of file +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp index 66f8846e..229aa20f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.cpp @@ -1,11 +1,7 @@ #include -#include #include -#include -#include #include "PinBodyWidget.hpp" -#include "src/Logger/Logger.hpp" using namespace Bloom::Widgets::InsightTargetWidgets::Qfp; using namespace Bloom::Targets; @@ -15,35 +11,7 @@ void PinBodyWidget::paintEvent(QPaintEvent* event) { this->drawWidget(painter); } -bool PinBodyWidget::event(QEvent* event) { - if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) { - switch (event->type()) { - case QEvent::Enter: { - this->hoverActive = true; - this->repaint(); - break; - } - case QEvent::Leave: { - this->hoverActive = false; - this->repaint(); - break; - } - default: { - break; - } - } - } - - return QWidget::event(event); -} - void PinBodyWidget::drawWidget(QPainter& painter) { - auto parentWidget = this->parentWidget(); - - if (parentWidget == nullptr) { - Logger::error("PinBodyWidget requires a parent widget"); - } - painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true); auto pinWidth = this->isVertical ? PinBodyWidget::WIDTH : PinBodyWidget::HEIGHT; auto pinHeight = this->isVertical ? PinBodyWidget::HEIGHT : PinBodyWidget::WIDTH; @@ -51,31 +19,6 @@ void PinBodyWidget::drawWidget(QPainter& painter) { auto pinColor = this->getBodyColor(); - if (this->pinDescriptor.type == TargetPinType::VCC) { - pinColor = QColor("#ff3d43"); - - } else if (this->pinDescriptor.type == TargetPinType::GND) { - pinColor = QColor("#575757"); - } - - if (this->pinState.has_value()) { - if (this->pinState->ioState.has_value() - && this->pinState->ioDirection.has_value() - && this->pinState->ioState.value() == TargetPinState::IoState::HIGH - ) { - pinColor = this->pinState->ioDirection.value() == TargetPinState::IoDirection::OUTPUT ? - QColor("#3D7F96") : QColor("#A47E3E"); - } - } - - if (!this->hoverActive) { - pinColor.setAlpha(225); - } - - if (!this->isEnabled()) { - pinColor.setAlpha(this->getDisableAlphaLevel()); - } - painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(pinColor); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp index 92b2ff84..40aa05a5 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinBodyWidget.hpp @@ -4,43 +4,26 @@ #include #include +#include "../TargetPinBodyWidget.hpp" #include "src/Targets/TargetPinDescriptor.hpp" namespace Bloom::Widgets::InsightTargetWidgets::Qfp { - class PinBodyWidget: public QWidget + class PinBodyWidget: public TargetPinBodyWidget { - Q_OBJECT - Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true) - Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true) - private: - Targets::TargetPinDescriptor pinDescriptor; - std::optional pinState; - QColor bodyColor = QColor("#AFB1B3"); - int disableAlphaLevel = 100; bool isVertical = false; protected: - bool hoverActive = false; void paintEvent(QPaintEvent* event) override; void drawWidget(QPainter& painter); - bool event(QEvent* event) override; - - void mouseReleaseEvent(QMouseEvent* event) override { - if (event->button() == Qt::MouseButton::LeftButton) { - emit this->clicked(); - } - - QWidget::mouseReleaseEvent(event); - } public: static const int WIDTH = 30; static const int HEIGHT = 40; PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical): - QWidget(parent), pinDescriptor(std::move(pinDescriptor)), isVertical(isVertical) { + TargetPinBodyWidget(parent, std::move(pinDescriptor)), isVertical(isVertical) { this->setObjectName("target-pin-body"); if (isVertical) { @@ -50,28 +33,5 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp this->setFixedSize(PinBodyWidget::HEIGHT, PinBodyWidget::WIDTH); } } - - void setPinState(const Targets::TargetPinState& pinState) { - this->pinState = pinState; - } - - QColor getBodyColor() const { - return this->bodyColor; - } - - void setBodyColor(const QColor& color) { - this->bodyColor = color; - } - - int getDisableAlphaLevel() const { - return this->disableAlphaLevel; - } - - void setDisableAlphaLevel(int level) { - this->disableAlphaLevel = level; - } - - signals: - void clicked(); }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss index d1edd0ad..4ee46b8f 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss @@ -16,15 +16,6 @@ color: #8a8a8d; } -#target-pin-number { -} - -#target-body { - qproperty-bodyColor: #A6A8AB; - qproperty-disableAlphaLevel: 100; -} - #target-pin-body { - qproperty-bodyColor: #A6A8AB; qproperty-disableAlphaLevel: 100; -} \ No newline at end of file +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp new file mode 100644 index 00000000..6e33fd5c --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.cpp @@ -0,0 +1,62 @@ +#include + +#include "TargetPinBodyWidget.hpp" + +using namespace Bloom::Widgets::InsightTargetWidgets; +using namespace Bloom::Targets; + +bool TargetPinBodyWidget::event(QEvent* event) { + if (this->isEnabled() + && this->pinState.has_value() + && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT + ) { + switch (event->type()) { + case QEvent::Enter: { + this->hoverActive = true; + this->repaint(); + break; + } + case QEvent::Leave: { + this->hoverActive = false; + this->repaint(); + break; + } + default: { + break; + } + } + } + + return QWidget::event(event); +} + +QColor TargetPinBodyWidget::getBodyColor() { + auto pinColor = this->defaultBodyColor; + + if (this->pinDescriptor.type == TargetPinType::VCC) { + pinColor = this->vccBodyColor; + + } else if (this->pinDescriptor.type == TargetPinType::GND) { + pinColor = this->gndBodyColor; + + } else if (this->pinDescriptor.type == TargetPinType::GPIO) { + if (this->pinState.has_value() + && this->pinState->ioState.has_value() + && this->pinState->ioDirection.has_value() + && this->pinState->ioState.value() == TargetPinState::IoState::HIGH + ) { + pinColor = this->pinState->ioDirection.value() == TargetPinState::IoDirection::OUTPUT ? + this->outputHighBodyColor : this->inputHighBodyColor; + } + + if (!this->hoverActive) { + pinColor.setAlpha(225); + } + } + + if (!this->isEnabled()) { + pinColor.setAlpha(this->disableAlphaLevel); + } + + return pinColor; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp new file mode 100644 index 00000000..d6d82c80 --- /dev/null +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinBodyWidget.hpp @@ -0,0 +1,113 @@ +#pragma once + +#include +#include +#include + +#include "src/Targets/TargetVariant.hpp" +#include "src/Targets/TargetPinDescriptor.hpp" + +namespace Bloom::Widgets::InsightTargetWidgets +{ + class TargetPinBodyWidget: public QWidget + { + Q_OBJECT + /* + * Pin body colors can be set in QSS files. + */ + Q_PROPERTY(QColor defaultBodyColor READ getDefaultBodyColor WRITE setDefaultBodyColor DESIGNABLE true) + Q_PROPERTY(QColor vccBodyColor READ getVccBodyColor WRITE setVccBodyColor DESIGNABLE true) + Q_PROPERTY(QColor gndBodyColor READ getGndBodyColor WRITE setGndBodyColor DESIGNABLE true) + Q_PROPERTY(QColor outputHighBodyColor READ getOutputHighBodyColor WRITE setOutputHighBodyColor DESIGNABLE true) + Q_PROPERTY(QColor inputHighBodyColor READ getInputHighBodyColor WRITE setInputHighBodyColor DESIGNABLE true) + + Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true) + + protected: + Targets::TargetPinDescriptor pinDescriptor; + std::optional pinState; + + bool hoverActive = false; + + QColor defaultBodyColor = QColor("#AFB1B3"); + QColor vccBodyColor = QColor("#764935"); + QColor gndBodyColor = QColor("#46484A"); + QColor outputHighBodyColor = QColor("#237B77"); + QColor inputHighBodyColor = QColor("#A47E3E"); + + int disableAlphaLevel = 100; + + bool event(QEvent* event) override; + + void mouseReleaseEvent(QMouseEvent* event) override { + if (event->button() == Qt::MouseButton::LeftButton) { + emit this->clicked(); + } + + QWidget::mouseReleaseEvent(event); + } + + public: + TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor): + QWidget(parent), pinDescriptor(std::move(pinDescriptor)) { + this->setObjectName("target-pin-body"); + } + + QColor getBodyColor(); + + void setPinState(const Targets::TargetPinState& pinState) { + this->pinState = pinState; + } + + const QColor& getDefaultBodyColor() const { + return this->defaultBodyColor; + } + + void setDefaultBodyColor(const QColor& color) { + this->defaultBodyColor = color; + } + + const QColor& getVccBodyColor() const { + return this->vccBodyColor; + } + + void setVccBodyColor(const QColor& vccBodyColor) { + this->vccBodyColor = vccBodyColor; + } + + const QColor& getGndBodyColor() const { + return this->gndBodyColor; + } + + void setGndBodyColor(const QColor& gndBodyColor) { + this->gndBodyColor = gndBodyColor; + } + + const QColor& getOutputHighBodyColor() const { + return this->outputHighBodyColor; + } + + void setOutputHighBodyColor(const QColor& outputHighBodyColor) { + this->outputHighBodyColor = outputHighBodyColor; + } + + const QColor& getInputHighBodyColor() const { + return this->inputHighBodyColor; + } + + void setInputHighBodyColor(const QColor& inputHighBodyColor) { + this->inputHighBodyColor = inputHighBodyColor; + } + + int getDisableAlphaLevel() const { + return this->disableAlphaLevel; + } + + void setDisableAlphaLevel(int level) { + this->disableAlphaLevel = level; + } + + signals: + void clicked(); + }; +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp index c2879930..0f12138b 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/TargetPinWidget.hpp @@ -47,10 +47,7 @@ namespace Bloom::Widgets::InsightTargetWidgets } void setDisabled(bool disabled) { - if (pinDescriptor.type != Targets::TargetPinType::GND - && pinDescriptor.type != Targets::TargetPinType::VCC - && pinDescriptor.type != Targets::TargetPinType::UNKNOWN - ) { + if (pinDescriptor.type != Targets::TargetPinType::UNKNOWN) { QWidget::setDisabled(disabled); } else {