ctkAxesWidget.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 __ctkAxesWidget_h
  15. #define __ctkAxesWidget_h
  16. // Qt includes
  17. #include <QMetaType>
  18. #include <QWidget>
  19. // CTK includes
  20. #include "ctkWidgetsExport.h"
  21. class ctkAxesWidgetPrivate;
  22. class CTK_WIDGETS_EXPORT ctkAxesWidget : public QWidget
  23. {
  24. Q_OBJECT
  25. Q_ENUMS(Axis)
  26. Q_PROPERTY(Axis currentAxis READ currentAxis WRITE setCurrentAxis NOTIFY currentAxisChanged)
  27. Q_PROPERTY(bool autoReset READ autoReset WRITE setAutoReset)
  28. public :
  29. enum Axis
  30. {
  31. None=0,
  32. Right,
  33. Left,
  34. Superior,
  35. Inferior,
  36. Anterior,
  37. Posterior,
  38. };
  39. ctkAxesWidget(QWidget *parent = 0);
  40. virtual ~ctkAxesWidget();
  41. ///
  42. /// Current selected axis. None by default.
  43. Axis currentAxis() const;
  44. ///
  45. /// If autoReset is true, anytime the current axis is changed, the current
  46. /// axis is automatically reset to None.
  47. /// False by default.
  48. bool autoReset() const;
  49. Q_SIGNALS:
  50. void currentAxisChanged(ctkAxesWidget::Axis axis);
  51. public slots :
  52. ///
  53. /// Select the current axis and emit the currentAxisChanged signal if it is
  54. /// a new one. Warning, if autoReset is true, the currentAxis will automatically
  55. /// be reset to None.
  56. void setCurrentAxis(Axis axis);
  57. ///
  58. /// Utility slot that set the current axis to none
  59. void setCurrentAxisToNone();
  60. ///
  61. /// Set the autoReset property to None anytime the currentAxis is changed.
  62. void setAutoReset(bool reset);
  63. /// Size hints
  64. virtual QSize minimumSizeHint()const;
  65. virtual QSize sizeHint()const;
  66. virtual bool hasHeightForWidth()const;
  67. virtual int heightForWidth(int width)const;
  68. protected:
  69. void paintEvent(QPaintEvent *);
  70. void mousePressEvent(QMouseEvent *mouseEvent);
  71. void mouseMoveEvent(QMouseEvent *mouseEvent);
  72. void mouseReleaseEvent(QMouseEvent *mouseEvent);
  73. QScopedPointer<ctkAxesWidgetPrivate> d_ptr;
  74. private :
  75. Q_DECLARE_PRIVATE(ctkAxesWidget);
  76. Q_DISABLE_COPY(ctkAxesWidget);
  77. };
  78. Q_DECLARE_METATYPE(ctkAxesWidget::Axis)
  79. #endif