Manually drawing DIP widget pin labels
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
#include "BodyWidget.hpp"
|
#include "BodyWidget.hpp"
|
||||||
|
|
||||||
#include <QPainter>
|
|
||||||
|
|
||||||
#include "src/Exceptions/Exception.hpp"
|
|
||||||
|
|
||||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||||
using namespace Bloom::Exceptions;
|
|
||||||
|
BodyWidget::BodyWidget(QWidget* parent): QWidget(parent) {
|
||||||
|
this->setObjectName("target-body");
|
||||||
|
|
||||||
|
this->setFixedHeight(BodyWidget::HEIGHT);
|
||||||
|
}
|
||||||
|
|
||||||
void BodyWidget::paintEvent(QPaintEvent* event) {
|
void BodyWidget::paintEvent(QPaintEvent* event) {
|
||||||
auto painter = QPainter(this);
|
auto painter = QPainter(this);
|
||||||
@@ -13,17 +14,11 @@ void BodyWidget::paintEvent(QPaintEvent* event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void BodyWidget::drawWidget(QPainter& painter) {
|
void BodyWidget::drawWidget(QPainter& painter) {
|
||||||
auto parentWidget = this->parentWidget();
|
|
||||||
|
|
||||||
if (parentWidget == nullptr) {
|
|
||||||
throw Exception("BodyWidget requires a parent widget");
|
|
||||||
}
|
|
||||||
|
|
||||||
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||||
|
|
||||||
// Draw target body
|
// Draw target body
|
||||||
auto targetBodyColor = this->getBodyColor();
|
auto targetBodyColor = this->getBodyColor();
|
||||||
auto backgroundColor = QColor("#373835");
|
auto backgroundColor = QColor(0x37, 0x38, 0x35);
|
||||||
|
|
||||||
if (!this->isEnabled()) {
|
if (!this->isEnabled()) {
|
||||||
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
||||||
@@ -31,7 +26,6 @@ void BodyWidget::drawWidget(QPainter& painter) {
|
|||||||
|
|
||||||
painter.setPen(Qt::PenStyle::NoPen);
|
painter.setPen(Qt::PenStyle::NoPen);
|
||||||
painter.setBrush(targetBodyColor);
|
painter.setBrush(targetBodyColor);
|
||||||
const auto targetBodyHeight = this->height();
|
|
||||||
|
|
||||||
auto targetBodyPoint = QPoint(
|
auto targetBodyPoint = QPoint(
|
||||||
0,
|
0,
|
||||||
@@ -42,22 +36,22 @@ void BodyWidget::drawWidget(QPainter& painter) {
|
|||||||
targetBodyPoint.x(),
|
targetBodyPoint.x(),
|
||||||
targetBodyPoint.y(),
|
targetBodyPoint.y(),
|
||||||
this->width(),
|
this->width(),
|
||||||
targetBodyHeight
|
BodyWidget::HEIGHT
|
||||||
);
|
);
|
||||||
|
|
||||||
painter.setPen(Qt::PenStyle::NoPen);
|
painter.setPen(Qt::PenStyle::NoPen);
|
||||||
painter.setBrush(backgroundColor);
|
painter.setBrush(backgroundColor);
|
||||||
painter.drawEllipse(QRectF(
|
painter.drawEllipse(QRectF(
|
||||||
targetBodyPoint.x() + 10,
|
targetBodyPoint.x() + 10,
|
||||||
targetBodyPoint.y() + (targetBodyHeight - 30),
|
targetBodyPoint.y() + (BodyWidget::HEIGHT - 30),
|
||||||
18,
|
18,
|
||||||
18
|
18
|
||||||
));
|
));
|
||||||
|
|
||||||
painter.drawEllipse(QRectF(
|
painter.drawEllipse(QRectF(
|
||||||
targetBodyPoint.x() - 15,
|
targetBodyPoint.x() - 15,
|
||||||
targetBodyPoint.y() + (targetBodyHeight / 2) - 15,
|
targetBodyPoint.y() + (BodyWidget::HEIGHT / 2) - 15,
|
||||||
28,
|
24,
|
||||||
28
|
24
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||||
{
|
{
|
||||||
@@ -11,9 +12,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
|
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit BodyWidget(QWidget* parent): QWidget(parent) {
|
static constexpr int HEIGHT = 130;
|
||||||
this->setObjectName("target-body");
|
|
||||||
}
|
explicit BodyWidget(QWidget* parent);
|
||||||
|
|
||||||
[[nodiscard]] QColor getBodyColor() const {
|
[[nodiscard]] QColor getBodyColor() const {
|
||||||
return this->bodyColor;
|
return this->bodyColor;
|
||||||
|
|||||||
@@ -30,18 +30,20 @@ DualInlinePackageWidget::DualInlinePackageWidget(
|
|||||||
this->layout = new QVBoxLayout();
|
this->layout = new QVBoxLayout();
|
||||||
this->layout->setSpacing(PinWidget::WIDTH_SPACING);
|
this->layout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||||
|
this->layout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||||
|
|
||||||
this->topPinLayout = new QHBoxLayout();
|
this->topPinLayout = new QHBoxLayout();
|
||||||
this->topPinLayout->setSpacing(0);
|
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||||
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||||
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->bottomPinLayout = new QHBoxLayout();
|
this->bottomPinLayout = new QHBoxLayout();
|
||||||
this->bottomPinLayout->setSpacing(0);
|
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||||
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||||
|
|
||||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||||
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||||
this->pinWidgets.push_back(pinWidget);
|
this->pinWidgets.push_back(pinWidget);
|
||||||
|
TargetPackageWidget::pinWidgets.push_back(pinWidget);
|
||||||
|
|
||||||
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
|
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
|
||||||
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
@@ -52,23 +54,33 @@ DualInlinePackageWidget::DualInlinePackageWidget(
|
|||||||
|
|
||||||
this->layout->addLayout(this->topPinLayout);
|
this->layout->addLayout(this->topPinLayout);
|
||||||
this->bodyWidget = new BodyWidget(this);
|
this->bodyWidget = new BodyWidget(this);
|
||||||
this->layout->addWidget(this->bodyWidget);
|
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignVCenter);
|
||||||
this->layout->addLayout(this->bottomPinLayout);
|
this->layout->addLayout(this->bottomPinLayout);
|
||||||
this->setLayout(this->layout);
|
this->setLayout(this->layout);
|
||||||
|
|
||||||
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
|
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
|
||||||
* static_cast<int>(this->pinWidgets.size() / 2)) + 46;
|
* static_cast<int>(this->pinWidgets.size() / 2)) - PinWidget::WIDTH_SPACING + 46;
|
||||||
const auto bodyWidgetHeight = 150;
|
|
||||||
|
|
||||||
const auto width = bodyWidgetWidth;
|
const auto width = bodyWidgetWidth;
|
||||||
const auto height = (PinWidget::MAXIMUM_HEIGHT * 2) + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2);
|
const auto height = (
|
||||||
|
(
|
||||||
|
PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING + PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||||
|
+ PinWidget::PIN_LABEL_SHORT_LINE_LENGTH + (
|
||||||
|
(PinWidget::LABEL_HEIGHT + PinWidget::PIN_LABEL_SPACING) * 2
|
||||||
|
)
|
||||||
|
) * 2) + BodyWidget::HEIGHT;
|
||||||
|
|
||||||
this->bodyWidget->setGeometry(0, PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING, width, bodyWidgetHeight);
|
this->bodyWidget->setGeometry(
|
||||||
|
0,
|
||||||
|
PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING,
|
||||||
|
width,
|
||||||
|
BodyWidget::HEIGHT
|
||||||
|
);
|
||||||
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
|
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
|
||||||
this->bottomPinLayout->setGeometry(
|
this->bottomPinLayout->setGeometry(
|
||||||
QRect(
|
QRect(
|
||||||
0,
|
0,
|
||||||
(PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2)),
|
(PinWidget::MAXIMUM_HEIGHT + BodyWidget::HEIGHT + (PinWidget::WIDTH_SPACING * 2)),
|
||||||
width,
|
width,
|
||||||
PinWidget::MAXIMUM_HEIGHT
|
PinWidget::MAXIMUM_HEIGHT
|
||||||
)
|
)
|
||||||
@@ -85,3 +97,151 @@ DualInlinePackageWidget::DualInlinePackageWidget(
|
|||||||
height
|
height
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DualInlinePackageWidget::paintEvent(QPaintEvent* event) {
|
||||||
|
auto painter = QPainter(this);
|
||||||
|
this->drawWidget(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void DualInlinePackageWidget::drawWidget(QPainter& painter) {
|
||||||
|
using Targets::TargetPinState;
|
||||||
|
|
||||||
|
static auto pinNameFont = QFont("'Ubuntu', sans-serif");
|
||||||
|
static auto pinDirectionFont = pinNameFont;
|
||||||
|
pinNameFont.setPixelSize(11);
|
||||||
|
pinDirectionFont.setPixelSize(10);
|
||||||
|
|
||||||
|
static const auto lineColor = QColor(0x4F, 0x4F, 0x4F);
|
||||||
|
static const auto pinNameFontColor = QColor(0xA6, 0xA7, 0xAA);
|
||||||
|
static const auto pinDirectionFontColor = QColor(0x8A, 0x8A, 0x8D);
|
||||||
|
static const auto pinChangedFontColor = QColor(0x4D, 0x7B, 0xBA);
|
||||||
|
|
||||||
|
static const auto inDirectionText = QString("IN");
|
||||||
|
static const auto outDirectionText = QString("OUT");
|
||||||
|
|
||||||
|
for (const auto* pinWidget : this->pinWidgets) {
|
||||||
|
const auto pinGeoPosition = pinWidget->pos();
|
||||||
|
const auto& pinState = pinWidget->getPinState();
|
||||||
|
const auto pinStateChanged = pinWidget->hasPinStateChanged();
|
||||||
|
|
||||||
|
painter.setFont(pinNameFont);
|
||||||
|
|
||||||
|
if (pinWidget->position == Position::TOP) {
|
||||||
|
painter.setPen(lineColor);
|
||||||
|
const auto pinNameLabelLineLength = (pinWidget->getPinNumber() % 2 == 0 ?
|
||||||
|
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||||
|
: PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||||
|
);
|
||||||
|
const auto pinDirectionLabelLineLength = (pinWidget->getPinNumber() % 2 == 0 ?
|
||||||
|
PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||||
|
: PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||||
|
);
|
||||||
|
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() - pinNameLabelLineLength,
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y()
|
||||||
|
));
|
||||||
|
|
||||||
|
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||||
|
painter.drawText(
|
||||||
|
QRect(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2)
|
||||||
|
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||||
|
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||||
|
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
),
|
||||||
|
Qt::AlignCenter,
|
||||||
|
pinWidget->pinNameLabelText
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pinState.has_value() && pinState->ioDirection.has_value()) {
|
||||||
|
painter.setFont(pinDirectionFont);
|
||||||
|
|
||||||
|
painter.setPen(lineColor);
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
- pinDirectionLabelLineLength,
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
));
|
||||||
|
|
||||||
|
painter.setPen(pinDirectionFontColor);
|
||||||
|
painter.drawText(
|
||||||
|
QRect(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2)
|
||||||
|
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() - pinNameLabelLineLength - pinDirectionLabelLineLength
|
||||||
|
- (PinWidget::MAXIMUM_LABEL_HEIGHT * 2),
|
||||||
|
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||||
|
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
),
|
||||||
|
Qt::AlignCenter,
|
||||||
|
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (pinWidget->position == Position::BOTTOM) {
|
||||||
|
painter.setPen(lineColor);
|
||||||
|
const auto pinNameLabelLineLength = (pinWidget->getPinNumber() % 2 == 0 ?
|
||||||
|
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||||
|
: PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||||
|
);
|
||||||
|
const auto pinDirectionLabelLineLength = (pinWidget->getPinNumber() % 2 == 0 ?
|
||||||
|
PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||||
|
: PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||||
|
);
|
||||||
|
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT,
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||||
|
));
|
||||||
|
|
||||||
|
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||||
|
painter.drawText(
|
||||||
|
QRect(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2)
|
||||||
|
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength,
|
||||||
|
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||||
|
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
),
|
||||||
|
Qt::AlignCenter,
|
||||||
|
pinWidget->pinNameLabelText
|
||||||
|
);
|
||||||
|
|
||||||
|
if (pinState.has_value() && pinState->ioDirection.has_value()) {
|
||||||
|
painter.setFont(pinDirectionFont);
|
||||||
|
|
||||||
|
painter.setPen(lineColor);
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||||
|
+ PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||||
|
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength
|
||||||
|
));
|
||||||
|
|
||||||
|
painter.setPen(pinDirectionFontColor);
|
||||||
|
painter.drawText(
|
||||||
|
QRect(
|
||||||
|
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2)
|
||||||
|
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||||
|
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||||
|
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength,
|
||||||
|
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||||
|
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||||
|
),
|
||||||
|
Qt::AlignCenter,
|
||||||
|
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <QHBoxLayout>
|
#include <QHBoxLayout>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
|
#include <QPaintEvent>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "../TargetPackageWidget.hpp"
|
#include "../TargetPackageWidget.hpp"
|
||||||
|
|
||||||
@@ -27,10 +29,16 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
QWidget* parent
|
QWidget* parent
|
||||||
);
|
);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
void drawWidget(QPainter& painter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QVBoxLayout* layout = nullptr;
|
QVBoxLayout* layout = nullptr;
|
||||||
QHBoxLayout* topPinLayout = nullptr;
|
QHBoxLayout* topPinLayout = nullptr;
|
||||||
QHBoxLayout* bottomPinLayout = nullptr;
|
QHBoxLayout* bottomPinLayout = nullptr;
|
||||||
BodyWidget* bodyWidget = nullptr;
|
BodyWidget* bodyWidget = nullptr;
|
||||||
|
|
||||||
|
std::vector<PinWidget*> pinWidgets;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,7 @@ PinWidget::PinWidget(
|
|||||||
InsightWorker& insightWorker,
|
InsightWorker& insightWorker,
|
||||||
QWidget* parent
|
QWidget* parent
|
||||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||||
static constexpr auto width = PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING;
|
this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT);
|
||||||
this->setFixedSize(width, PinWidget::MAXIMUM_HEIGHT);
|
|
||||||
|
|
||||||
this->layout = new QVBoxLayout();
|
this->layout = new QVBoxLayout();
|
||||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||||
@@ -25,21 +24,8 @@ PinWidget::PinWidget(
|
|||||||
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
|
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
|
||||||
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
||||||
|
|
||||||
this->pinDirectionLabel = new QLabel(this);
|
this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper();
|
||||||
this->pinDirectionLabel->setObjectName("target-pin-direction");
|
this->pinNameLabelText.truncate(5);
|
||||||
this->pinDirectionLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
|
||||||
|
|
||||||
auto pinName = QString::fromStdString(pinDescriptor.name).toUpper();
|
|
||||||
this->pinNameLabel = new QLabel(this);
|
|
||||||
this->pinNameLabel->setObjectName("target-pin-name");
|
|
||||||
this->pinNameLabel->setToolTip(pinName);
|
|
||||||
if (pinName.size() > 4) {
|
|
||||||
pinName.truncate(4);
|
|
||||||
}
|
|
||||||
this->pinNameLabel->setText(pinName);
|
|
||||||
this->pinNameLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
|
||||||
this->pinNameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
|
||||||
this->pinNameLabel->setFixedWidth(width);
|
|
||||||
|
|
||||||
this->pinNumberLabel = new QLabel(this);
|
this->pinNumberLabel = new QLabel(this);
|
||||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||||
@@ -51,55 +37,11 @@ PinWidget::PinWidget(
|
|||||||
}
|
}
|
||||||
|
|
||||||
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->layout->insertSpacing(1, 3);
|
this->layout->insertSpacing(1, PinWidget::PIN_LABEL_SPACING);
|
||||||
this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->layout->insertSpacing(3, (this->pinDescriptor.number % 2 == 0) ? 20 : 2);
|
this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT);
|
||||||
this->layout->addWidget(this->pinNameLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
|
||||||
this->layout->insertSpacing(5, (this->pinDescriptor.number % 2 != 0) ? 20 : 2);
|
|
||||||
this->layout->addWidget(this->pinDirectionLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
|
||||||
this->pinNameLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2);
|
|
||||||
this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2);
|
|
||||||
|
|
||||||
this->setLayout(this->layout);
|
this->setLayout(this->layout);
|
||||||
|
|
||||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PinWidget::paintEvent(QPaintEvent* event) {
|
|
||||||
auto painter = QPainter(this);
|
|
||||||
this->drawWidget(painter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void PinWidget::drawWidget(QPainter& painter) {
|
|
||||||
painter.setPen(QPen(QColor("#4F4F4F"), 1));
|
|
||||||
|
|
||||||
if (this->pinDescriptor.number % 2 == 0) {
|
|
||||||
/*
|
|
||||||
* Minus 17 for the length of the line
|
|
||||||
* Plus/minus 3 to account for spacing between the pin body and number label
|
|
||||||
*/
|
|
||||||
const auto yOffset = this->position == Position::TOP
|
|
||||||
? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - PinWidget::LABEL_HEIGHT - 17 - 3
|
|
||||||
: PinBodyWidget::HEIGHT + PinWidget::LABEL_HEIGHT + 3;
|
|
||||||
|
|
||||||
painter.drawLine(QLine(
|
|
||||||
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
|
||||||
yOffset,
|
|
||||||
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
|
||||||
yOffset + 17
|
|
||||||
));
|
|
||||||
|
|
||||||
} else if (this->pinState.has_value()) {
|
|
||||||
// Plus/minus 2 because it looks nicer
|
|
||||||
const auto yOffset = this->position == Position::TOP
|
|
||||||
? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - (PinWidget::LABEL_HEIGHT * 2) - 17 - 3 + 2
|
|
||||||
: PinBodyWidget::HEIGHT + (PinWidget::LABEL_HEIGHT * 2) + 3 - 2;
|
|
||||||
|
|
||||||
painter.drawLine(QLine(
|
|
||||||
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
|
||||||
yOffset,
|
|
||||||
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
|
||||||
yOffset + 17
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -24,12 +24,22 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
|
static constexpr int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
|
||||||
static const int WIDTH_SPACING = 6;
|
static constexpr int WIDTH_SPACING = 4;
|
||||||
static const int MAXIMUM_LABEL_COUNT = 3;
|
static constexpr int PIN_LABEL_SPACING = 2;
|
||||||
static const int LABEL_HEIGHT = 20;
|
static constexpr int PIN_LABEL_LONG_LINE_LENGTH = 25;
|
||||||
static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT
|
static constexpr int PIN_LABEL_SHORT_LINE_LENGTH = 5;
|
||||||
+ (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT) + 40;
|
static constexpr int MAXIMUM_LABEL_COUNT = 3;
|
||||||
|
static constexpr int LABEL_HEIGHT = 20;
|
||||||
|
static constexpr int MAXIMUM_PIN_NUMBER_LABEL_WIDTH = 26;
|
||||||
|
static constexpr int MAXIMUM_PIN_DIRECTION_LABEL_WIDTH = 24;
|
||||||
|
static constexpr int MAXIMUM_LABEL_WIDTH = 32;
|
||||||
|
static constexpr int MAXIMUM_LABEL_HEIGHT = 20;
|
||||||
|
static constexpr int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT + PinWidget::PIN_LABEL_SPACING
|
||||||
|
+ PinWidget::LABEL_HEIGHT;
|
||||||
|
|
||||||
|
Position position = Position::TOP;
|
||||||
|
QString pinNameLabelText;
|
||||||
|
|
||||||
PinWidget(
|
PinWidget(
|
||||||
const Targets::TargetPinDescriptor& pinDescriptor,
|
const Targets::TargetPinDescriptor& pinDescriptor,
|
||||||
@@ -41,39 +51,14 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
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()) {
|
|
||||||
this->pinDirectionLabel->setText(
|
|
||||||
pinState.ioDirection.value() == Targets::TargetPinState::IoDirection::INPUT ? "IN" : "OUT"
|
|
||||||
);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
this->pinDirectionLabel->setText("");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this->bodyWidget != nullptr) {
|
if (this->bodyWidget != nullptr) {
|
||||||
this->bodyWidget->setPinState(pinState);
|
this->bodyWidget->setPinState(pinState);
|
||||||
}
|
}
|
||||||
|
|
||||||
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected:
|
|
||||||
void paintEvent(QPaintEvent* event) override;
|
|
||||||
void drawWidget(QPainter& painter);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Position position = Position::TOP;
|
|
||||||
QVBoxLayout* layout = nullptr;
|
QVBoxLayout* layout = nullptr;
|
||||||
QLabel* pinNumberLabel = nullptr;
|
QLabel* pinNumberLabel = nullptr;
|
||||||
QLabel* pinNameLabel = nullptr;
|
|
||||||
QLabel* pinDirectionLabel = nullptr;
|
|
||||||
PinBodyWidget* bodyWidget = nullptr;
|
PinBodyWidget* bodyWidget = nullptr;
|
||||||
|
|
||||||
void setLabelColor(const QString& hexColor) {
|
|
||||||
auto style = QString("QLabel { color: " + hexColor + "; }");
|
|
||||||
if (this->pinNameLabel != nullptr) {
|
|
||||||
this->pinNameLabel->setStyleSheet(style);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#target-pin-number {
|
#target-pin-number {
|
||||||
font-size: 14px;
|
font-size: 13px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#target-pin-name {
|
#target-pin-name {
|
||||||
|
|||||||
Reference in New Issue
Block a user