diff --git a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp index ecd7bc2a..cc01b04e 100644 --- a/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/InsightWindow.cpp @@ -363,7 +363,6 @@ void InsightWindow::selectVariant(const TargetVariant* variant) { } else if (variant->package == TargetPackage::QFP || variant->package == TargetPackage::QFN) { this->targetPackageWidget = new InsightTargetWidgets::Qfp::QuadFlatPackageWidget( *variant, - this, this->insightWorker, this->ioContainerWidget ); diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp index 3ceb76c5..813520ba 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/BodyWidget.cpp @@ -23,13 +23,13 @@ void BodyWidget::drawWidget(QPainter& painter) { painter.setPen(Qt::PenStyle::NoPen); painter.setBrush(targetBodyColor); - auto containerGeometry = this->geometry(); - auto targetBodyWidth = containerGeometry.width() - 16; - auto targetBodyHeight = containerGeometry.height() - 16; + const auto containerSize = this->size(); + auto targetBodyWidth = containerSize.width() - 16; + auto targetBodyHeight = containerSize.height() - 16; auto targetBodyPoint = QPoint( - (containerGeometry.width() / 2) - (targetBodyWidth / 2), - (containerGeometry.height() / 2) - (targetBodyHeight / 2) + (containerSize.width() / 2) - (targetBodyWidth / 2), + (containerSize.height() / 2) - (targetBodyHeight / 2) ); painter.drawRect( diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp index 252a437f..f5b90b56 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/PinWidget.hpp @@ -29,7 +29,7 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp public: static const int PIN_WIDGET_LAYOUT_PADDING = 46; - static const int PIN_WIDGET_SPACING = 8; + static const int WIDTH_SPACING = 8; static const int MAXIMUM_LABEL_COUNT = 3; static const int LABEL_HEIGHT = 20; static const int MAXIMUM_LABEL_WIDTH = PinBodyWidget::WIDTH; diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp index f4e1fffa..9d651b70 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.cpp @@ -17,7 +17,6 @@ using namespace Bloom::Targets; QuadFlatPackageWidget::QuadFlatPackageWidget( const TargetVariant& targetVariant, - QObject* insightWindowObj, InsightWorker& insightWorker, QWidget* parent ): TargetPackageWidget(targetVariant, insightWorker, parent) { @@ -41,25 +40,22 @@ QuadFlatPackageWidget::QuadFlatPackageWidget( this->horizontalLayout->setDirection(QBoxLayout::Direction::LeftToRight); this->topPinLayout = new QHBoxLayout(); - this->topPinLayout->setSpacing(PinWidget::PIN_WIDGET_SPACING); + this->topPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft); this->rightPinLayout = new QVBoxLayout(); - this->rightPinLayout->setSpacing(PinWidget::PIN_WIDGET_SPACING); + this->rightPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->rightPinLayout->setDirection(QBoxLayout::Direction::BottomToTop); this->bottomPinLayout = new QHBoxLayout(); - this->bottomPinLayout->setSpacing(PinWidget::PIN_WIDGET_SPACING); + this->bottomPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->bottomPinLayout->setDirection(QBoxLayout::Direction::LeftToRight); this->leftPinLayout = new QVBoxLayout(); - this->leftPinLayout->setSpacing(PinWidget::PIN_WIDGET_SPACING); + this->leftPinLayout->setSpacing(PinWidget::WIDTH_SPACING); this->leftPinLayout->setDirection(QBoxLayout::Direction::TopToBottom); - auto insightWindow = qobject_cast(insightWindowObj); - assert(insightWindow != nullptr); - - auto pinCountPerLayout = (targetVariant.pinDescriptorsByNumber.size() / 4); + const auto pinCountPerLayout = static_cast(targetVariant.pinDescriptorsByNumber.size() / 4); for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) { auto pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this); this->pinWidgets.push_back(pinWidget); @@ -87,70 +83,30 @@ QuadFlatPackageWidget::QuadFlatPackageWidget( this->layout->addLayout(this->bottomPinLayout); this->setLayout(this->layout); - auto insightWindowWidget = this->window(); - assert(insightWindowWidget != nullptr); - - insightWindowWidget->setMinimumHeight( - std::max( - 500, - static_cast((PinWidget::MAXIMUM_HORIZONTAL_HEIGHT * pinCountPerLayout) - + (PinWidget::MAXIMUM_VERTICAL_HEIGHT * 2)) + 300 - ) - ); - - insightWindowWidget->setMinimumWidth( - std::max( - 1000, - static_cast(((PinWidget::MAXIMUM_VERTICAL_WIDTH + PinWidget::PIN_WIDGET_SPACING) * pinCountPerLayout) - + (PinWidget::MAXIMUM_VERTICAL_WIDTH * 2)) + 760 - ) - ); -} - -void QuadFlatPackageWidget::paintEvent(QPaintEvent* event) { - auto painter = QPainter(this); - this->drawWidget(painter); -} - -void QuadFlatPackageWidget::drawWidget(QPainter& painter) { - auto parentWidget = this->parentWidget(); - assert(parentWidget != nullptr); - - auto parentContainerHeight = parentWidget->height(); - auto parentContainerWidth = parentWidget->width(); - - auto verticalPinWidgetHeight = PinWidget::MAXIMUM_VERTICAL_HEIGHT; - auto verticalPinWidgetWidth = PinWidget::MAXIMUM_VERTICAL_WIDTH; - auto horizontalPinWidgetHeight = PinWidget::MAXIMUM_HORIZONTAL_HEIGHT; - auto horizontalPinWidgetWidth = PinWidget::MAXIMUM_HORIZONTAL_WIDTH; - - auto pinCountPerLayout = static_cast(this->pinWidgets.size() / 4); + // Layout sizing, positioning and padding + const auto verticalPinWidgetHeight = PinWidget::MAXIMUM_VERTICAL_HEIGHT; + const auto verticalPinWidgetWidth = PinWidget::MAXIMUM_VERTICAL_WIDTH; + const auto horizontalPinWidgetHeight = PinWidget::MAXIMUM_HORIZONTAL_HEIGHT; + const auto horizontalPinWidgetWidth = PinWidget::MAXIMUM_HORIZONTAL_WIDTH; /* * Horizontal layouts are the right and left pin layouts - the ones that hold horizontal pin widgets. * The bottom and top layouts are vertical layouts, as they hold the vertical pin widgets. */ - auto horizontalLayoutHeight = ((horizontalPinWidgetHeight + PinWidget::PIN_WIDGET_SPACING) * pinCountPerLayout - + PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::PIN_WIDGET_SPACING); + const auto horizontalLayoutHeight = ((horizontalPinWidgetHeight + PinWidget::WIDTH_SPACING) * pinCountPerLayout + + PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING); - auto verticalLayoutWidth = ((verticalPinWidgetWidth + PinWidget::PIN_WIDGET_SPACING) * pinCountPerLayout - + PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::PIN_WIDGET_SPACING); + const auto verticalLayoutWidth = ((verticalPinWidgetWidth + PinWidget::WIDTH_SPACING) * pinCountPerLayout + + PinWidget::PIN_WIDGET_LAYOUT_PADDING - PinWidget::WIDTH_SPACING); - auto containerWidth = verticalLayoutWidth + (horizontalPinWidgetWidth * 2); + const auto width = verticalLayoutWidth + (horizontalPinWidgetWidth * 2); + const auto height = horizontalLayoutHeight + (verticalPinWidgetHeight * 2); - this->topPinLayout->setGeometry(QRect( - horizontalPinWidgetWidth, - 0, - verticalLayoutWidth, - verticalPinWidgetHeight - )); + this->topPinLayout->insertSpacing(0, horizontalPinWidgetWidth); + this->topPinLayout->addSpacing(horizontalPinWidgetWidth); - this->horizontalLayout->setGeometry(QRect( - 0, - verticalPinWidgetHeight, - containerWidth, - horizontalLayoutHeight - )); + this->bottomPinLayout->insertSpacing(0, horizontalPinWidgetWidth); + this->bottomPinLayout->addSpacing(horizontalPinWidgetWidth); this->leftPinLayout->setGeometry(QRect( 0, @@ -159,12 +115,7 @@ void QuadFlatPackageWidget::drawWidget(QPainter& painter) { horizontalLayoutHeight )); - this->bodyWidget->setGeometry(QRect( - horizontalPinWidgetWidth, - verticalPinWidgetHeight, - horizontalLayoutHeight, - horizontalLayoutHeight - )); + this->bodyWidget->setFixedSize(verticalLayoutWidth, horizontalLayoutHeight); this->rightPinLayout->setGeometry(QRect( horizontalLayoutHeight + horizontalPinWidgetWidth, @@ -173,14 +124,7 @@ void QuadFlatPackageWidget::drawWidget(QPainter& painter) { horizontalLayoutHeight )); - this->bottomPinLayout->setGeometry(QRect( - horizontalPinWidgetWidth, - verticalPinWidgetHeight + horizontalLayoutHeight, - verticalLayoutWidth, - verticalPinWidgetHeight - )); - - auto pinWidgetLayoutMargin = PinWidget::PIN_WIDGET_LAYOUT_PADDING / 2; + const auto pinWidgetLayoutMargin = PinWidget::PIN_WIDGET_LAYOUT_PADDING / 2; this->topPinLayout->setContentsMargins( pinWidgetLayoutMargin, @@ -210,11 +154,11 @@ void QuadFlatPackageWidget::drawWidget(QPainter& painter) { pinWidgetLayoutMargin ); - auto containerHeight = horizontalLayoutHeight + (verticalPinWidgetHeight * 2); + // Set the fixed size and center the widget this->setGeometry( - (parentContainerWidth / 2) - (containerWidth / 2), - (parentContainerHeight / 2) - (containerHeight / 2), - containerWidth, - containerHeight + (parent->width() / 2) - (width / 2), + (parent->height() / 2) - (height / 2), + width, + height ); } diff --git a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp index 7bbf5f09..c2bfb446 100644 --- a/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp +++ b/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/QFP/QuadFlatPackageWidget.hpp @@ -27,14 +27,9 @@ namespace Bloom::Widgets::InsightTargetWidgets::Qfp QVBoxLayout* leftPinLayout = nullptr; BodyWidget* bodyWidget = nullptr; - protected: - void paintEvent(QPaintEvent* event) override; - void drawWidget(QPainter& painter); - public: QuadFlatPackageWidget( const Targets::TargetVariant& targetVariant, - QObject* insightWindowObj, InsightWorker& insightWorker, QWidget* parent );