Corrected pin spacing issue on DIP target package widget

Also moved redundant resizing out of the paintEvent handler.
And some other tidying of the DIP widget
This commit is contained in:
Nav
2021-09-26 18:15:43 +01:00
parent 647b6bc3e1
commit 135df2395b
5 changed files with 16 additions and 67 deletions

View File

@@ -356,7 +356,6 @@ void InsightWindow::selectVariant(const TargetVariant* variant) {
) {
this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget(
*variant,
this,
this->insightWorker,
this->ioContainerWidget
);

View File

@@ -31,11 +31,8 @@ void BodyWidget::drawWidget(QPainter& painter) {
painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(targetBodyColor);
auto parentContainerWidth = parentWidget->width();
auto targetBodyHeight = 150;
auto targetBodyWidth = parentContainerWidth;
auto targetBodyHeight = this->height();
this->setFixedSize(targetBodyWidth, targetBodyHeight);
auto targetBodyPoint = QPoint(
0,
0
@@ -44,7 +41,7 @@ void BodyWidget::drawWidget(QPainter& painter) {
painter.drawRect(
targetBodyPoint.x(),
targetBodyPoint.y(),
targetBodyWidth,
this->width(),
targetBodyHeight
);

View File

@@ -1,6 +1,5 @@
#include "DualInlinePackageWidget.hpp"
#include <QPainter>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <vector>
@@ -8,8 +7,6 @@
#include <QFile>
#include "../../../InsightWindow.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
#include "src/Helpers/Paths.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"
@@ -21,7 +18,6 @@ using Bloom::Targets::TargetVariant;
DualInlinePackageWidget::DualInlinePackageWidget(
const TargetVariant& targetVariant,
QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent
): TargetPackageWidget(targetVariant, insightWorker, parent) {
@@ -39,13 +35,10 @@ DualInlinePackageWidget::DualInlinePackageWidget(
this->layout->setContentsMargins(0, 0, 0, 0);
this->topPinLayout = new QHBoxLayout();
this->topPinLayout->setSpacing(8);
this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
this->bottomPinLayout = new QHBoxLayout();
this->bottomPinLayout->setSpacing(8);
auto insightWindow = qobject_cast<InsightWindow*>(insightWindowObj);
assert(insightWindow != nullptr);
this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING);
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
auto pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
@@ -64,64 +57,29 @@ DualInlinePackageWidget::DualInlinePackageWidget(
this->layout->addLayout(this->bottomPinLayout);
this->setLayout(this->layout);
auto insightWindowWidget = this->window();
assert(insightWindowWidget != nullptr);
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
* static_cast<int>(this->pinWidgets.size() / 2)) - PinWidget::WIDTH_SPACING + 46;
const auto bodyWidgetHeight = 150;
insightWindowWidget->setMinimumHeight(540);
insightWindowWidget->setMinimumWidth(1100);
}
void DualInlinePackageWidget::paintEvent(QPaintEvent* event) {
// Logger::debug("Drawing main package widget");
auto painter = QPainter(this);
this->drawWidget(painter);
}
void DualInlinePackageWidget::resizeEvent(QResizeEvent* event) {
// Logger::debug("RESIZE EVENT");
}
void DualInlinePackageWidget::drawWidget(QPainter& painter) {
auto parentWidget = this->parentWidget();
if (parentWidget == nullptr) {
throw Exception("DualInlinePackageWidget requires a parent widget");
}
auto parentContainerHeight = parentWidget->height();
auto parentContainerWidth = parentWidget->width();
auto width = ((PinWidget::MINIMUM_WIDTH + 8) * static_cast<int>(this->pinWidgets.size() / 2)) + 46;
const auto width = bodyWidgetWidth;
const auto height = (PinWidget::MAXIMUM_HEIGHT * 2) + bodyWidgetHeight + (8 * 3);
this->bodyWidget->setGeometry(0, PinWidget::MAXIMUM_HEIGHT + 8, width, bodyWidgetHeight);
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
auto bodyGeometry = QRect(0, this->topPinLayout->geometry().height() + 8, width, this->bodyWidget->height());
this->bodyWidget->setGeometry(bodyGeometry);
this->bottomPinLayout->setGeometry(
QRect(
0,
bodyGeometry.top() + bodyGeometry.height() + 8,
(PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (8 * 2)),
width,
PinWidget::MAXIMUM_HEIGHT
)
);
this->topPinLayout->setContentsMargins(
static_cast<int>(width * 0.04),
0,
static_cast<int>(width * 0.04),
0
);
this->bottomPinLayout->setContentsMargins(
static_cast<int>(width * 0.04),
0,
static_cast<int>(width * 0.04),
0
);
this->topPinLayout->setContentsMargins(23, 0, 23, 0);
this->bottomPinLayout->setContentsMargins( 23, 0, 23, 0);
auto height = (PinWidget::MAXIMUM_HEIGHT * 2) + bodyGeometry.height() + (8 * 3);
this->setGeometry(
(parentContainerWidth / 2) - (width / 2),
(parentContainerHeight / 2) - (height / 2),
(parent->width() / 2) - (width / 2),
(parent->height() / 2) - (height / 2),
width,
height
);

View File

@@ -24,15 +24,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
QHBoxLayout* bottomPinLayout = nullptr;
BodyWidget* bodyWidget = nullptr;
protected:
void paintEvent(QPaintEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
void drawWidget(QPainter& painter);
public:
DualInlinePackageWidget(
const Targets::TargetVariant& targetVariant,
QObject* insightWindowObj,
InsightWorker& insightWorker,
QWidget* parent
);

View File

@@ -28,6 +28,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
public:
static const int MINIMUM_WIDTH = 30;
static const int WIDTH_SPACING = 8;
static const int MAXIMUM_LABEL_COUNT = 3;
static const int LABEL_HEIGHT = 20;
static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT