Removed using namespace directive for class member function definitions in source files
This commit is contained in:
@@ -1,81 +1,85 @@
|
||||
#include "BodyWidget.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
{
|
||||
BodyWidget::BodyWidget(QWidget* parent, std::size_t pinCount): QWidget(parent) {
|
||||
this->setObjectName("target-body");
|
||||
|
||||
BodyWidget::BodyWidget(QWidget* parent, std::size_t pinCount): QWidget(parent) {
|
||||
this->setObjectName("target-body");
|
||||
|
||||
/*
|
||||
* The DIP package widget looks awkward when the body height is fixed. For this reason, the body height and
|
||||
* indicator sizes are proportional to the pin count.
|
||||
*
|
||||
* The proportionality constants used below were chosen because they look the nicest. No other reason.
|
||||
*/
|
||||
this->setFixedHeight(
|
||||
std::min(
|
||||
BodyWidget::MAXIMUM_BODY_HEIGHT,
|
||||
std::max(
|
||||
BodyWidget::MINIMUM_BODY_HEIGHT,
|
||||
static_cast<int>(std::ceil(3.6 * static_cast<double>(pinCount)))
|
||||
/*
|
||||
* The DIP package widget looks awkward when the body height is fixed. For this reason, the body height and
|
||||
* indicator sizes are proportional to the pin count.
|
||||
*
|
||||
* The proportionality constants used below were chosen because they look the nicest. No other reason.
|
||||
*/
|
||||
this->setFixedHeight(
|
||||
std::min(
|
||||
BodyWidget::MAXIMUM_BODY_HEIGHT,
|
||||
std::max(
|
||||
BodyWidget::MINIMUM_BODY_HEIGHT,
|
||||
static_cast<int>(std::ceil(3.6 * static_cast<double>(pinCount)))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
);
|
||||
|
||||
this->firstPinIndicatorDiameter = std::min(
|
||||
BodyWidget::MAXIMUM_FIRST_PIN_INDICATOR_HEIGHT,
|
||||
std::max(BodyWidget::MINIMUM_FIRST_PIN_INDICATOR_HEIGHT, static_cast<int>(std::floor(pinCount / 2)))
|
||||
);
|
||||
this->firstPinIndicatorDiameter = std::min(
|
||||
BodyWidget::MAXIMUM_FIRST_PIN_INDICATOR_HEIGHT,
|
||||
std::max(BodyWidget::MINIMUM_FIRST_PIN_INDICATOR_HEIGHT, static_cast<int>(std::floor(pinCount / 2)))
|
||||
);
|
||||
|
||||
this->orientationIndicatorDiameter = this->firstPinIndicatorDiameter % 2 == 0 ?
|
||||
this->firstPinIndicatorDiameter + 3
|
||||
: this->firstPinIndicatorDiameter + 2;
|
||||
}
|
||||
|
||||
void BodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void BodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||
const auto bodyHeight = this->height();
|
||||
const auto bodyRect = QRectF(
|
||||
0,
|
||||
0,
|
||||
this->width(),
|
||||
bodyHeight
|
||||
);
|
||||
|
||||
// The first pin indicator is just a circle positioned close to the first pin
|
||||
const auto firstPinIndicatorRect = QRectF(
|
||||
6,
|
||||
(bodyHeight - this->firstPinIndicatorDiameter - 6),
|
||||
this->firstPinIndicatorDiameter,
|
||||
this->firstPinIndicatorDiameter
|
||||
);
|
||||
|
||||
/*
|
||||
* The orientation indicator is just a half-circle cut-out, positioned on the side of the DIP package closest to
|
||||
* the first pin.
|
||||
*/
|
||||
const auto orientationIndicatorRect = QRectF(
|
||||
-(this->orientationIndicatorDiameter / 2),
|
||||
(bodyHeight / 2) - (this->orientationIndicatorDiameter / 2),
|
||||
this->orientationIndicatorDiameter,
|
||||
this->orientationIndicatorDiameter
|
||||
);
|
||||
|
||||
static const auto backgroundColor = QColor(0x37, 0x38, 0x35);
|
||||
auto targetBodyColor = this->getBodyColor();
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
||||
this->orientationIndicatorDiameter = this->firstPinIndicatorDiameter % 2 == 0 ?
|
||||
this->firstPinIndicatorDiameter + 3
|
||||
: this->firstPinIndicatorDiameter + 2;
|
||||
}
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(targetBodyColor);
|
||||
painter.drawRect(bodyRect);
|
||||
painter.setBrush(backgroundColor);
|
||||
painter.drawEllipse(firstPinIndicatorRect);
|
||||
painter.drawEllipse(orientationIndicatorRect);
|
||||
void BodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void BodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(
|
||||
QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform,
|
||||
true
|
||||
);
|
||||
const auto bodyHeight = this->height();
|
||||
const auto bodyRect = QRectF(
|
||||
0,
|
||||
0,
|
||||
this->width(),
|
||||
bodyHeight
|
||||
);
|
||||
|
||||
// The first pin indicator is just a circle positioned close to the first pin
|
||||
const auto firstPinIndicatorRect = QRectF(
|
||||
6,
|
||||
(bodyHeight - this->firstPinIndicatorDiameter - 6),
|
||||
this->firstPinIndicatorDiameter,
|
||||
this->firstPinIndicatorDiameter
|
||||
);
|
||||
|
||||
/*
|
||||
* The orientation indicator is just a half-circle cut-out, positioned on the side of the DIP package
|
||||
* closest to the first pin.
|
||||
*/
|
||||
const auto orientationIndicatorRect = QRectF(
|
||||
-(this->orientationIndicatorDiameter / 2),
|
||||
(bodyHeight / 2) - (this->orientationIndicatorDiameter / 2),
|
||||
this->orientationIndicatorDiameter,
|
||||
this->orientationIndicatorDiameter
|
||||
);
|
||||
|
||||
static const auto backgroundColor = QColor(0x37, 0x38, 0x35);
|
||||
auto targetBodyColor = this->getBodyColor();
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
||||
}
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(targetBodyColor);
|
||||
painter.drawRect(bodyRect);
|
||||
painter.setBrush(backgroundColor);
|
||||
painter.drawEllipse(firstPinIndicatorRect);
|
||||
painter.drawEllipse(orientationIndicatorRect);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,242 +8,245 @@
|
||||
|
||||
#include "src/Helpers/Paths.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||
using namespace Bloom::Exceptions;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
{
|
||||
using namespace Bloom::Exceptions;
|
||||
|
||||
using Bloom::Targets::TargetVariant;
|
||||
using Bloom::Targets::TargetVariant;
|
||||
|
||||
DualInlinePackageWidget::DualInlinePackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
Paths::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss"
|
||||
)
|
||||
);
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
|
||||
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
|
||||
this->topPinLayout = new QHBoxLayout();
|
||||
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->bottomPinLayout = new QHBoxLayout();
|
||||
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
TargetPackageWidget::pinWidgets.push_back(pinWidget);
|
||||
|
||||
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
|
||||
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
} else {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
}
|
||||
}
|
||||
|
||||
this->bodyWidget = new BodyWidget(this, targetVariant.pinDescriptorsByNumber.size());
|
||||
|
||||
this->layout->addLayout(this->topPinLayout);
|
||||
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignVCenter);
|
||||
this->layout->addLayout(this->bottomPinLayout);
|
||||
this->setLayout(this->layout);
|
||||
|
||||
const auto bodyWidgetHeight = this->bodyWidget->height();
|
||||
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
|
||||
* static_cast<int>(this->pinWidgets.size() / 2)) - PinWidget::WIDTH_SPACING + 46;
|
||||
|
||||
this->bodyWidget->setGeometry(
|
||||
0,
|
||||
PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING,
|
||||
bodyWidgetWidth,
|
||||
bodyWidgetHeight
|
||||
);
|
||||
|
||||
const auto width = bodyWidgetWidth;
|
||||
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
|
||||
DualInlinePackageWidget::DualInlinePackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
Paths::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/"
|
||||
"DualInlinePackage.qss"
|
||||
)
|
||||
) * 2) + bodyWidgetHeight;
|
||||
);
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
|
||||
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
|
||||
this->bottomPinLayout->setGeometry(
|
||||
QRect(
|
||||
0,
|
||||
(PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2)),
|
||||
width,
|
||||
PinWidget::MAXIMUM_HEIGHT
|
||||
)
|
||||
);
|
||||
this->topPinLayout->setContentsMargins(23, 0, 23, 0);
|
||||
this->bottomPinLayout->setContentsMargins( 23, 0, 23, 0);
|
||||
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
|
||||
this->setFixedSize(width, height);
|
||||
this->topPinLayout = new QHBoxLayout();
|
||||
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->bottomPinLayout = new QHBoxLayout();
|
||||
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
||||
this->setGeometry(
|
||||
(parent->width() / 2) - (width / 2),
|
||||
(parent->height() / 2) - (height / 2),
|
||||
width,
|
||||
height
|
||||
);
|
||||
}
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
TargetPackageWidget::pinWidgets.push_back(pinWidget);
|
||||
|
||||
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(9);
|
||||
|
||||
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
|
||||
);
|
||||
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
|
||||
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
} else {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
}
|
||||
}
|
||||
|
||||
} 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
|
||||
);
|
||||
this->bodyWidget = new BodyWidget(this, targetVariant.pinDescriptorsByNumber.size());
|
||||
|
||||
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
|
||||
));
|
||||
this->layout->addLayout(this->topPinLayout);
|
||||
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignVCenter);
|
||||
this->layout->addLayout(this->bottomPinLayout);
|
||||
this->setLayout(this->layout);
|
||||
|
||||
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
|
||||
);
|
||||
const auto bodyWidgetHeight = this->bodyWidget->height();
|
||||
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
|
||||
* static_cast<int>(this->pinWidgets.size() / 2)) - PinWidget::WIDTH_SPACING + 46;
|
||||
|
||||
if (pinState.has_value() && pinState->ioDirection.has_value()) {
|
||||
painter.setFont(pinDirectionFont);
|
||||
this->bodyWidget->setGeometry(
|
||||
0,
|
||||
PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING,
|
||||
bodyWidgetWidth,
|
||||
bodyWidgetHeight
|
||||
);
|
||||
|
||||
const auto width = bodyWidgetWidth;
|
||||
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) + bodyWidgetHeight;
|
||||
|
||||
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
|
||||
this->bottomPinLayout->setGeometry(
|
||||
QRect(
|
||||
0,
|
||||
(PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2)),
|
||||
width,
|
||||
PinWidget::MAXIMUM_HEIGHT
|
||||
)
|
||||
);
|
||||
this->topPinLayout->setContentsMargins(23, 0, 23, 0);
|
||||
this->bottomPinLayout->setContentsMargins( 23, 0, 23, 0);
|
||||
|
||||
this->setFixedSize(width, height);
|
||||
|
||||
this->setGeometry(
|
||||
(parent->width() / 2) - (width / 2),
|
||||
(parent->height() / 2) - (height / 2),
|
||||
width,
|
||||
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(9);
|
||||
|
||||
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() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||
pinGeoPosition.y() - pinNameLabelLineLength,
|
||||
pinGeoPosition.x() + (PinWidget::MINIMUM_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength
|
||||
pinGeoPosition.y()
|
||||
));
|
||||
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
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_HEIGHT + pinDirectionLabelLineLength,
|
||||
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,34 +2,39 @@
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor)
|
||||
: TargetPinBodyWidget(parent, std::move(pinDescriptor)) {
|
||||
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
|
||||
}
|
||||
|
||||
void PinBodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void PinBodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||
auto pinWidth = PinBodyWidget::WIDTH;
|
||||
auto pinHeight = PinBodyWidget::HEIGHT;
|
||||
this->setFixedSize(pinWidth, pinHeight);
|
||||
|
||||
auto pinColor = this->getBodyColor();
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(pinColor);
|
||||
|
||||
painter.drawRect(
|
||||
0,
|
||||
0,
|
||||
pinWidth,
|
||||
pinHeight
|
||||
);
|
||||
PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor)
|
||||
: TargetPinBodyWidget(parent, std::move(pinDescriptor)) {
|
||||
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
|
||||
}
|
||||
|
||||
void PinBodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void PinBodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(
|
||||
QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform,
|
||||
true
|
||||
);
|
||||
auto pinWidth = PinBodyWidget::WIDTH;
|
||||
auto pinHeight = PinBodyWidget::HEIGHT;
|
||||
this->setFixedSize(pinWidth, pinHeight);
|
||||
|
||||
auto pinColor = this->getBodyColor();
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(pinColor);
|
||||
|
||||
painter.drawRect(
|
||||
0,
|
||||
0,
|
||||
pinWidth,
|
||||
pinHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,47 +1,49 @@
|
||||
#include "PinWidget.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT);
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT);
|
||||
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
|
||||
this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor);
|
||||
this->position = (pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2))
|
||||
? Position::TOP : Position::BOTTOM;
|
||||
this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor);
|
||||
this->position = (pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2))
|
||||
? Position::TOP : Position::BOTTOM;
|
||||
|
||||
const bool isTopWidget = this->position == Position::TOP;
|
||||
const bool isTopWidget = this->position == Position::TOP;
|
||||
|
||||
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
|
||||
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
||||
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
|
||||
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
||||
|
||||
this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper();
|
||||
this->pinNameLabelText.truncate(5);
|
||||
this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper();
|
||||
this->pinNameLabelText.truncate(5);
|
||||
|
||||
this->pinNumberLabel = new QLabel(this);
|
||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||
this->pinNumberLabel->setText(QString::number(pinDescriptor.number));
|
||||
this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
||||
this->pinNumberLabel = new QLabel(this);
|
||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||
this->pinNumberLabel->setText(QString::number(pinDescriptor.number));
|
||||
this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
||||
|
||||
if (isTopWidget) {
|
||||
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
if (isTopWidget) {
|
||||
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
}
|
||||
|
||||
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
this->layout->insertSpacing(1, PinWidget::PIN_LABEL_SPACING);
|
||||
this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT);
|
||||
|
||||
this->setLayout(this->layout);
|
||||
|
||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||
}
|
||||
|
||||
this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
this->layout->insertSpacing(1, PinWidget::PIN_LABEL_SPACING);
|
||||
this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||
this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT);
|
||||
|
||||
this->setLayout(this->layout);
|
||||
|
||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||
}
|
||||
|
||||
@@ -2,47 +2,51 @@
|
||||
|
||||
#include <QPainter>
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
|
||||
|
||||
void BodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void BodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
|
||||
|
||||
auto targetBodyColor = this->getBodyColor();
|
||||
auto backgroundColor = QColor("#373835");
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
{
|
||||
void BodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(targetBodyColor);
|
||||
void BodyWidget::drawWidget(QPainter& painter) {
|
||||
painter.setRenderHints(
|
||||
QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform,
|
||||
true
|
||||
);
|
||||
|
||||
const auto containerSize = this->size();
|
||||
const auto targetBodyWidth = containerSize.width() - 8;
|
||||
const auto targetBodyHeight = containerSize.height() - 8;
|
||||
auto targetBodyColor = this->getBodyColor();
|
||||
auto backgroundColor = QColor("#373835");
|
||||
|
||||
auto targetBodyPoint = QPoint(
|
||||
(containerSize.width() / 2) - (targetBodyWidth / 2),
|
||||
(containerSize.height() / 2) - (targetBodyHeight / 2)
|
||||
);
|
||||
if (!this->isEnabled()) {
|
||||
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
|
||||
}
|
||||
|
||||
painter.drawRect(
|
||||
targetBodyPoint.x(),
|
||||
targetBodyPoint.y(),
|
||||
targetBodyWidth,
|
||||
targetBodyHeight
|
||||
);
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(targetBodyColor);
|
||||
|
||||
painter.setBrush(backgroundColor);
|
||||
painter.drawEllipse(QRectF(
|
||||
targetBodyPoint.x() + 13,
|
||||
targetBodyPoint.y() + 13,
|
||||
18,
|
||||
18
|
||||
));
|
||||
const auto containerSize = this->size();
|
||||
const auto targetBodyWidth = containerSize.width() - 8;
|
||||
const auto targetBodyHeight = containerSize.height() - 8;
|
||||
|
||||
auto targetBodyPoint = QPoint(
|
||||
(containerSize.width() / 2) - (targetBodyWidth / 2),
|
||||
(containerSize.height() / 2) - (targetBodyHeight / 2)
|
||||
);
|
||||
|
||||
painter.drawRect(
|
||||
targetBodyPoint.x(),
|
||||
targetBodyPoint.y(),
|
||||
targetBodyWidth,
|
||||
targetBodyHeight
|
||||
);
|
||||
|
||||
painter.setBrush(backgroundColor);
|
||||
painter.drawEllipse(QRectF(
|
||||
targetBodyPoint.x() + 13,
|
||||
targetBodyPoint.y() + 13,
|
||||
18,
|
||||
18
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,39 +3,44 @@
|
||||
#include <QPainter>
|
||||
#include <QEvent>
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical)
|
||||
: TargetPinBodyWidget(parent, std::move(pinDescriptor)), isVertical(isVertical) {
|
||||
if (isVertical) {
|
||||
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
|
||||
PinBodyWidget::PinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor, bool isVertical)
|
||||
: TargetPinBodyWidget(parent, std::move(pinDescriptor)), isVertical(isVertical) {
|
||||
if (isVertical) {
|
||||
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
|
||||
|
||||
} else {
|
||||
this->setFixedSize(PinBodyWidget::HEIGHT, PinBodyWidget::WIDTH);
|
||||
} else {
|
||||
this->setFixedSize(PinBodyWidget::HEIGHT, PinBodyWidget::WIDTH);
|
||||
}
|
||||
}
|
||||
|
||||
void PinBodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void PinBodyWidget::drawWidget(QPainter& painter) {
|
||||
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;
|
||||
this->setFixedSize(pinWidth, pinHeight);
|
||||
|
||||
auto pinColor = this->getBodyColor();
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(pinColor);
|
||||
|
||||
painter.drawRect(
|
||||
0,
|
||||
0,
|
||||
pinWidth,
|
||||
pinHeight
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void PinBodyWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void PinBodyWidget::drawWidget(QPainter& painter) {
|
||||
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;
|
||||
this->setFixedSize(pinWidth, pinHeight);
|
||||
|
||||
auto pinColor = this->getBodyColor();
|
||||
|
||||
painter.setPen(Qt::PenStyle::NoPen);
|
||||
painter.setBrush(pinColor);
|
||||
|
||||
painter.drawRect(
|
||||
0,
|
||||
0,
|
||||
pinWidth,
|
||||
pinHeight
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,95 +7,97 @@
|
||||
#include "PinWidget.hpp"
|
||||
#include "PinBodyWidget.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
PinWidget::PinWidget(
|
||||
const TargetPinDescriptor& pinDescriptor,
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||
this->layout = new QBoxLayout(QBoxLayout::TopToBottom);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->layout->setSpacing(0);
|
||||
|
||||
auto pinCountPerLayout = (targetVariant.pinDescriptorsByNumber.size() / 4);
|
||||
auto pinCountPerLayout = (targetVariant.pinDescriptorsByNumber.size() / 4);
|
||||
|
||||
if (pinDescriptor.number <= pinCountPerLayout) {
|
||||
this->position = Position::LEFT;
|
||||
if (pinDescriptor.number <= pinCountPerLayout) {
|
||||
this->position = Position::LEFT;
|
||||
|
||||
} else if (pinDescriptor.number > pinCountPerLayout && pinDescriptor.number <= (pinCountPerLayout * 2)) {
|
||||
this->position = Position::BOTTOM;
|
||||
} else if (pinDescriptor.number > pinCountPerLayout && pinDescriptor.number <= (pinCountPerLayout * 2)) {
|
||||
this->position = Position::BOTTOM;
|
||||
|
||||
} else if (pinDescriptor.number > (pinCountPerLayout * 2) && pinDescriptor.number <= (pinCountPerLayout * 3)) {
|
||||
this->position = Position::RIGHT;
|
||||
} else if (pinDescriptor.number > (pinCountPerLayout * 2) && pinDescriptor.number <= (pinCountPerLayout * 3)) {
|
||||
this->position = Position::RIGHT;
|
||||
|
||||
} else if (pinDescriptor.number > (pinCountPerLayout * 3) && pinDescriptor.number <= (pinCountPerLayout * 4)) {
|
||||
this->position = Position::TOP;
|
||||
}
|
||||
} else if (pinDescriptor.number > (pinCountPerLayout * 3) && pinDescriptor.number <= (pinCountPerLayout * 4)) {
|
||||
this->position = Position::TOP;
|
||||
}
|
||||
|
||||
this->bodyWidget = new PinBodyWidget(
|
||||
this,
|
||||
this->pinDescriptor,
|
||||
(this->position == Position::TOP || this->position == Position::BOTTOM)
|
||||
);
|
||||
|
||||
this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper();
|
||||
this->pinNameLabelText.truncate(5);
|
||||
|
||||
this->pinNumberLabel = new QLabel(this);
|
||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||
auto pinNumberText = QString::number(pinDescriptor.number);
|
||||
pinNumberText.truncate(5);
|
||||
this->pinNumberLabel->setText(QString::number(pinDescriptor.number));
|
||||
this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
||||
|
||||
if (this->position == Position::LEFT) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignVCenter | Qt::AlignmentFlag::AlignRight));
|
||||
this->layout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_HORIZONTAL_WIDTH, PinWidget::MAXIMUM_HORIZONTAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::BOTTOM) {
|
||||
this->layout->setAlignment(Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop);
|
||||
this->layout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_VERTICAL_WIDTH, PinWidget::MAXIMUM_VERTICAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::RIGHT) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignVCenter | Qt::AlignmentFlag::AlignLeft));
|
||||
this->layout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_HORIZONTAL_WIDTH, PinWidget::MAXIMUM_HORIZONTAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::TOP) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom));
|
||||
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_VERTICAL_WIDTH, PinWidget::MAXIMUM_VERTICAL_HEIGHT);
|
||||
}
|
||||
|
||||
this->layout->addWidget(this->bodyWidget);
|
||||
this->layout->addSpacing(3);
|
||||
this->layout->addWidget(this->pinNumberLabel);
|
||||
|
||||
if (this->position == Position::LEFT || this->position == Position::RIGHT) {
|
||||
this->pinNumberLabel->setFixedSize(
|
||||
PinWidget::MAXIMUM_PIN_NUMBER_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2
|
||||
this->bodyWidget = new PinBodyWidget(
|
||||
this,
|
||||
this->pinDescriptor,
|
||||
(this->position == Position::TOP || this->position == Position::BOTTOM)
|
||||
);
|
||||
|
||||
} else if (this->position == Position::TOP || this->position == Position::BOTTOM) {
|
||||
this->pinNumberLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
|
||||
this->pinNameLabelText = QString::fromStdString(pinDescriptor.name).toUpper();
|
||||
this->pinNameLabelText.truncate(5);
|
||||
|
||||
this->pinNumberLabel = new QLabel(this);
|
||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||
auto pinNumberText = QString::number(pinDescriptor.number);
|
||||
pinNumberText.truncate(5);
|
||||
this->pinNumberLabel->setText(QString::number(pinDescriptor.number));
|
||||
this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
||||
|
||||
if (this->position == Position::LEFT) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignVCenter | Qt::AlignmentFlag::AlignRight));
|
||||
this->layout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_HORIZONTAL_WIDTH, PinWidget::MAXIMUM_HORIZONTAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::BOTTOM) {
|
||||
this->layout->setAlignment(Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop);
|
||||
this->layout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_VERTICAL_WIDTH, PinWidget::MAXIMUM_VERTICAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::RIGHT) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignVCenter | Qt::AlignmentFlag::AlignLeft));
|
||||
this->layout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_HORIZONTAL_WIDTH, PinWidget::MAXIMUM_HORIZONTAL_HEIGHT);
|
||||
|
||||
} else if (this->position == Position::TOP) {
|
||||
this->layout->setAlignment((Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom));
|
||||
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
this->setFixedSize(PinWidget::MAXIMUM_VERTICAL_WIDTH, PinWidget::MAXIMUM_VERTICAL_HEIGHT);
|
||||
}
|
||||
|
||||
this->layout->addWidget(this->bodyWidget);
|
||||
this->layout->addSpacing(3);
|
||||
this->layout->addWidget(this->pinNumberLabel);
|
||||
|
||||
if (this->position == Position::LEFT || this->position == Position::RIGHT) {
|
||||
this->pinNumberLabel->setFixedSize(
|
||||
PinWidget::MAXIMUM_PIN_NUMBER_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2
|
||||
);
|
||||
|
||||
} else if (this->position == Position::TOP || this->position == Position::BOTTOM) {
|
||||
this->pinNumberLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
|
||||
}
|
||||
|
||||
this->layout->addStretch(1);
|
||||
this->setLayout(this->layout);
|
||||
|
||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||
}
|
||||
|
||||
this->layout->addStretch(1);
|
||||
this->setLayout(this->layout);
|
||||
void PinWidget::updatePinState(const Targets::TargetPinState& pinState) {
|
||||
TargetPinWidget::updatePinState(pinState);
|
||||
|
||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||
}
|
||||
|
||||
void PinWidget::updatePinState(const Targets::TargetPinState& pinState) {
|
||||
TargetPinWidget::updatePinState(pinState);
|
||||
|
||||
if (this->bodyWidget != nullptr) {
|
||||
this->bodyWidget->setPinState(pinState);
|
||||
if (this->bodyWidget != nullptr) {
|
||||
this->bodyWidget->setPinState(pinState);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,403 +11,407 @@
|
||||
#include "PinWidget.hpp"
|
||||
#include "BodyWidget.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets::Qfp;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets::Qfp
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
QuadFlatPackageWidget::QuadFlatPackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0);
|
||||
QuadFlatPackageWidget::QuadFlatPackageWidget(
|
||||
const TargetVariant& targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): TargetPackageWidget(targetVariant, insightWorker, parent) {
|
||||
assert((targetVariant.pinDescriptorsByNumber.size() % 4) == 0);
|
||||
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
Paths::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss"
|
||||
)
|
||||
);
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
auto stylesheetFile = QFile(QString::fromStdString(
|
||||
Paths::compiledResourcesPath()
|
||||
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/Stylesheets/QuadFlatPackage.qss"
|
||||
)
|
||||
);
|
||||
stylesheetFile.open(QFile::ReadOnly);
|
||||
this->setStyleSheet(stylesheetFile.readAll());
|
||||
|
||||
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setSpacing(0);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
|
||||
this->layout = new QVBoxLayout();
|
||||
this->layout->setSpacing(0);
|
||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||
|
||||
this->horizontalLayout = new QHBoxLayout();
|
||||
this->horizontalLayout->setSpacing(0);
|
||||
this->horizontalLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->horizontalLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->horizontalLayout = new QHBoxLayout();
|
||||
this->horizontalLayout->setSpacing(0);
|
||||
this->horizontalLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->horizontalLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
||||
this->topPinLayout = new QHBoxLayout();
|
||||
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->topPinLayout = new QHBoxLayout();
|
||||
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
|
||||
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
||||
this->rightPinLayout = new QVBoxLayout();
|
||||
this->rightPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->rightPinLayout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
this->rightPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
this->rightPinLayout = new QVBoxLayout();
|
||||
this->rightPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->rightPinLayout->setDirection(QBoxLayout::Direction::BottomToTop);
|
||||
this->rightPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
|
||||
this->bottomPinLayout = new QHBoxLayout();
|
||||
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->bottomPinLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
this->bottomPinLayout = new QHBoxLayout();
|
||||
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->bottomPinLayout->setDirection(QBoxLayout::Direction::LeftToRight);
|
||||
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
|
||||
|
||||
this->leftPinLayout = new QVBoxLayout();
|
||||
this->leftPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->leftPinLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
this->leftPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
this->leftPinLayout = new QVBoxLayout();
|
||||
this->leftPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
|
||||
this->leftPinLayout->setDirection(QBoxLayout::Direction::TopToBottom);
|
||||
this->leftPinLayout->setAlignment(Qt::AlignmentFlag::AlignVCenter);
|
||||
|
||||
const auto pinCountPerLayout = static_cast<int>(targetVariant.pinDescriptorsByNumber.size() / 4);
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
TargetPackageWidget::pinWidgets.push_back(pinWidget);
|
||||
const auto pinCountPerLayout = static_cast<int>(targetVariant.pinDescriptorsByNumber.size() / 4);
|
||||
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
|
||||
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
|
||||
this->pinWidgets.push_back(pinWidget);
|
||||
TargetPackageWidget::pinWidgets.push_back(pinWidget);
|
||||
|
||||
if (pinWidget->position == Position::LEFT) {
|
||||
this->leftPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignRight);
|
||||
if (pinWidget->position == Position::LEFT) {
|
||||
this->leftPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignRight);
|
||||
|
||||
} else if (pinWidget->position == Position::BOTTOM) {
|
||||
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignTop);
|
||||
} else if (pinWidget->position == Position::BOTTOM) {
|
||||
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignTop);
|
||||
|
||||
} else if (pinWidget->position == Position::RIGHT) {
|
||||
this->rightPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignLeft);
|
||||
} else if (pinWidget->position == Position::RIGHT) {
|
||||
this->rightPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignLeft);
|
||||
|
||||
} else if (pinWidget->position == Position::TOP) {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignBottom);
|
||||
} else if (pinWidget->position == Position::TOP) {
|
||||
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignBottom);
|
||||
}
|
||||
}
|
||||
|
||||
this->bodyWidget = new BodyWidget(this);
|
||||
this->layout->addLayout(this->topPinLayout);
|
||||
this->horizontalLayout->addLayout(this->leftPinLayout);
|
||||
this->horizontalLayout->addWidget(this->bodyWidget);
|
||||
this->horizontalLayout->addLayout(this->rightPinLayout);
|
||||
this->layout->addLayout(this->horizontalLayout);
|
||||
this->layout->addLayout(this->bottomPinLayout);
|
||||
this->setLayout(this->layout);
|
||||
|
||||
// Layout sizing, positioning and padding
|
||||
const auto verticalPinWidgetHeight = PinWidget::MAXIMUM_VERTICAL_HEIGHT;
|
||||
const auto verticalPinWidgetWidth = PinWidget::MAXIMUM_VERTICAL_WIDTH;
|
||||
const auto horizontalPinWidgetHeight = PinWidget::MAXIMUM_HORIZONTAL_HEIGHT;
|
||||
const auto horizontalPinWidgetWidth = PinWidget::MAXIMUM_HORIZONTAL_WIDTH;
|
||||
|
||||
/*
|
||||
* Horizontal layouts are the right and left pin layouts - the ones that hold horizontal pin widgets.
|
||||
* The bottom and top layouts are vertical layouts, as they hold the vertical pin widgets.
|
||||
*/
|
||||
const auto horizontalLayoutHeight = ((horizontalPinWidgetHeight + PinWidget::WIDTH_SPACING) * pinCountPerLayout
|
||||
+ PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING);
|
||||
|
||||
const auto verticalLayoutWidth = ((verticalPinWidgetWidth + PinWidget::WIDTH_SPACING) * pinCountPerLayout
|
||||
+ PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING);
|
||||
|
||||
const auto height = horizontalLayoutHeight + (verticalPinWidgetHeight * 2) + (
|
||||
(
|
||||
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
+ PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||
+ (PinWidget::MAXIMUM_LABEL_HEIGHT * 2)
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 3)
|
||||
) * 2
|
||||
);
|
||||
const auto width = verticalLayoutWidth + (horizontalPinWidgetWidth * 2) + (
|
||||
(
|
||||
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
+ PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
+ PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 2)
|
||||
) * 2
|
||||
);
|
||||
|
||||
this->topPinLayout->insertSpacing(0, horizontalPinWidgetWidth);
|
||||
this->topPinLayout->addSpacing(horizontalPinWidgetWidth);
|
||||
|
||||
this->bottomPinLayout->insertSpacing(0, horizontalPinWidgetWidth);
|
||||
this->bottomPinLayout->addSpacing(horizontalPinWidgetWidth);
|
||||
|
||||
this->leftPinLayout->setGeometry(QRect(
|
||||
0,
|
||||
verticalPinWidgetHeight,
|
||||
horizontalPinWidgetWidth,
|
||||
horizontalLayoutHeight
|
||||
));
|
||||
|
||||
this->bodyWidget->setFixedSize(verticalLayoutWidth, horizontalLayoutHeight);
|
||||
|
||||
this->rightPinLayout->setGeometry(QRect(
|
||||
horizontalLayoutHeight + horizontalPinWidgetWidth,
|
||||
verticalPinWidgetHeight,
|
||||
horizontalPinWidgetWidth,
|
||||
horizontalLayoutHeight
|
||||
));
|
||||
|
||||
const auto pinWidgetLayoutMargin = PinWidget::PIN_WIDGET_LAYOUT_PADDING / 2;
|
||||
|
||||
this->topPinLayout->setContentsMargins(
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0
|
||||
);
|
||||
|
||||
this->bottomPinLayout->setContentsMargins(
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0
|
||||
);
|
||||
|
||||
this->leftPinLayout->setContentsMargins(
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin
|
||||
);
|
||||
|
||||
this->rightPinLayout->setContentsMargins(
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin
|
||||
);
|
||||
|
||||
this->setFixedSize(width, height);
|
||||
|
||||
// Set the fixed size and center the widget
|
||||
this->setGeometry(
|
||||
(parent->width() / 2) - (width / 2),
|
||||
(parent->height() / 2) - (height / 2),
|
||||
width,
|
||||
height
|
||||
);
|
||||
}
|
||||
|
||||
this->bodyWidget = new BodyWidget(this);
|
||||
this->layout->addLayout(this->topPinLayout);
|
||||
this->horizontalLayout->addLayout(this->leftPinLayout);
|
||||
this->horizontalLayout->addWidget(this->bodyWidget);
|
||||
this->horizontalLayout->addLayout(this->rightPinLayout);
|
||||
this->layout->addLayout(this->horizontalLayout);
|
||||
this->layout->addLayout(this->bottomPinLayout);
|
||||
this->setLayout(this->layout);
|
||||
void QuadFlatPackageWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
// Layout sizing, positioning and padding
|
||||
const auto verticalPinWidgetHeight = PinWidget::MAXIMUM_VERTICAL_HEIGHT;
|
||||
const auto verticalPinWidgetWidth = PinWidget::MAXIMUM_VERTICAL_WIDTH;
|
||||
const auto horizontalPinWidgetHeight = PinWidget::MAXIMUM_HORIZONTAL_HEIGHT;
|
||||
const auto horizontalPinWidgetWidth = PinWidget::MAXIMUM_HORIZONTAL_WIDTH;
|
||||
void QuadFlatPackageWidget::drawWidget(QPainter& painter) {
|
||||
static auto pinNameFont = QFont("'Ubuntu', sans-serif");
|
||||
static auto pinDirectionFont = pinNameFont;
|
||||
pinNameFont.setPixelSize(11);
|
||||
pinDirectionFont.setPixelSize(9);
|
||||
|
||||
/*
|
||||
* Horizontal layouts are the right and left pin layouts - the ones that hold horizontal pin widgets.
|
||||
* The bottom and top layouts are vertical layouts, as they hold the vertical pin widgets.
|
||||
*/
|
||||
const auto horizontalLayoutHeight = ((horizontalPinWidgetHeight + PinWidget::WIDTH_SPACING) * pinCountPerLayout
|
||||
+ PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING);
|
||||
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);
|
||||
|
||||
const auto verticalLayoutWidth = ((verticalPinWidgetWidth + PinWidget::WIDTH_SPACING) * pinCountPerLayout
|
||||
+ PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING);
|
||||
static const auto inDirectionText = QString("IN");
|
||||
static const auto outDirectionText = QString("OUT");
|
||||
|
||||
const auto height = horizontalLayoutHeight + (verticalPinWidgetHeight * 2) + (
|
||||
(
|
||||
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
+ PinWidget::PIN_LABEL_SHORT_LINE_LENGTH
|
||||
+ (PinWidget::MAXIMUM_LABEL_HEIGHT * 2)
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 3)
|
||||
) * 2
|
||||
);
|
||||
const auto width = verticalLayoutWidth + (horizontalPinWidgetWidth * 2) + (
|
||||
(
|
||||
PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
+ PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
+ PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 2)
|
||||
) * 2
|
||||
);
|
||||
for (const auto* pinWidget : this->pinWidgets) {
|
||||
const auto pinGeoPosition = pinWidget->pos();
|
||||
const auto& pinState = pinWidget->getPinState();
|
||||
const auto pinStateChanged = pinWidget->hasPinStateChanged();
|
||||
|
||||
this->topPinLayout->insertSpacing(0, horizontalPinWidgetWidth);
|
||||
this->topPinLayout->addSpacing(horizontalPinWidgetWidth);
|
||||
painter.setFont(pinNameFont);
|
||||
|
||||
this->bottomPinLayout->insertSpacing(0, horizontalPinWidgetWidth);
|
||||
this->bottomPinLayout->addSpacing(horizontalPinWidgetWidth);
|
||||
if (pinWidget->position == Position::LEFT) {
|
||||
painter.setPen(lineColor);
|
||||
painter.drawLine(QLine(
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2),
|
||||
pinGeoPosition.x(),
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2)
|
||||
));
|
||||
|
||||
this->leftPinLayout->setGeometry(QRect(
|
||||
0,
|
||||
verticalPinWidgetHeight,
|
||||
horizontalPinWidgetWidth,
|
||||
horizontalLayoutHeight
|
||||
));
|
||||
|
||||
this->bodyWidget->setFixedSize(verticalLayoutWidth, horizontalLayoutHeight);
|
||||
|
||||
this->rightPinLayout->setGeometry(QRect(
|
||||
horizontalLayoutHeight + horizontalPinWidgetWidth,
|
||||
verticalPinWidgetHeight,
|
||||
horizontalPinWidgetWidth,
|
||||
horizontalLayoutHeight
|
||||
));
|
||||
|
||||
const auto pinWidgetLayoutMargin = PinWidget::PIN_WIDGET_LAYOUT_PADDING / 2;
|
||||
|
||||
this->topPinLayout->setContentsMargins(
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0
|
||||
);
|
||||
|
||||
this->bottomPinLayout->setContentsMargins(
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0
|
||||
);
|
||||
|
||||
this->leftPinLayout->setContentsMargins(
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin
|
||||
);
|
||||
|
||||
this->rightPinLayout->setContentsMargins(
|
||||
0,
|
||||
pinWidgetLayoutMargin,
|
||||
0,
|
||||
pinWidgetLayoutMargin
|
||||
);
|
||||
|
||||
this->setFixedSize(width, height);
|
||||
|
||||
// Set the fixed size and center the widget
|
||||
this->setGeometry(
|
||||
(parent->width() / 2) - (width / 2),
|
||||
(parent->height() / 2) - (height / 2),
|
||||
width,
|
||||
height
|
||||
);
|
||||
}
|
||||
|
||||
void QuadFlatPackageWidget::paintEvent(QPaintEvent* event) {
|
||||
auto painter = QPainter(this);
|
||||
this->drawWidget(painter);
|
||||
}
|
||||
|
||||
void QuadFlatPackageWidget::drawWidget(QPainter& painter) {
|
||||
static auto pinNameFont = QFont("'Ubuntu', sans-serif");
|
||||
static auto pinDirectionFont = pinNameFont;
|
||||
pinNameFont.setPixelSize(11);
|
||||
pinDirectionFont.setPixelSize(9);
|
||||
|
||||
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::LEFT) {
|
||||
painter.setPen(lineColor);
|
||||
painter.drawLine(QLine(
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2),
|
||||
pinGeoPosition.x(),
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_HORIZONTAL_HEIGHT / 2)
|
||||
));
|
||||
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH - PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
- (PinWidget::PIN_LABEL_SPACING * 2),
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
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(pinDirectionFontColor);
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH - PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
- (PinWidget::PIN_LABEL_SPACING * 3) - PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
- PinWidget::MAXIMUM_LABEL_WIDTH - (PinWidget::PIN_LABEL_SPACING * 2),
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
pinWidget->pinNameLabelText
|
||||
);
|
||||
}
|
||||
|
||||
} else if (pinWidget->position == Position::RIGHT) {
|
||||
painter.setPen(lineColor);
|
||||
painter.drawLine(QLine(
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH + PinWidget::PIN_LABEL_LONG_LINE_LENGTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
));
|
||||
if (pinState.has_value() && pinState->ioDirection.has_value()) {
|
||||
painter.setFont(pinDirectionFont);
|
||||
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() - PinWidget::PIN_LABEL_LONG_LINE_LENGTH
|
||||
- PinWidget::MAXIMUM_LABEL_WIDTH - (PinWidget::PIN_LABEL_SPACING * 3)
|
||||
- PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
);
|
||||
}
|
||||
|
||||
} else if (pinWidget->position == Position::RIGHT) {
|
||||
painter.setPen(lineColor);
|
||||
painter.drawLine(QLine(
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH
|
||||
+ PinWidget::PIN_LABEL_LONG_LINE_LENGTH + 8,
|
||||
+ PinWidget::PIN_LABEL_LONG_LINE_LENGTH,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
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(pinDirectionFontColor);
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH
|
||||
+ PinWidget::PIN_LABEL_LONG_LINE_LENGTH + PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 3),
|
||||
+ PinWidget::PIN_LABEL_LONG_LINE_LENGTH + 8,
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
);
|
||||
}
|
||||
|
||||
} else 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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() - pinNameLabelLineLength,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y()
|
||||
));
|
||||
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
- pinDirectionLabelLineLength,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
));
|
||||
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_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
|
||||
pinWidget->pinNameLabelText
|
||||
);
|
||||
}
|
||||
|
||||
} 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
|
||||
);
|
||||
if (pinState.has_value() && pinState->ioDirection.has_value()) {
|
||||
painter.setFont(pinDirectionFont);
|
||||
|
||||
painter.drawLine(QLine(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
));
|
||||
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||
pinGeoPosition.y() + + PinWidget::MAXIMUM_VERTICAL_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(pinDirectionFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + PinWidget::MAXIMUM_HORIZONTAL_WIDTH
|
||||
+ PinWidget::PIN_LABEL_LONG_LINE_LENGTH + PinWidget::MAXIMUM_LABEL_WIDTH
|
||||
+ (PinWidget::PIN_LABEL_SPACING * 3),
|
||||
pinGeoPosition.y() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_HEIGHT / 2),
|
||||
PinWidget::MAXIMUM_PIN_DIRECTION_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
);
|
||||
}
|
||||
|
||||
} else 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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||
pinGeoPosition.y() - pinNameLabelLineLength,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength
|
||||
pinGeoPosition.y()
|
||||
));
|
||||
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
- pinDirectionLabelLineLength,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() - pinNameLabelLineLength - PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
));
|
||||
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
));
|
||||
|
||||
painter.setPen(pinStateChanged ? pinChangedFontColor : pinNameFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||
pinGeoPosition.y() + + PinWidget::MAXIMUM_VERTICAL_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::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength,
|
||||
PinWidget::MAXIMUM_LABEL_WIDTH,
|
||||
PinWidget::MAXIMUM_LABEL_HEIGHT
|
||||
),
|
||||
Qt::AlignCenter,
|
||||
pinState->ioDirection == TargetPinState::IoDirection::INPUT ? inDirectionText : outDirectionText
|
||||
);
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT,
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_HEIGHT + pinNameLabelLineLength
|
||||
+ PinWidget::MAXIMUM_LABEL_HEIGHT + pinDirectionLabelLineLength
|
||||
));
|
||||
|
||||
painter.setPen(pinDirectionFontColor);
|
||||
painter.drawText(
|
||||
QRect(
|
||||
pinGeoPosition.x() + (PinWidget::MAXIMUM_VERTICAL_WIDTH / 2)
|
||||
- (PinWidget::MAXIMUM_LABEL_WIDTH / 2),
|
||||
pinGeoPosition.y() + PinWidget::MAXIMUM_VERTICAL_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,90 +4,90 @@
|
||||
|
||||
#include "src/Insight/InsightWorker/Tasks/RefreshTargetPinStates.hpp"
|
||||
|
||||
using namespace Bloom;
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets
|
||||
{
|
||||
using Bloom::Targets::TargetState;
|
||||
|
||||
using Bloom::Targets::TargetState;
|
||||
TargetPackageWidget::TargetPackageWidget(
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): QWidget(parent), targetVariant(std::move(targetVariant)), insightWorker(insightWorker) {
|
||||
QObject::connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetStateUpdated,
|
||||
this,
|
||||
&TargetPackageWidget::onTargetStateChanged
|
||||
);
|
||||
|
||||
TargetPackageWidget::TargetPackageWidget(
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): QWidget(parent), targetVariant(std::move(targetVariant)), insightWorker(insightWorker) {
|
||||
QObject::connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetStateUpdated,
|
||||
this,
|
||||
&TargetPackageWidget::onTargetStateChanged
|
||||
);
|
||||
QObject::connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetRegistersWritten,
|
||||
this,
|
||||
&TargetPackageWidget::onRegistersWritten
|
||||
);
|
||||
|
||||
QObject::connect(
|
||||
&(this->insightWorker),
|
||||
&InsightWorker::targetRegistersWritten,
|
||||
this,
|
||||
&TargetPackageWidget::onRegistersWritten
|
||||
);
|
||||
this->setDisabled(true);
|
||||
}
|
||||
|
||||
this->setDisabled(true);
|
||||
}
|
||||
|
||||
void TargetPackageWidget::refreshPinStates(std::optional<std::function<void(void)>> callback) {
|
||||
auto* refreshTask = new RefreshTargetPinStates(this->targetVariant.id);
|
||||
QObject::connect(
|
||||
refreshTask,
|
||||
&RefreshTargetPinStates::targetPinStatesRetrieved,
|
||||
this,
|
||||
&TargetPackageWidget::updatePinStates
|
||||
);
|
||||
|
||||
if (callback.has_value()) {
|
||||
void TargetPackageWidget::refreshPinStates(std::optional<std::function<void(void)>> callback) {
|
||||
auto* refreshTask = new RefreshTargetPinStates(this->targetVariant.id);
|
||||
QObject::connect(
|
||||
refreshTask,
|
||||
&InsightWorkerTask::completed,
|
||||
&RefreshTargetPinStates::targetPinStatesRetrieved,
|
||||
this,
|
||||
callback.value()
|
||||
&TargetPackageWidget::updatePinStates
|
||||
);
|
||||
|
||||
if (callback.has_value()) {
|
||||
QObject::connect(
|
||||
refreshTask,
|
||||
&InsightWorkerTask::completed,
|
||||
this,
|
||||
callback.value()
|
||||
);
|
||||
}
|
||||
|
||||
this->insightWorker.queueTask(refreshTask);
|
||||
}
|
||||
|
||||
this->insightWorker.queueTask(refreshTask);
|
||||
}
|
||||
void TargetPackageWidget::updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber) {
|
||||
for (auto& pinWidget : this->pinWidgets) {
|
||||
auto pinNumber = pinWidget->getPinNumber();
|
||||
if (pinStatesByNumber.contains(pinNumber)) {
|
||||
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber));
|
||||
}
|
||||
}
|
||||
|
||||
void TargetPackageWidget::updatePinStates(const Targets::TargetPinStateMappingType& pinStatesByNumber) {
|
||||
for (auto& pinWidget : this->pinWidgets) {
|
||||
auto pinNumber = pinWidget->getPinNumber();
|
||||
if (pinStatesByNumber.contains(pinNumber)) {
|
||||
pinWidget->updatePinState(pinStatesByNumber.at(pinNumber));
|
||||
this->update();
|
||||
}
|
||||
|
||||
void TargetPackageWidget::onTargetStateChanged(TargetState newState) {
|
||||
this->targetState = newState;
|
||||
|
||||
if (newState == TargetState::RUNNING) {
|
||||
this->setDisabled(true);
|
||||
|
||||
} else if (newState == TargetState::STOPPED) {
|
||||
this->refreshPinStates([this] {
|
||||
if (this->targetState == TargetState::STOPPED) {
|
||||
this->setDisabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
this->update();
|
||||
}
|
||||
|
||||
void TargetPackageWidget::onTargetStateChanged(TargetState newState) {
|
||||
this->targetState = newState;
|
||||
|
||||
if (newState == TargetState::RUNNING) {
|
||||
this->setDisabled(true);
|
||||
|
||||
} else if (newState == TargetState::STOPPED) {
|
||||
this->refreshPinStates([this] {
|
||||
if (this->targetState == TargetState::STOPPED) {
|
||||
this->setDisabled(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void TargetPackageWidget::onRegistersWritten(Targets::TargetRegisters targetRegisters) {
|
||||
if (this->targetState != TargetState::STOPPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If a PORT register was just updated, refresh pin states.
|
||||
for (const auto& targetRegister : targetRegisters) {
|
||||
if (targetRegister.descriptor.type == Targets::TargetRegisterType::PORT_REGISTER) {
|
||||
this->refreshPinStates();
|
||||
void TargetPackageWidget::onRegistersWritten(Targets::TargetRegisters targetRegisters) {
|
||||
if (this->targetState != TargetState::STOPPED) {
|
||||
return;
|
||||
}
|
||||
|
||||
// If a PORT register was just updated, refresh pin states.
|
||||
for (const auto& targetRegister : targetRegisters) {
|
||||
if (targetRegister.descriptor.type == Targets::TargetRegisterType::PORT_REGISTER) {
|
||||
this->refreshPinStates();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,29 +2,29 @@
|
||||
|
||||
#include <QLayout>
|
||||
|
||||
using namespace Bloom;
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets
|
||||
{
|
||||
TargetPackageWidgetContainer::TargetPackageWidgetContainer(QWidget* parent): QWidget(parent) {}
|
||||
|
||||
TargetPackageWidgetContainer::TargetPackageWidgetContainer(QWidget* parent): QWidget(parent) {}
|
||||
void TargetPackageWidgetContainer::setPackageWidget(TargetPackageWidget* packageWidget) {
|
||||
this->packageWidget = packageWidget;
|
||||
|
||||
void TargetPackageWidgetContainer::setPackageWidget(TargetPackageWidget* packageWidget) {
|
||||
this->packageWidget = packageWidget;
|
||||
|
||||
if (packageWidget != nullptr) {
|
||||
this->layout()->addWidget(packageWidget);
|
||||
}
|
||||
}
|
||||
|
||||
void TargetPackageWidgetContainer::resizeEvent(QResizeEvent* event) {
|
||||
if (this->packageWidget == nullptr) {
|
||||
return;
|
||||
if (packageWidget != nullptr) {
|
||||
this->layout()->addWidget(packageWidget);
|
||||
}
|
||||
}
|
||||
|
||||
const auto packageSize = this->packageWidget->size();
|
||||
this->packageWidget->setGeometry(
|
||||
(this->width() / 2) - (packageSize.width() / 2),
|
||||
(this->height() / 2) - (packageSize.height() / 2),
|
||||
packageSize.width(),
|
||||
packageSize.height()
|
||||
);
|
||||
void TargetPackageWidgetContainer::resizeEvent(QResizeEvent* event) {
|
||||
if (this->packageWidget == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto packageSize = this->packageWidget->size();
|
||||
this->packageWidget->setGeometry(
|
||||
(this->width() / 2) - (packageSize.width() / 2),
|
||||
(this->height() / 2) - (packageSize.height() / 2),
|
||||
packageSize.width(),
|
||||
packageSize.height()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,72 +2,74 @@
|
||||
|
||||
#include "TargetPinBodyWidget.hpp"
|
||||
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
using namespace Bloom::Targets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets
|
||||
{
|
||||
using namespace Bloom::Targets;
|
||||
|
||||
TargetPinBodyWidget::TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor)
|
||||
: QWidget(parent), pinDescriptor(std::move(pinDescriptor)) {
|
||||
this->setObjectName("target-pin-body");
|
||||
this->setToolTip(QString::fromStdString(this->pinDescriptor.name).toUpper());
|
||||
}
|
||||
TargetPinBodyWidget::TargetPinBodyWidget(QWidget* parent, Targets::TargetPinDescriptor pinDescriptor)
|
||||
: QWidget(parent), pinDescriptor(std::move(pinDescriptor)) {
|
||||
this->setObjectName("target-pin-body");
|
||||
this->setToolTip(QString::fromStdString(this->pinDescriptor.name).toUpper());
|
||||
}
|
||||
|
||||
QColor TargetPinBodyWidget::getBodyColor() {
|
||||
auto pinColor = this->defaultBodyColor;
|
||||
QColor TargetPinBodyWidget::getBodyColor() {
|
||||
auto pinColor = this->defaultBodyColor;
|
||||
|
||||
if (this->pinDescriptor.type == TargetPinType::VCC) {
|
||||
pinColor = this->vccBodyColor;
|
||||
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::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()
|
||||
) {
|
||||
const auto ioDirection = this->pinState->ioDirection.value();
|
||||
const auto ioState = this->pinState->ioState.value();
|
||||
|
||||
if (this->pinState->ioState.value() == TargetPinState::IoState::HIGH) {
|
||||
pinColor = ioDirection == TargetPinState::IoDirection::OUTPUT ?
|
||||
this->outputHighBodyColor : this->inputHighBodyColor;
|
||||
}
|
||||
|
||||
if ((
|
||||
ioDirection == TargetPinState::IoDirection::OUTPUT
|
||||
|| (ioDirection == TargetPinState::IoDirection::INPUT && ioState == TargetPinState::IoState::LOW)
|
||||
) && !this->hoverActive
|
||||
} else if (this->pinDescriptor.type == TargetPinType::GPIO) {
|
||||
if (this->pinState.has_value()
|
||||
&& this->pinState->ioState.has_value()
|
||||
&& this->pinState->ioDirection.has_value()
|
||||
) {
|
||||
pinColor.setAlpha(220);
|
||||
const auto ioDirection = this->pinState->ioDirection.value();
|
||||
const auto ioState = this->pinState->ioState.value();
|
||||
|
||||
if (this->pinState->ioState.value() == TargetPinState::IoState::HIGH) {
|
||||
pinColor = ioDirection == TargetPinState::IoDirection::OUTPUT ?
|
||||
this->outputHighBodyColor : this->inputHighBodyColor;
|
||||
}
|
||||
|
||||
if ((
|
||||
ioDirection == TargetPinState::IoDirection::OUTPUT
|
||||
|| (ioDirection == TargetPinState::IoDirection::INPUT && ioState == TargetPinState::IoState::LOW)
|
||||
) && !this->hoverActive
|
||||
) {
|
||||
pinColor.setAlpha(220);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
pinColor.setAlpha(this->disableAlphaLevel);
|
||||
}
|
||||
|
||||
return pinColor;
|
||||
}
|
||||
|
||||
if (!this->isEnabled()) {
|
||||
pinColor.setAlpha(this->disableAlphaLevel);
|
||||
}
|
||||
|
||||
return pinColor;
|
||||
}
|
||||
|
||||
bool TargetPinBodyWidget::event(QEvent* event) {
|
||||
if (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;
|
||||
bool TargetPinBodyWidget::event(QEvent* event) {
|
||||
if (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);
|
||||
return QWidget::event(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,49 +2,51 @@
|
||||
|
||||
#include "src/Insight/InsightWorker/Tasks/SetTargetPinState.hpp"
|
||||
|
||||
using namespace Bloom;
|
||||
using namespace Bloom::Widgets::InsightTargetWidgets;
|
||||
namespace Bloom::Widgets::InsightTargetWidgets
|
||||
{
|
||||
using Bloom::Targets::TargetVariant;
|
||||
using Bloom::Targets::TargetPinDescriptor;
|
||||
using Bloom::Targets::TargetPinType;
|
||||
using Bloom::Targets::TargetPinState;
|
||||
|
||||
using Bloom::Targets::TargetVariant;
|
||||
using Bloom::Targets::TargetPinDescriptor;
|
||||
using Bloom::Targets::TargetPinType;
|
||||
using Bloom::Targets::TargetPinState;
|
||||
|
||||
TargetPinWidget::TargetPinWidget(
|
||||
Targets::TargetPinDescriptor pinDescriptor,
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
): QWidget(parent),
|
||||
insightWorker(insightWorker),
|
||||
targetVariant(std::move(targetVariant)),
|
||||
pinDescriptor(std::move(pinDescriptor)) {
|
||||
if (this->pinDescriptor.type == TargetPinType::UNKNOWN) {
|
||||
this->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
void TargetPinWidget::onWidgetBodyClicked() {
|
||||
// Currently, we only allow users to toggle the IO state of output pins
|
||||
if (this->pinState.has_value()
|
||||
&& this->pinState.value().ioDirection == TargetPinState::IoDirection::OUTPUT
|
||||
TargetPinWidget::TargetPinWidget(
|
||||
Targets::TargetPinDescriptor pinDescriptor,
|
||||
Targets::TargetVariant targetVariant,
|
||||
InsightWorker& insightWorker,
|
||||
QWidget* parent
|
||||
)
|
||||
: QWidget(parent)
|
||||
, insightWorker(insightWorker)
|
||||
, targetVariant(std::move(targetVariant))
|
||||
, pinDescriptor(std::move(pinDescriptor)
|
||||
) {
|
||||
this->setDisabled(true);
|
||||
if (this->pinDescriptor.type == TargetPinType::UNKNOWN) {
|
||||
this->setDisabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
auto pinState = this->pinState.value();
|
||||
pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) ?
|
||||
TargetPinState::IoState::LOW : TargetPinState::IoState::HIGH;
|
||||
void TargetPinWidget::onWidgetBodyClicked() {
|
||||
// Currently, we only allow users to toggle the IO state of output pins
|
||||
if (this->pinState.has_value()
|
||||
&& this->pinState.value().ioDirection == TargetPinState::IoDirection::OUTPUT
|
||||
) {
|
||||
this->setDisabled(true);
|
||||
|
||||
auto* setPinStateTask = new SetTargetPinState(this->pinDescriptor, pinState);
|
||||
QObject::connect(setPinStateTask, &InsightWorkerTask::completed, this, [this, pinState] {
|
||||
this->updatePinState(pinState);
|
||||
this->setDisabled(false);
|
||||
});
|
||||
auto pinState = this->pinState.value();
|
||||
pinState.ioState = (pinState.ioState == TargetPinState::IoState::HIGH) ?
|
||||
TargetPinState::IoState::LOW : TargetPinState::IoState::HIGH;
|
||||
|
||||
QObject::connect(setPinStateTask, &InsightWorkerTask::failed, this, [this] {
|
||||
this->setDisabled(false);
|
||||
});
|
||||
auto* setPinStateTask = new SetTargetPinState(this->pinDescriptor, pinState);
|
||||
QObject::connect(setPinStateTask, &InsightWorkerTask::completed, this, [this, pinState] {
|
||||
this->updatePinState(pinState);
|
||||
this->setDisabled(false);
|
||||
});
|
||||
|
||||
this->insightWorker.queueTask(setPinStateTask);
|
||||
QObject::connect(setPinStateTask, &InsightWorkerTask::failed, this, [this] {
|
||||
this->setDisabled(false);
|
||||
});
|
||||
|
||||
this->insightWorker.queueTask(setPinStateTask);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user