Added base class for pin body widgets & increased temperature of pin body colors (so that they're easier on the eyes)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -4,34 +4,16 @@
|
||||
#include <QMouseEvent>
|
||||
#include <utility>
|
||||
|
||||
#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<Targets::TargetPinState> 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();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
#include <QPainter>
|
||||
#include <QLayout>
|
||||
#include <QEvent>
|
||||
#include <QMenu>
|
||||
#include <QContextMenuEvent>
|
||||
|
||||
#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);
|
||||
|
||||
|
||||
@@ -4,43 +4,26 @@
|
||||
#include <QMouseEvent>
|
||||
#include <utility>
|
||||
|
||||
#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<Targets::TargetPinState> 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();
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#include <QEvent>
|
||||
|
||||
#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;
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
#pragma once
|
||||
|
||||
#include <QWidget>
|
||||
#include <QEvent>
|
||||
#include <QMouseEvent>
|
||||
|
||||
#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<Targets::TargetPinState> 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();
|
||||
};
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user