ctkToolTipTrapper.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. /*=========================================================================
  15. Program: ParaView
  16. Module: pqToolTipTrapper.h
  17. Copyright (c) 2005-2008 Sandia Corporation, Kitware Inc.
  18. All rights reserved.
  19. ParaView is a free software; you can redistribute it and/or modify it
  20. under the terms of the ParaView license version 1.2.
  21. See http://www.paraview.org/paraview/project/license.html for the full ParaView license.
  22. A copy of this license can be obtained by contacting
  23. Kitware Inc.
  24. 28 Corporate Drive
  25. Clifton Park, NY 12065
  26. USA
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
  31. CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  32. EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  33. PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  34. PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  35. LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  36. NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  37. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. =========================================================================*/
  39. #ifndef __ctkToolTipTrapper_h
  40. #define __ctkToolTipTrapper_h
  41. // Qt includes
  42. #include <QObject>
  43. // CTK includes
  44. #include "ctkWidgetsExport.h"
  45. class ctkToolTipTrapperPrivate;
  46. /// \ingroup Widgets
  47. /// Filters tooltips, to prevent tooltips from appearing or to word wrap
  48. /// tooltips.
  49. /// If toolTipsTrapped or toolTipsWordWrapped is true, installs an event filter to
  50. /// trap or wrap tooltips.
  51. /// If toolTipsTrapped and toolTipsWordWrapped are false, does not install the event
  52. /// filter.
  53. /// Tooltips are trapped and not word wrapped by default.
  54. class CTK_WIDGETS_EXPORT ctkToolTipTrapper : public QObject
  55. {
  56. Q_OBJECT
  57. Q_PROPERTY( bool toolTipsTrapped READ toolTipsTrapped WRITE setToolTipsTrapped)
  58. Q_PROPERTY( bool toolTipsWordWrapped READ toolTipsWordWrapped WRITE setToolTipsWordWrapped)
  59. public:
  60. typedef QObject Superclass;
  61. /// Constructs a ToolTip trapper which is a child of objectParent
  62. explicit ctkToolTipTrapper(QObject* objectParent = 0);
  63. explicit ctkToolTipTrapper(bool toolTipsTrapped,
  64. bool toolTipsWordWordWrapped,
  65. QObject* objectParent = 0);
  66. virtual ~ctkToolTipTrapper();
  67. /// Returns true if the tooltips are trapped to prevent them from appearing.
  68. bool toolTipsTrapped()const;
  69. /// Returns true if the tooltips are word wrapped.
  70. bool toolTipsWordWrapped()const;
  71. /// Automatically called when the tooltips are trapped or word wrapped.
  72. /// You shouldn't have to call it manually.
  73. bool eventFilter(QObject* watched, QEvent* event);
  74. public Q_SLOTS:
  75. /// If true, installs the eventFilter on the application if it isn't already
  76. /// installed. Otherwise, removes the eventFilter if tooltips are neither
  77. /// trapped nor word wrapped.
  78. void setToolTipsTrapped(bool toolTipsTrapped);
  79. void setToolTipsWordWrapped(bool toolTipsWordWrapped);
  80. protected:
  81. QScopedPointer<ctkToolTipTrapperPrivate> d_ptr;
  82. private:
  83. Q_DECLARE_PRIVATE(ctkToolTipTrapper);
  84. Q_DISABLE_COPY(ctkToolTipTrapper);
  85. };
  86. #endif