Files
BloomPatched/src/Insight/UserInterfaces/InsightWindow/Widgets/TargetWidgets/DIP/PinWidget.hpp

80 lines
2.3 KiB
C++
Raw Normal View History

2021-04-04 21:04:12 +01:00
#pragma once
#include <QWidget>
#include <cstdint>
#include <QVBoxLayout>
2021-04-04 21:04:12 +01:00
#include <QLabel>
#include <QPainter>
2021-04-04 21:04:12 +01:00
#include "../TargetPinWidget.hpp"
2021-04-04 21:04:12 +01:00
#include "PinBodyWidget.hpp"
#include "src/Targets/TargetVariant.hpp"
namespace Bloom::Widgets::InsightTargetWidgets::Dip
2021-04-04 21:04:12 +01:00
{
enum Position : std::uint8_t
{
TOP,
BOTTOM
};
2021-04-04 21:04:12 +01:00
class PinWidget: public TargetPinWidget
{
Q_OBJECT
2021-04-04 21:04:12 +01:00
public:
static const int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
static const int WIDTH_SPACING = 6;
2021-04-04 21:04:12 +01:00
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) + 40;
2021-04-04 21:04:12 +01:00
PinWidget(
const Targets::TargetPinDescriptor& pinDescriptor,
const Targets::TargetVariant& targetVariant,
InsightWorker& insightWorker,
QWidget* parent
);
2021-04-04 21:04:12 +01:00
2021-06-21 00:14:31 +01:00
void updatePinState(const Targets::TargetPinState& pinState) override {
2021-04-04 21:04:12 +01:00
TargetPinWidget::updatePinState(pinState);
if (pinState.ioDirection.has_value()) {
this->pinDirectionLabel->setText(
pinState.ioDirection.value() == Targets::TargetPinState::IoDirection::INPUT ? "IN" : "OUT"
);
2021-04-04 21:04:12 +01:00
} else {
this->pinDirectionLabel->setText("");
}
if (this->bodyWidget != nullptr) {
this->bodyWidget->setPinState(pinState);
}
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
2021-04-04 21:04:12 +01:00
}
protected:
void paintEvent(QPaintEvent* event) override;
void drawWidget(QPainter& painter);
private:
Position position = Position::TOP;
QVBoxLayout* layout = nullptr;
QLabel* pinNumberLabel = nullptr;
QLabel* pinNameLabel = nullptr;
QLabel* pinDirectionLabel = nullptr;
PinBodyWidget* bodyWidget = nullptr;
void setLabelColor(const QString& hexColor) {
auto style = QString("QLabel { color: " + hexColor + "; }");
if (this->pinNameLabel != nullptr) {
this->pinNameLabel->setStyleSheet(style);
}
}
2021-04-04 21:04:12 +01:00
};
}