|
|
@@ -185,38 +185,34 @@ void HMIDocument::showContextMenu(QPoint globalPos) |
|
|
|
} |
|
|
|
else |
|
|
|
{ |
|
|
|
// 选中图形:显示完整菜单 |
|
|
|
// 选中图形:显示基础菜单 |
|
|
|
QAction *propAction = menu.addAction("属性"); |
|
|
|
QAction *copyAction = menu.addAction("复制"); |
|
|
|
QAction *pasteAction = menu.addAction("粘贴"); |
|
|
|
QAction *deleteAction = menu.addAction("删除"); |
|
|
|
QAction *onAction = menu.addAction("置为ON"); |
|
|
|
QAction *offAction = menu.addAction("置为OFF"); |
|
|
|
|
|
|
|
pasteAction->setEnabled(!m_copiedItemsData.isEmpty()); |
|
|
|
|
|
|
|
connect(propAction, &QAction::triggered, this, &HMIDocument::showItemProperties); |
|
|
|
connect(copyAction, &QAction::triggered, this, &HMIDocument::copySelectedItems); |
|
|
|
connect(pasteAction, &QAction::triggered, this, &HMIDocument::pasteItems); |
|
|
|
connect(deleteAction, &QAction::triggered, this, &HMIDocument::deleteSelectedItems); |
|
|
|
|
|
|
|
// ON/OFF动作(针对指示灯和按钮) |
|
|
|
connect(onAction, &QAction::triggered, [=]() { |
|
|
|
if (auto ellipse = dynamic_cast<ResizableEllipse*>(clickedItem)) { |
|
|
|
ellipse->setBrush(ellipse->onColor()); |
|
|
|
} else if (auto rect = dynamic_cast<ResizableRectangle*>(clickedItem)) { |
|
|
|
rect->setBrush(rect->pressedColor()); |
|
|
|
} |
|
|
|
}); |
|
|
|
connect(offAction, &QAction::triggered, [=]() { |
|
|
|
if (auto ellipse = dynamic_cast<ResizableEllipse*>(clickedItem)) { |
|
|
|
ellipse->setBrush(ellipse->offColor()); |
|
|
|
} else if (auto rect = dynamic_cast<ResizableRectangle*>(clickedItem)) { |
|
|
|
rect->setBrush(rect->releasedColor()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
// 仅对按钮(矩形)显示ON/OFF选项,指示灯(椭圆)不显示 |
|
|
|
if (dynamic_cast<ResizableRectangle*>(clickedItem)) { |
|
|
|
QAction *onAction = menu.addAction("置为ON"); |
|
|
|
QAction *offAction = menu.addAction("置为OFF"); |
|
|
|
|
|
|
|
connect(onAction, &QAction::triggered, [=]() { |
|
|
|
if (auto rect = dynamic_cast<ResizableRectangle*>(clickedItem)) { |
|
|
|
rect->setBrush(rect->pressedColor()); |
|
|
|
} |
|
|
|
}); |
|
|
|
connect(offAction, &QAction::triggered, [=]() { |
|
|
|
if (auto rect = dynamic_cast<ResizableRectangle*>(clickedItem)) { |
|
|
|
rect->setBrush(rect->releasedColor()); |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
menu.exec(globalPos + QPoint(10, 10)); |
|
|
|
} |
|
|
|
|
|
|
@@ -286,7 +282,7 @@ void HMIDocument::showItemProperties() |
|
|
|
|
|
|
|
// 线圈地址输入 - 使用SpinBox替代LineEdit |
|
|
|
QSpinBox *coilAddrSpin = new QSpinBox(); |
|
|
|
coilAddrSpin->setRange(0, 65535); // 设置PLC线圈地址常见范围 |
|
|
|
coilAddrSpin->setRange(0, 4000); // 设置PLC线圈地址常见范围 |
|
|
|
// 尝试从名称解析现有地址(如果之前用数字作为名称) |
|
|
|
bool isNumber; |
|
|
|
int addr = namedItem->name().toInt(&isNumber); |
|
|
|