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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user