Manually drawing DIP widget pin labels
This commit is contained in:
@@ -24,12 +24,22 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
static const int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
|
||||
static const int WIDTH_SPACING = 6;
|
||||
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;
|
||||
static constexpr int MINIMUM_WIDTH = PinBodyWidget::WIDTH;
|
||||
static constexpr int WIDTH_SPACING = 4;
|
||||
static constexpr int PIN_LABEL_SPACING = 2;
|
||||
static constexpr int PIN_LABEL_LONG_LINE_LENGTH = 25;
|
||||
static constexpr int PIN_LABEL_SHORT_LINE_LENGTH = 5;
|
||||
static constexpr int MAXIMUM_LABEL_COUNT = 3;
|
||||
static constexpr int LABEL_HEIGHT = 20;
|
||||
static constexpr int MAXIMUM_PIN_NUMBER_LABEL_WIDTH = 26;
|
||||
static constexpr int MAXIMUM_PIN_DIRECTION_LABEL_WIDTH = 24;
|
||||
static constexpr int MAXIMUM_LABEL_WIDTH = 32;
|
||||
static constexpr int MAXIMUM_LABEL_HEIGHT = 20;
|
||||
static constexpr int MAXIMUM_HEIGHT = PinBodyWidget::HEIGHT + PinWidget::PIN_LABEL_SPACING
|
||||
+ PinWidget::LABEL_HEIGHT;
|
||||
|
||||
Position position = Position::TOP;
|
||||
QString pinNameLabelText;
|
||||
|
||||
PinWidget(
|
||||
const Targets::TargetPinDescriptor& pinDescriptor,
|
||||
@@ -41,39 +51,14 @@ namespace Bloom::Widgets::InsightTargetWidgets::Dip
|
||||
void updatePinState(const Targets::TargetPinState& pinState) override {
|
||||
TargetPinWidget::updatePinState(pinState);
|
||||
|
||||
if (pinState.ioDirection.has_value()) {
|
||||
this->pinDirectionLabel->setText(
|
||||
pinState.ioDirection.value() == Targets::TargetPinState::IoDirection::INPUT ? "IN" : "OUT"
|
||||
);
|
||||
|
||||
} else {
|
||||
this->pinDirectionLabel->setText("");
|
||||
}
|
||||
|
||||
if (this->bodyWidget != nullptr) {
|
||||
this->bodyWidget->setPinState(pinState);
|
||||
}
|
||||
|
||||
this->setLabelColor(this->pinStateChanged ? "#4d7bba" : "#a6a7aa");
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user