ctkPopupWidgetEventTranslator.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.apache.org/licenses/LICENSE-2.0.txt
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. // Qt includes
  15. #include <QDebug>
  16. #include <QEvent>
  17. // CTK includes
  18. #include "ctkPopupWidget.h"
  19. #include "ctkPopupWidgetEventTranslator.h"
  20. // ----------------------------------------------------------------------------
  21. ctkPopupWidgetEventTranslator::ctkPopupWidgetEventTranslator(QObject *parent)
  22. : pqWidgetEventTranslator(parent),
  23. CurrentObject(0)
  24. {
  25. }
  26. // ----------------------------------------------------------------------------
  27. bool ctkPopupWidgetEventTranslator::translateEvent(QObject *Object,
  28. QEvent *Event,
  29. bool &Error)
  30. {
  31. Q_UNUSED(Error);
  32. ctkPopupWidget* const object = qobject_cast<ctkPopupWidget*>(Object);
  33. if(!object)
  34. {
  35. return false;
  36. }
  37. if(Event->type() == QEvent::ShowToParent )
  38. {
  39. if(this->CurrentObject != Object)
  40. {
  41. if(this->CurrentObject)
  42. {
  43. disconnect(this->CurrentObject, 0, this, 0);
  44. }
  45. this->CurrentObject = Object;
  46. // connect
  47. connect(object, SIGNAL(destroyed(QObject*)),
  48. this, SLOT(onDestroyed()));
  49. connect(object, SIGNAL(popupOpened(const bool&)),
  50. this, SLOT(onPopupOpened(const bool&)));
  51. }
  52. }
  53. return false;
  54. }
  55. // ----------------------------------------------------------------------------
  56. void ctkPopupWidgetEventTranslator::onDestroyed()
  57. {
  58. this->CurrentObject = 0;
  59. }
  60. // ----------------------------------------------------------------------------
  61. void ctkPopupWidgetEventTranslator::onPopupOpened(const bool& open)
  62. {
  63. QString state = open ? "true" : "false";
  64. emit recordEvent(this->CurrentObject, "popupOpen", state);
  65. }