Initial commit

This commit is contained in:
Nav
2021-04-04 21:04:12 +01:00
commit a29c5e1fec
549 changed files with 441216 additions and 0 deletions

View File

@@ -0,0 +1,70 @@
#include <QPainter>
#include <cmath>
#include "BodyWidget.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::InsightTargetWidgets::Dip;
using namespace Bloom::Exceptions;
void BodyWidget::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this);
this->drawWidget(painter);
}
void BodyWidget::drawWidget(QPainter& painter) {
auto parentWidget = this->parentWidget();
if (parentWidget == nullptr) {
throw Exception("BodyWidget requires a parent widget");
}
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
// Draw target body
// auto targetBodyColor = QColor("#AFB1B3");
auto targetBodyColor = this->getBodyColor();
auto backgroundColor = QColor("#3C3F41");
if (!this->isEnabled()) {
targetBodyColor.setAlpha(this->getDisableAlphaLevel());
}
painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(targetBodyColor);
auto parentContainerWidth = parentWidget->width();
// this->setFixedSize(parentContainerWidth, parentContainerHeight);
auto targetBodyHeight = 150;
auto targetBodyWidth = parentContainerWidth;
this->setFixedSize(targetBodyWidth, targetBodyHeight);
auto targetBodyPoint = QPoint(
0,
0
);
painter.drawRect(
targetBodyPoint.x(),
targetBodyPoint.y(),
targetBodyWidth,
targetBodyHeight
);
painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(backgroundColor);
painter.drawEllipse(QRectF(
targetBodyPoint.x() + 10,
targetBodyPoint.y() + (targetBodyHeight - 30),
20,
20
));
painter.drawEllipse(QRectF(
targetBodyPoint.x() - 15,
targetBodyPoint.y() + (targetBodyHeight / 2) - 15,
30,
30
));
}

View File

@@ -0,0 +1,42 @@
#pragma once
#include <QWidget>
namespace Bloom::InsightTargetWidgets::Dip
{
class BodyWidget: public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
QColor bodyColor = QColor("#AFB1B3");
int disableAlphaLevel = 100;
protected:
void paintEvent(QPaintEvent* event);
void drawWidget(QPainter& painter);
public:
BodyWidget(QWidget* parent): QWidget(parent) {
this->setObjectName("target-body");
}
QColor getBodyColor() const {
return this->bodyColor;
}
void setBodyColor(QColor color) {
this->bodyColor = color;
}
int getDisableAlphaLevel() const {
return this->disableAlphaLevel;
}
void setDisableAlphaLevel(int level) {
this->disableAlphaLevel = level;
}
};
}

View File

@@ -0,0 +1,119 @@
#include <QPainter>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <vector>
#include <QEvent>
#include <QFile>
#include "../../InsightWindow.hpp"
#include "DualInlinePackageWidget.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"
using namespace Bloom::InsightTargetWidgets::Dip;
using namespace Bloom::Exceptions;
DualInlinePackageWidget::DualInlinePackageWidget(const TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent):
TargetPackageWidget(targetVariant, insightWindowObj, parent) {
auto stylesheetFile = QFile("/home/nav/Projects/Bloom/src/Insight/UserInterfaces/InsightWindow/TargetWidgets/DIP/Stylesheets/DualInlinePackage.qss");
stylesheetFile.open(QFile::ReadOnly);
this->setStyleSheet(stylesheetFile.readAll());
this->pinWidgets.reserve(targetVariant.pinDescriptorsByNumber.size());
this->layout = new QVBoxLayout();
this->layout->setSpacing(8);
this->layout->setMargin(0);
this->topPinLayout = new QHBoxLayout();
this->topPinLayout->setSpacing(8);
this->topPinLayout->setDirection(QBoxLayout::Direction::RightToLeft);
this->bottomPinLayout = new QHBoxLayout();
this->bottomPinLayout->setSpacing(8);
auto insightWindow = qobject_cast<InsightWindow*>(insightWindowObj);
assert(insightWindow != nullptr);
for (const auto& [targetPinNumber, targetPinDescriptor]: targetVariant.pinDescriptorsByNumber) {
auto pinWidget = new PinWidget(this, targetPinDescriptor, targetVariant);
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::AlignRight);
}
connect(pinWidget, &TargetPinWidget::toggleIoState, insightWindow, &InsightWindow::togglePinIoState);
}
this->layout->addLayout(this->topPinLayout);
this->bodyWidget = new BodyWidget(this);
this->layout->addWidget(this->bodyWidget);
this->layout->addLayout(this->bottomPinLayout);
this->setLayout(this->layout);
auto insightWindowWidget = this->window();
assert(insightWindowWidget != nullptr);
insightWindowWidget->setMinimumHeight(500);
insightWindowWidget->setMinimumWidth(1000);
}
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->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,
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
);
auto height = (PinWidget::MAXIMUM_HEIGHT * 2) + bodyGeometry.height() + (8 * 3);
this->setGeometry(
(parentContainerWidth / 2) - (width / 2),
(parentContainerHeight / 2) - (height / 2),
width,
height
);
}

