From 56a3c7d6ce997dbc9081c9762d60ebd84647af4c Mon Sep 17 00:00:00 2001 From: Nav Date: Sat, 23 Oct 2021 12:45:01 +0100 Subject: [PATCH] Decreased the size of pin body widgets for the DIP target package widget Also moved the pin labels around to make best use of the space --- .../Widgets/TargetWidgets/DIP/BodyWidget.cpp | 10 +-- .../TargetWidgets/DIP/PinBodyWidget.hpp | 4 +- .../Widgets/TargetWidgets/DIP/PinWidget.cpp | 64 ++++++++++++++++--- .../Widgets/TargetWidgets/DIP/PinWidget.hpp | 19 +++++- .../DIP/Stylesheets/DualInlinePackage.qss | 5 +- 5 files changed, 79 insertions(+), 23 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp index 16cb5ec7..1e9a1f8a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp @@ -31,7 +31,7 @@ void BodyWidget::drawWidget(QPainter& painter) { painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(targetBodyColor); - auto targetBodyHeight = this->height(); + const auto targetBodyHeight = this->height(); auto targetBodyPoint = QPoint( 0, @@ -50,14 +50,14 @@ void BodyWidget::drawWidget(QPainter& painter) { painter.drawEllipse(QRectF( targetBodyPoint.x() + 10, targetBodyPoint.y() + (targetBodyHeight - 30), - 20, - 20 + 18, + 18 )); painter.drawEllipse(QRectF( targetBodyPoint.x() - 15, targetBodyPoint.y() + (targetBodyHeight / 2) - 15, - 30, - 30 + 28, + 28 )); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp index cc2d92a7..db82e15d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinBodyWidget.hpp @@ -14,8 +14,8 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip Q_OBJECT public: - static const int WIDTH = 30; - static const int HEIGHT = 40; + static const int WIDTH = 25; + static const int HEIGHT = 34; PinBodyWidget( QWidget* parent, diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp index fc9fa13d..1b21ee94 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.cpp @@ -9,12 +9,17 @@ PinWidget::PinWidget( InsightWorker& insightWorker, QWidget* parent ): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) { + this->setFixedSize(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING, PinWidget::MAXIMUM_HEIGHT); + this->layout = new QVBoxLayout(); this->layout->setContentsMargins(0, 0, 0, 0); this->layout->setSpacing(0); this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor); - bool isTopWidget = pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2); + this->position = (pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2)) + ? Position::TOP : Position::BOTTOM; + + const bool isTopWidget = this->position == Position::TOP; this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom) : (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop)); @@ -32,6 +37,7 @@ PinWidget::PinWidget( } this->pinNameLabel->setText(pinName); this->pinNameLabel->setAlignment(Qt::AlignmentFlag::AlignCenter); + this->pinNameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); this->pinNumberLabel = new QLabel(this); this->pinNumberLabel->setObjectName("target-pin-number"); @@ -42,18 +48,56 @@ PinWidget::PinWidget( this->layout->setDirection(QBoxLayout::Direction::BottomToTop); } - this->layout->addWidget(this->bodyWidget); + this->layout->addWidget(this->bodyWidget, 0, Qt::AlignmentFlag::AlignHCenter); this->layout->insertSpacing(1, 3); - this->layout->addWidget(this->pinNumberLabel); - this->layout->insertSpacing(3, 2); - this->layout->addWidget(this->pinNameLabel); - this->layout->insertSpacing(5, 2); - this->layout->addWidget(this->pinDirectionLabel); - this->pinNameLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2); - this->pinNumberLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2); + this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter); + this->layout->insertSpacing(3, (this->pinDescriptor.number % 2 == 0) ? 20 : 2); + this->layout->addWidget(this->pinNameLabel, 0, Qt::AlignmentFlag::AlignHCenter); + this->layout->insertSpacing(5, (this->pinDescriptor.number % 2 != 0) ? 20 : 2); + this->layout->addWidget(this->pinDirectionLabel, 0, Qt::AlignmentFlag::AlignHCenter); + this->pinNameLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2); + this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2); - this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT); this->setLayout(this->layout); connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked); } + +void PinWidget::paintEvent(QPaintEvent* event) { + auto painter = QPainter(this); + this->drawWidget(painter); +} + +void PinWidget::drawWidget(QPainter& painter) { + painter.setPen(QPen(QColor("#4F4F4F"), 1)); + + if (this->pinDescriptor.number % 2 == 0) { + /* + * Minus 17 for the length of the line + * Plus/minus 3 to account for spacing between the pin body and number label + */ + const auto yOffset = this->position == Position::TOP + ? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - PinWidget::LABEL_HEIGHT - 17 - 3 + : PinBodyWidget::HEIGHT + PinWidget::LABEL_HEIGHT + 3; + + painter.drawLine(QLine( + (PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2, + yOffset, + (PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2, + yOffset + 17 + )); + + } else if (this->pinState.has_value()) { + // Plus/minus 2 because it looks nicer + const auto yOffset = this->position == Position::TOP + ? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - (PinWidget::LABEL_HEIGHT * 2) - 17 - 3 + 2 + : PinBodyWidget::HEIGHT + (PinWidget::LABEL_HEIGHT * 2) + 3 - 2; + + painter.drawLine(QLine( + (PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2, + yOffset, + (PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2, + yOffset + 17 + )); + } +} diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp index d89697e1..5b46d76c 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp @@ -1,8 +1,10 @@ #pragma once #include +#include #include #include +#include #include "../TargetPinWidget.hpp" @@ -11,17 +13,23 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip { + enum Position : std::uint8_t + { + TOP, + BOTTOM + }; + class PinWidget: public TargetPinWidget { Q_OBJECT public: - static const int MINIMUM_WIDTH = 30; - static const int WIDTH_SPACING = 8; + static const int MINIMUM_WIDTH = PinBodyWidget::WIDTH; + static const int WIDTH_SPACING = 6; static const int MAXIMUM_LABEL_COUNT = 3; static const int LABEL_HEIGHT = 20; static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT - + (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT); + + (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT) + 40; PinWidget( const Targets::TargetPinDescriptor& pinDescriptor, @@ -49,7 +57,12 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa"); } + protected: + void paintEvent(QPaintEvent* event) override; + void drawWidget(QPainter& painter); + private: + Position position = Position::TOP; QVBoxLayout* layout = nullptr; QLabel* pinNumberLabel = nullptr; QLabel* pinNameLabel = nullptr; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss index 4ee46b8f..12e7422a 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss @@ -1,10 +1,8 @@ -#target-pin-number, #target-pin-number { font-size: 14px; } -#target-pin-name, -#target-pin-direction { +#target-pin-name { font-size: 11px; } @@ -14,6 +12,7 @@ #target-pin-direction { color: #8a8a8d; + font-size: 11px; } #target-pin-body {