ctkPopupWidget.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. #ifndef __ctkPopupWidget_h
  15. #define __ctkPopupWidget_h
  16. // CTK includes
  17. #include "ctkBasePopupWidget.h"
  18. class ctkPopupWidgetPrivate;
  19. /// \ingroup Widgets
  20. /// Description:
  21. class CTK_WIDGETS_EXPORT ctkPopupWidget : public ctkBasePopupWidget
  22. {
  23. Q_OBJECT
  24. /// Control whether the popup listens to the application and baseWidget
  25. /// events and decides if it needs to be permanently or temporarily hidden.
  26. /// You might want to setActive(false) when embedding the popup
  27. /// into a static layout intead of having it top-level (no parent).
  28. /// Consider also removing its windowFlags (Qt::ToolTip |
  29. /// Qt::FramelessWindowHint) and removing the baseWidget.
  30. /// True by default
  31. Q_PROPERTY( bool active READ isActive WRITE setActive)
  32. /// Control wether the popup automatically opens when the mouse
  33. /// enter the widget. True by default
  34. Q_PROPERTY( bool autoShow READ autoShow WRITE setAutoShow)
  35. /// Time in ms to wait before opening the popup if autoShow is set.
  36. /// 20ms by default
  37. Q_PROPERTY( int showDelay READ showDelay WRITE setShowDelay)
  38. /// Control wether the popup automatically closes when the mouse
  39. /// leaves the widget. True by default
  40. Q_PROPERTY( bool autoHide READ autoHide WRITE setAutoHide)
  41. /// Time in ms to wait before closing the popup if autoHide is set.
  42. /// 200ms by default
  43. Q_PROPERTY( int hideDelay READ hideDelay WRITE setHideDelay)
  44. public:
  45. typedef ctkBasePopupWidget Superclass;
  46. explicit ctkPopupWidget(QWidget* parent = 0);
  47. virtual ~ctkPopupWidget();
  48. bool isActive()const;
  49. void setActive(bool);
  50. bool autoShow()const;
  51. /// Calling setAutoShow automatically updates opens the popup if the cursor
  52. /// is above the popup or the base widget.
  53. void setAutoShow(bool);
  54. int showDelay()const;
  55. void setShowDelay(int delay);
  56. bool autoHide()const;
  57. /// Don't automatically close the popup when leaving the widget.
  58. /// Calling setAutoHide automatically updates the state close the popup
  59. /// if the mouse is not over the popup nor the base widget.
  60. void setAutoHide(bool autoHide);
  61. int hideDelay()const;
  62. void setHideDelay(int delay);
  63. public Q_SLOTS:
  64. /// Convenient function that calls setAutoHide(!pin) and opens the popup
  65. /// if pin is true regardless of the value of \a AutoShow.
  66. /// It is typically connected with a checkable button to anchor the popup.
  67. void pinPopup(bool pin);
  68. public:
  69. /// Reimplemented for internal reasons
  70. virtual void hidePopup();
  71. protected:
  72. virtual void leaveEvent(QEvent* event);
  73. virtual void enterEvent(QEvent* event);
  74. virtual bool eventFilter(QObject* obj, QEvent* event);
  75. /// Widget the popup is attached to. It opens right under \a baseWidget
  76. /// and if the ctkPopupWidget sizepolicy contains the growFlag/shrinkFlag,
  77. /// it tries to resize itself to fit the same width of \a baseWidget.
  78. virtual void setBaseWidget(QWidget* baseWidget);
  79. protected Q_SLOTS:
  80. void updatePopup();
  81. virtual void onEffectFinished();
  82. private:
  83. Q_DECLARE_PRIVATE(ctkPopupWidget);
  84. Q_DISABLE_COPY(ctkPopupWidget);
  85. };
  86. #endif