|
|
@@ -1,4 +1,5 @@ |
|
|
|
#include "comparator.h" |
|
|
|
#include <QMenu> |
|
|
|
#include <QPainter> |
|
|
|
#include <QStyleOptionGraphicsItem> |
|
|
|
|
|
|
@@ -15,10 +16,15 @@ QRectF Comparator::boundingRect() const |
|
|
|
void Comparator::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) |
|
|
|
{ |
|
|
|
painter->setRenderHint(QPainter::Antialiasing); |
|
|
|
if (state()) { |
|
|
|
painter->setBrush(Qt::green); // 激活状态 |
|
|
|
} else { |
|
|
|
painter->setBrush(Qt::white); // 未激活状态 |
|
|
|
} |
|
|
|
if (type_ == "比较") { |
|
|
|
painter->drawRect(QRectF(-12, -8, 24, 16)); |
|
|
|
painter->setFont(QFont("Arial", 8)); |
|
|
|
painter->drawText(QRectF(-10, -8, 20, 16), Qt::AlignCenter, "CP"); |
|
|
|
painter->drawText(QRectF(-10, -8, 20, 16), Qt::AlignCenter, compare_); |
|
|
|
|
|
|
|
// 锚点 |
|
|
|
painter->setBrush(Qt::darkGray); |
|
|
@@ -75,3 +81,40 @@ void Comparator::setRegisterValue(const QString ®isterId, quint16 value) |
|
|
|
update(); // 触发重绘 |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::addMenuActions(QMenu *menu) |
|
|
|
{ |
|
|
|
menu->addAction("比较"); |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::handleMenuAction(QAction *action) |
|
|
|
{ |
|
|
|
if (action->text() == "复制") { |
|
|
|
emit requestCopy(this); |
|
|
|
} |
|
|
|
if (action->text() == "删除") { |
|
|
|
emit requestDelete(this); |
|
|
|
} |
|
|
|
if (action->text() == "对象"){ |
|
|
|
emit requestBindRegister(this); |
|
|
|
} |
|
|
|
if (action->text() == "比较"){ |
|
|
|
emit requestCompare(this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void Comparator::setCompare(QString compare) |
|
|
|
{ |
|
|
|
compare_ = compare; |
|
|
|
update(); |
|
|
|
} |
|
|
|
|
|
|
|
bool Comparator::state() const |
|
|
|
{ |
|
|
|
if (compare_ == ">") return registerValue_ > registerValue2_; |
|
|
|
if (compare_ == "<") return registerValue_ < registerValue2_; |
|
|
|
if (compare_ == "=") return registerValue_ == registerValue2_; |
|
|
|
if (compare_ == ">=") return registerValue_ >= registerValue2_; |
|
|
|
if (compare_ == "<") return registerValue_ <= registerValue2_; |
|
|
|
return false; |
|
|
|
} |