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( this->targetPackageWidget = new InsightTargetWidgets::Dip::DualInlinePackageWidget(
*variant, *variant,
this,
this->insightWorker, this->insightWorker,
this->ioContainerWidget this->ioContainerWidget
); );

View File

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

View File

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

View File

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

View File

@@ -28,6 +28,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
public: public:
static const int MINIMUM_WIDTH = 30; static const int MINIMUM_WIDTH = 30;
static const int WIDTH_SPACING = 8;
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