Files
BloomPatched/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/DualInlinePackageWidget.cpp

88 lines
3.2 KiB
C++
Raw Normal View History

#include "DualInlinePackageWidget.hpp"
2021-04-04 21:04:12 +01:00
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <vector>
#include <QEvent>
#include <QFile>
#include "src/Helpers/Paths.hpp"
2021-04-04 21:04:12 +01:00
using namespace Bloom::Widgets::InsightTargetWidgets::Dip;
2021-04-04 21:04:12 +01:00
using namespace Bloom::Exceptions;
using Bloom::Targets::TargetVariant;
DualInlinePackageWidget::DualInlinePackageWidget(
const TargetVariant& targetVariant,
InsightWorker& insightWorker,
QWidget* parent
): TargetPackageWidget(targetVariant, insightWorker, parent) {
auto stylesheetFile = QFile(QString::fromStdString(
Paths::compiledResourcesPath()
+ "/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss"
)
);
2021-04-04 21:04:12 +01:00
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
this->layout = new QVBoxLayout();
this->layout->setSpacing(PinWidget::WIDTH_SPACING);
2021-08-18 22:51:15 +01:00
this->layout->setContentsMargins(0, 0, 0, 0);
2021-04-04 21:04:12 +01:00
this->topPinLayout = new QHBoxLayout();
this->topPinLayout->setSpacing(0);
2021-04-04 21:04:12 +01:00
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
this->topPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
2021-04-04 21:04:12 +01:00
this->bottomPinLayout = new QHBoxLayout();
this->bottomPinLayout->setSpacing(0);
this->bottomPinLayout->setAlignment(Qt::AlignmentFlag::AlignHCenter);
2021-04-04 21:04:12 +01:00
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
auto* pinWidget = new PinWidget(targetPinDescriptor, targetVariant, insightWorker, this);
2021-04-04 21:04:12 +01:00
this->pinWidgets.push_back(pinWidget);
if (targetPinNumber <= (targetVariant.pinDescriptorsByNumber.size() / 2)) {
this->bottomPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
} else {
this->topPinLayout->addWidget(pinWidget, 0, Qt::AlignmentFlag::AlignHCenter);
2021-04-04 21:04:12 +01:00
}
}
this->layout->addLayout(this->topPinLayout);
this->bodyWidget = new BodyWidget(this);
this->layout->addWidget(this->bodyWidget);
this->layout->addLayout(this->bottomPinLayout);
this->setLayout(this->layout);
const auto bodyWidgetWidth = ((PinWidget::MINIMUM_WIDTH + PinWidget::WIDTH_SPACING)
* static_cast<int>(this->pinWidgets.size() / 2)) + 46;
const auto bodyWidgetHeight = 150;
2021-04-04 21:04:12 +01:00
const auto width = bodyWidgetWidth;
const auto height = (PinWidget::MAXIMUM_HEIGHT * 2) + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2);
2021-04-04 21:04:12 +01:00
this->bodyWidget->setGeometry(0, PinWidget::MAXIMUM_HEIGHT + PinWidget::WIDTH_SPACING, width, bodyWidgetHeight);
2021-04-04 21:04:12 +01:00
this->topPinLayout->setGeometry(QRect(0, 0, width, PinWidget::MAXIMUM_HEIGHT));
this->bottomPinLayout->setGeometry(
QRect(
0,
(PinWidget::MAXIMUM_HEIGHT + bodyWidgetHeight + (PinWidget::WIDTH_SPACING * 2)),
2021-04-04 21:04:12 +01:00
width,
PinWidget::MAXIMUM_HEIGHT
)
);
this->topPinLayout->setContentsMargins(23, 0, 23, 0);
this->bottomPinLayout->setContentsMargins( 23, 0, 23, 0);
2021-04-04 21:04:12 +01:00
this->setFixedSize(width, height);
2021-04-04 21:04:12 +01:00
this->setGeometry(
(parent->width() / 2) - (width / 2),
(parent->height() / 2) - (height / 2),
2021-04-04 21:04:12 +01:00
width,
height
);
}