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
This commit is contained in:
@@ -31,7 +31,7 @@ void BodyWidget::drawWidget(QPainter& painter) {
|
|||||||
|
|
||||||
painter.setPen(Qt::PenStyle::NoPen);
|
painter.setPen(Qt::PenStyle::NoPen);
|
||||||
painter.setBrush(targetBodyColor);
|
painter.setBrush(targetBodyColor);
|
||||||
auto targetBodyHeight = this->height();
|
const auto targetBodyHeight = this->height();
|
||||||
|
|
||||||
auto targetBodyPoint = QPoint(
|
auto targetBodyPoint = QPoint(
|
||||||
0,
|
0,
|
||||||
@@ -50,14 +50,14 @@ void BodyWidget::drawWidget(QPainter& painter) {
|
|||||||
painter.drawEllipse(QRectF(
|
painter.drawEllipse(QRectF(
|
||||||
targetBodyPoint.x() + 10,
|
targetBodyPoint.x() + 10,
|
||||||
targetBodyPoint.y() + (targetBodyHeight - 30),
|
targetBodyPoint.y() + (targetBodyHeight - 30),
|
||||||
20,
|
18,
|
||||||
20
|
18
|
||||||
));
|
));
|
||||||
|
|
||||||
painter.drawEllipse(QRectF(
|
painter.drawEllipse(QRectF(
|
||||||
targetBodyPoint.x() - 15,
|
targetBodyPoint.x() - 15,
|
||||||
targetBodyPoint.y() + (targetBodyHeight / 2) - 15,
|
targetBodyPoint.y() + (targetBodyHeight / 2) - 15,
|
||||||
30,
|
28,
|
||||||
30
|
28
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int WIDTH = 30;
|
static const int WIDTH = 25;
|
||||||
static const int HEIGHT = 40;
|
static const int HEIGHT = 34;
|
||||||
|
|
||||||
PinBodyWidget(
|
PinBodyWidget(
|
||||||
QWidget* parent,
|
QWidget* parent,
|
||||||
|
|||||||
@@ -9,12 +9,17 @@ PinWidget::PinWidget(
|
|||||||
InsightWorker& insightWorker,
|
InsightWorker& insightWorker,
|
||||||
QWidget* parent
|
QWidget* parent
|
||||||
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
): TargetPinWidget(pinDescriptor, targetVariant, insightWorker, parent) {
|
||||||
|
this->setFixedSize(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING, PinWidget::MAXIMUM_HEIGHT);
|
||||||
|
|
||||||
this->layout = new QVBoxLayout();
|
this->layout = new QVBoxLayout();
|
||||||
this->layout->setContentsMargins(0, 0, 0, 0);
|
this->layout->setContentsMargins(0, 0, 0, 0);
|
||||||
this->layout->setSpacing(0);
|
this->layout->setSpacing(0);
|
||||||
|
|
||||||
this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor);
|
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)
|
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
|
||||||
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
|
||||||
@@ -32,6 +37,7 @@ PinWidget::PinWidget(
|
|||||||
}
|
}
|
||||||
this->pinNameLabel->setText(pinName);
|
this->pinNameLabel->setText(pinName);
|
||||||
this->pinNameLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
this->pinNameLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
|
||||||
|
this->pinNameLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
|
||||||
|
|
||||||
this->pinNumberLabel = new QLabel(this);
|
this->pinNumberLabel = new QLabel(this);
|
||||||
this->pinNumberLabel->setObjectName("target-pin-number");
|
this->pinNumberLabel->setObjectName("target-pin-number");
|
||||||
@@ -42,18 +48,56 @@ PinWidget::PinWidget(
|
|||||||
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
|
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->insertSpacing(1, 3);
|
||||||
this->layout->addWidget(this->pinNumberLabel);
|
this->layout->addWidget(this->pinNumberLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->layout->insertSpacing(3, 2);
|
this->layout->insertSpacing(3, (this->pinDescriptor.number % 2 == 0) ? 20 : 2);
|
||||||
this->layout->addWidget(this->pinNameLabel);
|
this->layout->addWidget(this->pinNameLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->layout->insertSpacing(5, 2);
|
this->layout->insertSpacing(5, (this->pinDescriptor.number % 2 != 0) ? 20 : 2);
|
||||||
this->layout->addWidget(this->pinDirectionLabel);
|
this->layout->addWidget(this->pinDirectionLabel, 0, Qt::AlignmentFlag::AlignHCenter);
|
||||||
this->pinNameLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
|
this->pinNameLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2);
|
||||||
this->pinNumberLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
|
this->pinNumberLabel->setFixedHeight(PinWidget::LABEL_HEIGHT - 2);
|
||||||
|
|
||||||
this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT);
|
|
||||||
this->setLayout(this->layout);
|
this->setLayout(this->layout);
|
||||||
|
|
||||||
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PinWidget::paintEvent(QPaintEvent* event) {
|
||||||
|
auto painter = QPainter(this);
|
||||||
|
this->drawWidget(painter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PinWidget::drawWidget(QPainter& painter) {
|
||||||
|
painter.setPen(QPen(QColor("#4F4F4F"), 1));
|
||||||
|
|
||||||
|
if (this->pinDescriptor.number % 2 == 0) {
|
||||||
|
/*
|
||||||
|
* Minus 17 for the length of the line
|
||||||
|
* Plus/minus 3 to account for spacing between the pin body and number label
|
||||||
|
*/
|
||||||
|
const auto yOffset = this->position == Position::TOP
|
||||||
|
? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - PinWidget::LABEL_HEIGHT - 17 - 3
|
||||||
|
: PinBodyWidget::HEIGHT + PinWidget::LABEL_HEIGHT + 3;
|
||||||
|
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
||||||
|
yOffset,
|
||||||
|
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
||||||
|
yOffset + 17
|
||||||
|
));
|
||||||
|
|
||||||
|
} else if (this->pinState.has_value()) {
|
||||||
|
// Plus/minus 2 because it looks nicer
|
||||||
|
const auto yOffset = this->position == Position::TOP
|
||||||
|
? PinWidget::MAXIMUM_HEIGHT - PinBodyWidget::HEIGHT - (PinWidget::LABEL_HEIGHT * 2) - 17 - 3 + 2
|
||||||
|
: PinBodyWidget::HEIGHT + (PinWidget::LABEL_HEIGHT * 2) + 3 - 2;
|
||||||
|
|
||||||
|
painter.drawLine(QLine(
|
||||||
|
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
||||||
|
yOffset,
|
||||||
|
(PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING) / 2,
|
||||||
|
yOffset + 17
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
#include <cstdint>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
|
#include <QPainter>
|
||||||
|
|
||||||
#include "../TargetPinWidget.hpp"
|
#include "../TargetPinWidget.hpp"
|
||||||
|
|
||||||
@@ -11,17 +13,23 @@
|
|||||||
|
|
||||||
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||||
{
|
{
|
||||||
|
enum Position : std::uint8_t
|
||||||
|
{
|
||||||
|
TOP,
|
||||||
|
BOTTOM
|
||||||
|
};
|
||||||
|
|
||||||
class PinWidget: public TargetPinWidget
|
class PinWidget: public TargetPinWidget
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static const int MINIMUM_WIDTH = 30;
|
static const int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
|
||||||
static const int WIDTH_SPACING = 8;
|
static const int WIDTH_SPACING = 6;
|
||||||
static const int MAXIMUM_LABEL_COUNT = 3;
|
static const int MAXIMUM_LABEL_COUNT = 3;
|
||||||
static const int LABEL_HEIGHT = 20;
|
static const int LABEL_HEIGHT = 20;
|
||||||
static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT
|
static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT
|
||||||
+ (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT);
|
+ (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT) + 40;
|
||||||
|
|
||||||
PinWidget(
|
PinWidget(
|
||||||
const Targets::TargetPinDescriptor& pinDescriptor,
|
const Targets::TargetPinDescriptor& pinDescriptor,
|
||||||
@@ -49,7 +57,12 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
|||||||
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
|
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void paintEvent(QPaintEvent* event) override;
|
||||||
|
void drawWidget(QPainter& painter);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Position position = Position::TOP;
|
||||||
QVBoxLayout* layout = nullptr;
|
QVBoxLayout* layout = nullptr;
|
||||||
QLabel* pinNumberLabel = nullptr;
|
QLabel* pinNumberLabel = nullptr;
|
||||||
QLabel* pinNameLabel = nullptr;
|
QLabel* pinNameLabel = nullptr;
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
#target-pin-number,
|
|
||||||
#target-pin-number {
|
#target-pin-number {
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#target-pin-name,
|
#target-pin-name {
|
||||||
#target-pin-direction {
|
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -14,6 +12,7 @@
|
|||||||
|
|
||||||
#target-pin-direction {
|
#target-pin-direction {
|
||||||
color: #8a8a8d;
|
color: #8a8a8d;
|
||||||
|
font-size: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#target-pin-body {
|
#target-pin-body {
|
||||||
|
|||||||
Reference in New Issue
Block a user