You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 regels
1.4 KiB

  1. #include "button.h"
  2. #include <QPainter>
  3. #include <QStyleOptionGraphicsItem>
  4. #include <QMenu>
  5. Button::Button(const QString &type) : Item(type)
  6. {
  7. }
  8. QRectF Button::boundingRect() const
  9. {
  10. return QRectF(0, 0, 50, 50);
  11. }
  12. void Button::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *)
  13. {
  14. painter->setRenderHint(QPainter::Antialiasing);
  15. if (type_ == "按钮") {
  16. painter->drawRect(0,0,50,50);
  17. }
  18. if (option->state & QStyle::State_Selected) {
  19. QPen pen(Qt::DashLine);
  20. pen.setColor(Qt::blue);
  21. pen.setWidth(2);
  22. painter->setPen(pen);
  23. painter->setBrush(Qt::NoBrush);
  24. painter->drawRect(boundingRect());
  25. }
  26. }
  27. void Button::addMenuActions(QMenu *menu)
  28. {
  29. menu->addAction("置ON");
  30. menu->addAction("置OFF");
  31. }
  32. void Button::handleMenuAction(QAction *action)
  33. {
  34. if (action->text() == "复制") {
  35. emit requestCopy(this);
  36. }
  37. if (action->text() == "删除") {
  38. emit requestDelete(this);
  39. }
  40. if (action->text() == "对象"){
  41. emit requestBindRegister(this);
  42. }
  43. if (action->text() == "重置"){
  44. emit requestReset(this);
  45. }
  46. if (action->text() == "置ON"){
  47. emit requestSetON(this, true);
  48. }
  49. if (action->text() == "置OFF"){
  50. emit requestSetON(this, false);
  51. }
  52. }