DebugAttachmentButton.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "DebugAttachmentButton.hxx"
  9. #include <Source/LUA/moc_DebugAttachmentButton.cpp>
  10. #include <Source/LUA/LUAContextControlMessages.h>
  11. #include <Source/LUA/LUAEditorContextMessages.h>
  12. #include <QPainter>
  13. #include <QStyleOptionButton>
  14. namespace LUAEditor
  15. {
  16. DebugAttachmentButton::DebugAttachmentButton(QWidget* pParent)
  17. : QPushButton(pParent)
  18. {
  19. QSizePolicy sizePolicy1(QSizePolicy::Preferred, QSizePolicy::Preferred);
  20. sizePolicy1.setHorizontalStretch(0);
  21. sizePolicy1.setVerticalStretch(0);
  22. sizePolicy1.setHeightForWidth(sizePolicy().hasHeightForWidth());
  23. setSizePolicy(sizePolicy1);
  24. // default state to disconnected and unattached
  25. // change state on later message updates
  26. OnDebuggerDetached();
  27. connect(this, SIGNAL(clicked()), this, SLOT(OnClicked()));
  28. Context_ControlManagement::Handler::BusConnect();
  29. }
  30. DebugAttachmentButton::~DebugAttachmentButton()
  31. {
  32. Context_ControlManagement::Handler::BusDisconnect();
  33. }
  34. void DebugAttachmentButton::paintEvent(QPaintEvent* /* event */)
  35. {
  36. QPainter painter(this);
  37. QStyleOptionButton option;
  38. option.initFrom(this);
  39. option.features = QStyleOptionButton::None;
  40. option.text = text();
  41. option.icon = icon();
  42. option.iconSize = iconSize();
  43. style()->drawControl(QStyle::CE_PushButton, &option, &painter, this);
  44. }
  45. void DebugAttachmentButton::OnClicked()
  46. {
  47. switch (m_State)
  48. {
  49. case DAS_ATTACHED:
  50. Context_DebuggerManagement::Bus::Broadcast(&Context_DebuggerManagement::Bus::Events::RequestDetachDebugger);
  51. break;
  52. case DAS_UNATTACHED:
  53. case DAS_REFUSED:
  54. {
  55. Context_DebuggerManagement::Bus::Broadcast(&Context_DebuggerManagement::Bus::Events::RequestAttachDebugger);
  56. }
  57. break;
  58. }
  59. }
  60. void DebugAttachmentButton::OnDebuggerAttached()
  61. {
  62. this->setToolTip(tr("Click to detach from debugging"));
  63. UpdateStatus(DAS_ATTACHED);
  64. }
  65. void DebugAttachmentButton::OnDebuggerRefused()
  66. {
  67. this->setToolTip(tr("Target refused debug request. Click here to retry attaching"));
  68. UpdateStatus(DAS_REFUSED);
  69. }
  70. void DebugAttachmentButton::OnDebuggerDetached()
  71. {
  72. this->setToolTip(tr("Click to attach for debugging"));
  73. UpdateStatus(DAS_UNATTACHED);
  74. }
  75. void DebugAttachmentButton::UpdateStatus(DebugAttachmentState newState)
  76. {
  77. m_State = newState;
  78. switch (newState)
  79. {
  80. case DAS_ATTACHED:
  81. this->setIcon(QIcon(":/debug/debugger_connected"));
  82. this->setText("Debugging: ON");
  83. break;
  84. case DAS_UNATTACHED:
  85. this->setIcon(QIcon(":/debug/debugger_disconnected"));
  86. this->setText("Debugging: OFF");
  87. break;
  88. case DAS_REFUSED:
  89. this->setIcon(QIcon(":/general/target_none"));
  90. this->setText("Debugging: Refused");
  91. break;
  92. }
  93. }
  94. //-----------------------------------------------------------------------
  95. DebugAttachmentButtonAction::DebugAttachmentButtonAction(QObject* pParent)
  96. : QWidgetAction(pParent)
  97. {
  98. }
  99. QWidget* DebugAttachmentButtonAction::createWidget(QWidget* pParent)
  100. {
  101. return aznew DebugAttachmentButton(pParent);
  102. }
  103. }