ctkVTKMagnifyView.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 __ctkVTKMagnifyView_h
  15. #define __ctkVTKMagnifyView_h
  16. // QT includes
  17. #include <QList>
  18. // CTK includes
  19. #include "ctkCrosshairLabel.h"
  20. #include "ctkVisualizationVTKWidgetsExport.h"
  21. // VTK includes
  22. #if CTK_USE_QVTKOPENGLWIDGET
  23. class QVTKOpenGLWidget;
  24. #else
  25. class QVTKWidget;
  26. #endif
  27. class ctkVTKMagnifyViewPrivate;
  28. /// \ingroup Visualization_VTK_Widgets
  29. /// Gives a magnified view of a QVTKWidget around the mouse position, with
  30. /// overlaid crosshair (ex. cross-hair). You must specify the QVTKWidget(s) to be
  31. /// observed.
  32. /// \sa ctkCrosshairLabel
  33. class CTK_VISUALIZATION_VTK_WIDGETS_EXPORT ctkVTKMagnifyView
  34. : public ctkCrosshairLabel
  35. {
  36. Q_OBJECT
  37. Q_PROPERTY(double magnification READ magnification WRITE setMagnification)
  38. Q_PROPERTY(bool observeRenderWindowEvents
  39. READ observeRenderWindowEvents WRITE setObserveRenderWindowEvents)
  40. Q_PROPERTY(int updateInterval READ updateInterval WRITE setUpdateInterval)
  41. public:
  42. /// Constructors
  43. typedef ctkCrosshairLabel Superclass;
  44. explicit ctkVTKMagnifyView(QWidget* parent = 0);
  45. virtual ~ctkVTKMagnifyView();
  46. /// Set/get the magnification (zoom). Looks best when the magnification and
  47. /// the widget size are both either even or odd. Default 1.0.
  48. double magnification() const;
  49. void setMagnification(double newMagnification);
  50. /// Set/get whether or not to observe EndEvents emitted by the observed
  51. /// QVTKWidgets' vtkRenderWindows after they have rendered. This triggers
  52. /// updates to the magnify widget whenever the vtkRenderWindow does a render,
  53. /// even if the mouse position does not move. Default true.
  54. bool observeRenderWindowEvents() const;
  55. void setObserveRenderWindowEvents(bool newObserve);
  56. /// Set/get a fixed interval, in milliseconds, at which this widget will update
  57. /// itself. Default 20. Specify an update interval of 0 to handle all events as
  58. /// they occur.
  59. int updateInterval() const;
  60. void setUpdateInterval(int newInterval);
  61. /// Add a QVTKWidget to observe mouse events on. You can call this function
  62. /// multiple times to observe multiple QVTKWidgets.
  63. /// \sa observe
  64. #if CTK_USE_QVTKOPENGLWIDGET
  65. void observe(QVTKOpenGLWidget * widget);
  66. #else
  67. void observe(QVTKWidget * widget);
  68. #endif
  69. /// Add multiple QVTKWidgets at once to observe mouse events on. You can
  70. /// call this function multiple times to observe multiple QVTKWidgets.
  71. /// \sa observe
  72. #if CTK_USE_QVTKOPENGLWIDGET
  73. void observe(QList<QVTKOpenGLWidget *> widgets);
  74. #else
  75. void observe(QList<QVTKWidget *> widgets);
  76. #endif
  77. /// Remove a QVTKWidget to observe mouse events on. You can call this
  78. /// function multiple times to remove multiple QVTKWidgets.
  79. /// \sa remove
  80. #if CTK_USE_QVTKOPENGLWIDGET
  81. void remove(QVTKOpenGLWidget * widget);
  82. #else
  83. void remove(QVTKWidget * widget);
  84. #endif
  85. /// Remove multiple QVTKWidgets at once to observe mouse events on. You can
  86. /// call this function multiple times to remove multiple QVTKWidgets.
  87. /// \sa unobserve
  88. #if CTK_USE_QVTKOPENGLWIDGET
  89. void remove(QList<QVTKOpenGLWidget *> widgets);
  90. #else
  91. void remove(QList<QVTKWidget *> widgets);
  92. #endif
  93. /// Returns whether a QVTKWidget is observed
  94. #if CTK_USE_QVTKOPENGLWIDGET
  95. bool isObserved(QVTKOpenGLWidget * widget) const;
  96. #else
  97. bool isObserved(QVTKWidget * widget) const;
  98. #endif
  99. /// Returns the number of observed QVTKWidgets
  100. int numberObserved()const;
  101. /// Returns true if the mouse cursor is over an observed widget,
  102. /// false otherwise.
  103. bool hasCursorInObservedWidget()const;
  104. protected:
  105. QScopedPointer<ctkVTKMagnifyViewPrivate> d_ptr;
  106. /// Handles mouse events on the observed QVTKWidgets (specifically,
  107. /// enterEvent, leaveEvent and mouseMoveEvent).
  108. virtual bool eventFilter(QObject *obj, QEvent *event);
  109. Q_SIGNALS:
  110. #if CTK_USE_QVTKOPENGLWIDGET
  111. void enteredObservedWidget(QVTKOpenGLWidget * widget);
  112. void leftObservedWidget(QVTKOpenGLWidget * widget);
  113. #else
  114. void enteredObservedWidget(QVTKWidget * widget);
  115. void leftObservedWidget(QVTKWidget * widget);
  116. #endif
  117. private:
  118. Q_DECLARE_PRIVATE(ctkVTKMagnifyView)
  119. Q_DISABLE_COPY(ctkVTKMagnifyView)
  120. };
  121. #endif