View File

@@ -0,0 +1,37 @@
#pragma once
#include <QWidget>
#include <vector>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include "../TargetPackageWidget.hpp"
#include "PinWidget.hpp"
#include "BodyWidget.hpp"
#include "src/Targets/TargetVariant.hpp"
namespace Bloom::InsightTargetWidgets::Dip
{
using Targets::TargetVariant;
/**
* The DualInlinePackageWidget implements a custom Qt widget for the Dual-inline package target variants.
*/
class DualInlinePackageWidget: public TargetPackageWidget
{
Q_OBJECT
private:
QVBoxLayout* layout = nullptr;
QHBoxLayout* topPinLayout = nullptr;
QHBoxLayout* bottomPinLayout = nullptr;
BodyWidget* bodyWidget = nullptr;
protected:
void paintEvent(QPaintEvent* event);
void resizeEvent(QResizeEvent* event);
void drawWidget(QPainter& painter);
public:
DualInlinePackageWidget(const TargetVariant& targetVariant, QObject* insightWindowObj, QWidget* parent);
};
}

View File

@@ -0,0 +1,91 @@
#include <QPainter>
#include <QLayout>
#include <cmath>
#include <QEvent>
#include <QMenu>
#include <QContextMenuEvent>
#include "PinBodyWidget.hpp"
#include "src/Logger/Logger.hpp"
#include "src/Exceptions/Exception.hpp"
using namespace Bloom::InsightTargetWidgets::Dip;
using namespace Bloom::Exceptions;
void PinBodyWidget::paintEvent(QPaintEvent* event) {
auto painter = QPainter(this);
this->drawWidget(painter);
}
bool PinBodyWidget::event(QEvent* event)
{
if (this->isEnabled() && this->pinState.has_value() && this->pinState->ioDirection == TargetPinState::IoDirection::OUTPUT) {
switch (event->type()) {
case QEvent::Enter: {
this->hoverActive = true;
this->repaint();
break;
}
case QEvent::Leave: {
this->hoverActive = false;
this->repaint();
break;
}
default: {
break;
}
}
}
return QWidget::event(event);
}
void PinBodyWidget::drawWidget(QPainter& painter) {
auto parentWidget = this->parentWidget();
if (parentWidget == nullptr) {
Logger::error("PinBodyWidget requires a parent widget");
}
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
auto pinWidth = PinBodyWidget::WIDTH;
auto pinHeight = PinBodyWidget::HEIGHT;
this->setFixedSize(pinWidth, pinHeight);
auto pinColor = this->getBodyColor();
if (this->pinDescriptor.type == TargetPinType::VCC) {
pinColor = QColor("#ff3d43");
} else if (this->pinDescriptor.type == TargetPinType::GND) {
pinColor = QColor("#575757");
}
if (this->pinState.has_value()) {
if (this->pinState->ioState.has_value()
&& this->pinState->ioDirection.has_value()
&& this->pinState->ioState.value() == TargetPinState::IoState::HIGH
) {
pinColor = this->pinState->ioDirection.value() == TargetPinState::IoDirection::OUTPUT ?
QColor("#3D7F96") : QColor("#A47E3E");
}
}
if (!this->hoverActive) {
pinColor.setAlpha(225);
}
if (!this->isEnabled()) {
pinColor.setAlpha(this->getDisableAlphaLevel());
}
painter.setPen(Qt::PenStyle::NoPen);
painter.setBrush(pinColor);
painter.drawRect(
0,
0,
pinWidth,
pinHeight
);
}

View File

@@ -0,0 +1,71 @@
#pragma once
#include <QWidget>
#include <QMouseEvent>
#include "src/Targets/TargetPinDescriptor.hpp"
namespace Bloom::InsightTargetWidgets::Dip
{
using Targets::TargetPinDescriptor;
using Targets::TargetPinType;
using Targets::TargetPinState;
class PinBodyWidget: public QWidget
{
Q_OBJECT
Q_PROPERTY(QColor bodyColor READ getBodyColor WRITE setBodyColor DESIGNABLE true)
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
TargetPinDescriptor pinDescriptor;
std::optional<TargetPinState> pinState;
QColor bodyColor = QColor("#AFB1B3");
int disableAlphaLevel = 100;
protected:
bool hoverActive = false;
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
bool event(QEvent* event) override;
void mouseReleaseEvent(QMouseEvent* event) override {
if (event->button() == Qt::MouseButton::LeftButton) {
emit this->clicked();
}
QWidget::mouseReleaseEvent(event);
}
public:
static const int WIDTH = 30;
static const int HEIGHT = 40;
PinBodyWidget(QWidget* parent, const TargetPinDescriptor& pinDescriptor): QWidget(parent), pinDescriptor(pinDescriptor) {
this->setFixedSize(PinBodyWidget::WIDTH, PinBodyWidget::HEIGHT);
this->setObjectName("target-pin-body");
}
void setPinState(const TargetPinState& pinState) {
this->pinState = pinState;
}
QColor getBodyColor() const {
return this->bodyColor;
}
void setBodyColor(QColor color) {
this->bodyColor = color;
}
int getDisableAlphaLevel() const {
return this->disableAlphaLevel;
}
void setDisableAlphaLevel(int level) {
this->disableAlphaLevel = level;
}
signals:
void clicked();
};
}

