From 9b1fbb148101ea728dc17d632ec1bfbf897d169f Mon Sep 17 00:00:00 2001 From: Nav Date: Wed, 1 Dec 2021 02:33:41 +0000 Subject: [PATCH] Made DIP body widget height dynamic, along with indicator sizes. --- .../Widgets/TargetWidgets/DIP/BodyWidget.cpp | 79 +++++++++++-------- .../Widgets/TargetWidgets/DIP/BodyWidget.hpp | 11 ++- .../DIP/DualInlinePackageWidget.cpp | 21 ++--- 3 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp index 6f2e45ed..1adc4194 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.cpp @@ -2,10 +2,26 @@ using namespace Bloom::Widgets::InsightTargetWidgets::Dip; -BodyWidget::BodyWidget(QWidget* parent): QWidget(parent) { +BodyWidget::BodyWidget(QWidget* parent, std::size_t pinCount): QWidget(parent) { this->setObjectName("target-body"); + this->setFixedHeight( + std::min( + BodyWidget::MAXIMUM_BODY_HEIGHT, + std::max( + BodyWidget::MINIMUM_BODY_HEIGHT, + static_cast(std::ceil(3.6 * static_cast(pinCount))) + ) + ) + ); - this->setFixedHeight(BodyWidget::HEIGHT); + this->firstPinIndicatorDiameter = std::min( + BodyWidget::MAXIMUM_FIRST_PIN_INDICATOR_HEIGHT, + std::max(BodyWidget::MINIMUM_FIRST_PIN_INDICATOR_HEIGHT, static_cast(std::floor(pinCount / 2))) + ); + + this->orientationIndicatorDiameter = this->firstPinIndicatorDiameter % 2 == 0 ? + this->firstPinIndicatorDiameter + 3 + : this->firstPinIndicatorDiameter + 2; } void BodyWidget::paintEvent(QPaintEvent* event) { @@ -15,10 +31,35 @@ void BodyWidget::paintEvent(QPaintEvent* event) { 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 + ); - // Draw target body + // 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(); - auto backgroundColor = QColor(0x37, 0x38, 0x35); if (!this->isEnabled()) { targetBodyColor.setAlpha(this->getDisableAlphaLevel()); @@ -26,32 +67,8 @@ void BodyWidget::drawWidget(QPainter& painter) { painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(targetBodyColor); - - auto targetBodyPoint = QPoint( - 0, - 0 - ); - - painter.drawRect( - targetBodyPoint.x(), - targetBodyPoint.y(), - this->width(), - BodyWidget::HEIGHT - ); - - painter.setPen(Qt::PenStyle::NoPen); + painter.drawRect(bodyRect); painter.setBrush(backgroundColor); - painter.drawEllipse(QRectF( - targetBodyPoint.x() + 10, - targetBodyPoint.y() + (BodyWidget::HEIGHT - 30), - 18, - 18 - )); - - painter.drawEllipse(QRectF( - targetBodyPoint.x() - 15, - targetBodyPoint.y() + (BodyWidget::HEIGHT / 2) - 15, - 24, - 24 - )); + painter.drawEllipse(firstPinIndicatorRect); + painter.drawEllipse(orientationIndicatorRect); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp index 0c97f000..91478d7d 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/BodyWidget.hpp @@ -12,9 +12,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true) public: - static constexpr int HEIGHT = 130; - - explicit BodyWidget(QWidget* parent); + explicit BodyWidget(QWidget* parent, std::size_t pinCount); [[nodiscard]] QColor getBodyColor() const { return this->bodyColor; @@ -37,8 +35,15 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip void drawWidget(QPainter& painter); private: + static constexpr int MAXIMUM_BODY_HEIGHT = 156; + static constexpr int MINIMUM_BODY_HEIGHT = 80; + static constexpr int MAXIMUM_FIRST_PIN_INDICATOR_HEIGHT = 16; + static constexpr int MINIMUM_FIRST_PIN_INDICATOR_HEIGHT = 12; + // These properties can be modified via Qt style sheets (see Stylesheets/DualInlinePackage.qss) QColor bodyColor = QColor("#8E8B83"); int disableAlphaLevel = 100; + int firstPinIndicatorDiameter = 14; + int orientationIndicatorDiameter = 16; }; } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp index bed6a4d1..c3d57834 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp @@ -52,15 +52,24 @@ DualInlinePackageWidget::DualInlinePackageWidget( } } + this->bodyWidget = new BodyWidget(this, targetVariant.pinDescriptorsByNumber.size()); + this->layout->addLayout(this->topPinLayout); - this->bodyWidget = new BodyWidget(this); 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(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 = ( ( @@ -68,19 +77,13 @@ DualInlinePackageWidget::DualInlinePackageWidget( + PinWidget::PIN_LABEL_SHORT_LINE_LENGTH + ( (PinWidget::LABEL_HEIGHT + PinWidget::PIN_LABEL_SPACING) * 2 ) - ) * 2) + BodyWidget::HEIGHT; + ) * 2) + bodyWidgetHeight; - this->bodyWidget->setGeometry( - 0, - PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING, - width, - BodyWidget::HEIGHT - ); this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT)); this->bottomPinLayout->setGeometry( QRect( 0, - (PinWidget::MAXIMUM_HEIGHT + BodyWidget::HEIGHT + (PinWidget::WIDTH_SPACING * 2)), + (PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2)), width, PinWidget::MAXIMUM_HEIGHT )