Made DIP body widget height dynamic, along with indicator sizes.

This commit is contained in:
Nav
2021-12-01 02:33:41 +00:00
parent 5716e6f306
commit 9b1fbb1481
3 changed files with 68 additions and 43 deletions

View File

@@ -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<int>(std::ceil(3.6 * static_cast<double>(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<int>(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);
}