View File

@@ -0,0 +1,58 @@
#include <QWidget>
#include <QPainter>
#include <QLayout>
#include <cmath>
#include <QEvent>
#include "PinWidget.hpp"
#include "PinBodyWidget.hpp"
#include "src/Logger/Logger.hpp"
using namespace Bloom::InsightTargetWidgets::Dip;
PinWidget::PinWidget(QWidget* parent, const TargetPinDescriptor& pinDescriptor, const TargetVariant& targetVariant):
TargetPinWidget(parent, pinDescriptor, targetVariant) {
this->layout = new QVBoxLayout();
this->layout->setMargin(0);
this->layout->setSpacing(0);
this->bodyWidget = new PinBodyWidget(this, this->pinDescriptor);
bool isTopWidget = pinDescriptor.number > (targetVariant.pinDescriptorsByNumber.size() / 2);
this->layout->setAlignment(isTopWidget ? (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignBottom)
: (Qt::AlignmentFlag::AlignHCenter | Qt::AlignmentFlag::AlignTop));
this->pinDirectionLabel = new QLabel(this);
this->pinDirectionLabel->setObjectName("target-pin-direction");
this->pinDirectionLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
this->pinNameLabel = new QLabel(this);
this->pinNameLabel->setObjectName("target-pin-name");
this->pinNameLabel->setText(QString::fromStdString(pinDescriptor.name).toUpper());
this->pinNameLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
this->pinNumberLabel = new QLabel(this);
this->pinNumberLabel->setObjectName("target-pin-number");
this->pinNumberLabel->setText(QString::number(pinDescriptor.number));
this->pinNumberLabel->setAlignment(Qt::AlignmentFlag::AlignCenter);
if (isTopWidget) {
this->layout->setDirection(QBoxLayout::Direction::BottomToTop);
}
this->layout->addWidget(this->bodyWidget);
this->layout->insertSpacing(1, 3);
this->layout->addWidget(this->pinNumberLabel);
this->layout->insertSpacing(3, 2);
this->layout->addWidget(this->pinNameLabel);
this->layout->insertSpacing(5, 2);
this->layout->addWidget(this->pinDirectionLabel);
this->pinNameLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
this->pinNumberLabel->setFixedSize(PinBodyWidget::WIDTH, PinWidget::LABEL_HEIGHT - 2);
this->setFixedSize(PinWidget::MINIMUM_WIDTH, PinWidget::MAXIMUM_HEIGHT);
this->setLayout(this->layout);
connect(this->bodyWidget, &PinBodyWidget::clicked, this, &TargetPinWidget::onWidgetBodyClicked);
}

View File

@@ -0,0 +1,59 @@
#pragma once
#include <QWidget>
#include <QLabel>
#include "../TargetPinWidget.hpp"
#include "PinBodyWidget.hpp"
#include "src/Targets/TargetVariant.hpp"
namespace Bloom::InsightTargetWidgets::Dip
{
class PinWidget: public TargetPinWidget
{
Q_OBJECT
private:
QVBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
void setLabelColor(QString hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNumberLabel != nullptr) {
// this->pinNumberLabel->setStyleSheet(style);
}
if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style);
}
}
public:
static const int MINIMUM_WIDTH = 30;
static const int MAXIMUM_LABEL_COUNT = 3;
static const int LABEL_HEIGHT = 20;
static const int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT + (PinWidget::LABEL_HEIGHT * PinWidget::MAXIMUM_LABEL_COUNT);
PinWidget(QWidget* parent, const TargetPinDescriptor& pinDescriptor, const TargetVariant& targetVariant);
virtual void updatePinState(const TargetPinState& pinState) override {
TargetPinWidget::updatePinState(pinState);
if (pinState.ioDirection.has_value()) {
this->pinDirectionLabel->setText(pinState.ioDirection.value() == TargetPinState::IoDirection::INPUT ?
"IN" : "OUT");
} else {
this->pinDirectionLabel->setText("");
}
if (this->bodyWidget != nullptr) {
this->bodyWidget->setPinState(pinState);
}
this->setLabelColor(this->pinStateChanged ? "#6FA0FF" : "#a6a7aa");
}
};
}

View File

@@ -0,0 +1,30 @@
#target-pin-number,
#target-pin-number {
font-size: 14px;
}
#target-pin-name,
#target-pin-direction {
font-size: 11px;
}
#target-pin-name {
color: #a6a7aa;
}
#target-pin-direction {
color: #8a8a8d;
}
#target-pin-number-top {
}
#target-body {
qproperty-bodyColor: #A6A8AB;
qproperty-disableAlphaLevel: 100;
}
#target-pin-body {
qproperty-bodyColor: #A6A8AB;
qproperty-disableAlphaLevel: 100;
}