|
|
@@ -50,10 +50,11 @@ public: |
|
|
// 返回图元自身坐标系中的矩形范围,用于绘制和命中测试 |
|
|
// 返回图元自身坐标系中的矩形范围,用于绘制和命中测试 |
|
|
QRectF boundingRect() const override |
|
|
QRectF boundingRect() const override |
|
|
{ |
|
|
{ |
|
|
return {0, |
|
|
|
|
|
0, |
|
|
|
|
|
static_cast<qreal>(control_.bounds.width), |
|
|
|
|
|
static_cast<qreal>(control_.bounds.height)}; |
|
|
|
|
|
|
|
|
if (!control_.binding.has_value()) |
|
|
|
|
|
{ |
|
|
|
|
|
return controlRect(); |
|
|
|
|
|
} |
|
|
|
|
|
return controlRect().united(addressRect()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void paint( |
|
|
void paint( |
|
|
@@ -62,10 +63,22 @@ public: |
|
|
QWidget *) override |
|
|
QWidget *) override |
|
|
{ |
|
|
{ |
|
|
// 留出一个像素边距,避免描边被图元边界裁剪 |
|
|
// 留出一个像素边距,避免描边被图元边界裁剪 |
|
|
const QRectF rect = boundingRect().adjusted(1, 1, -1, -1); |
|
|
|
|
|
|
|
|
const QRectF rect = controlRect().adjusted(1, 1, -1, -1); |
|
|
painter->setRenderHint(QPainter::Antialiasing, true); |
|
|
painter->setRenderHint(QPainter::Antialiasing, true); |
|
|
painter->setPen(QPen(QColor(QStringLiteral("#47545f")), 1)); |
|
|
painter->setPen(QPen(QColor(QStringLiteral("#47545f")), 1)); |
|
|
|
|
|
|
|
|
|
|
|
if (control_.binding.has_value()) |
|
|
|
|
|
{ |
|
|
|
|
|
const QFont original_font = painter->font(); |
|
|
|
|
|
QFont address_font = original_font; |
|
|
|
|
|
address_font.setPixelSize(11); |
|
|
|
|
|
painter->setFont(address_font); |
|
|
|
|
|
painter->setPen(QColor(QStringLiteral("#5f6b73"))); |
|
|
|
|
|
painter->drawText(addressRect(), Qt::AlignCenter, bindingText()); |
|
|
|
|
|
painter->setFont(original_font); |
|
|
|
|
|
painter->setPen(QPen(QColor(QStringLiteral("#47545f")), 1)); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
switch (control_.type) |
|
|
switch (control_.type) |
|
|
{ |
|
|
{ |
|
|
case HmiControlType::Button: |
|
|
case HmiControlType::Button: |
|
|
@@ -136,7 +149,7 @@ public: |
|
|
// 选中框独立于控件类型,提示当前可编辑对象 |
|
|
// 选中框独立于控件类型,提示当前可编辑对象 |
|
|
painter->setBrush(Qt::NoBrush); |
|
|
painter->setBrush(Qt::NoBrush); |
|
|
painter->setPen(QPen(QColor(QStringLiteral("#1677a8")), 2)); |
|
|
painter->setPen(QPen(QColor(QStringLiteral("#1677a8")), 2)); |
|
|
painter->drawRect(boundingRect().adjusted(0, 0, -1, -1)); |
|
|
|
|
|
|
|
|
painter->drawRect(controlRect().adjusted(0, 0, -1, -1)); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@@ -225,6 +238,33 @@ protected: |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private: |
|
|
private: |
|
|
|
|
|
// 控件本体范围保持领域坐标和尺寸语义不变 |
|
|
|
|
|
QRectF controlRect() const |
|
|
|
|
|
{ |
|
|
|
|
|
return {0, |
|
|
|
|
|
0, |
|
|
|
|
|
static_cast<qreal>(control_.bounds.width), |
|
|
|
|
|
static_cast<qreal>(control_.bounds.height)}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 地址作为控件的附属信息显示在本体上方 |
|
|
|
|
|
QRectF addressRect() const |
|
|
|
|
|
{ |
|
|
|
|
|
constexpr qreal address_height = 16.0; |
|
|
|
|
|
constexpr qreal address_spacing = 2.0; |
|
|
|
|
|
return {0, |
|
|
|
|
|
-address_height - address_spacing, |
|
|
|
|
|
static_cast<qreal>(control_.bounds.width), |
|
|
|
|
|
address_height}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
QString bindingText() const |
|
|
|
|
|
{ |
|
|
|
|
|
return control_.binding.has_value() |
|
|
|
|
|
? QString::fromStdString(control_.binding->toString()) |
|
|
|
|
|
: QString{}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 根据控件类型和运行数据组合当前应绘制的文字 |
|
|
// 根据控件类型和运行数据组合当前应绘制的文字 |
|
|
QString textWithValue() const |
|
|
QString textWithValue() const |
|
|
{ |
|
|
{ |
|
|
@@ -433,7 +473,7 @@ void HmiEditorWidget::fitCurrentPage() |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
fitInView( |
|
|
fitInView( |
|
|
scene_->sceneRect().adjusted(-16, -16, 16, 16), |
|
|
|
|
|
|
|
|
scene_->sceneRect().adjusted(-24, -24, 24, 24), |
|
|
Qt::KeepAspectRatio); |
|
|
Qt::KeepAspectRatio); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|