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:
Nav
2021-07-19 20:24:07 +01:00
parent dccf77fdb0
commit c0b99516d3
10 changed files with 185 additions and 215 deletions

View File

@@ -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);

View File

@@ -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();
};
}

View File

@@ -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;
}
}