ctkAxesWidget.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /// \ingroup Widgets
  23. class CTK_WIDGETS_EXPORT ctkAxesWidget : public QWidget
  24. {
  25. Q_OBJECT
  26. Q_ENUMS(Axis)
  27. Q_PROPERTY(Axis currentAxis READ currentAxis WRITE setCurrentAxis NOTIFY currentAxisChanged)
  28. Q_PROPERTY(bool autoReset READ autoReset WRITE setAutoReset)
  29. Q_PROPERTY(QStringList axesLabels READ axesLabels WRITE setAxesLabels)
  30. public :
  31. enum Axis
  32. {
  33. None=0,
  34. Right,
  35. Left,
  36. Superior,
  37. Inferior,
  38. Anterior,
  39. Posterior,
  40. };
  41. ctkAxesWidget(QWidget *parent = 0);
  42. virtual ~ctkAxesWidget();
  43. ///
  44. /// Current selected axis. None by default.
  45. Axis currentAxis() const;
  46. ///
  47. /// If autoReset is true, anytime the current axis is changed, the current
  48. /// axis is automatically reset to None.
  49. /// False by default.
  50. bool autoReset() const;
  51. Q_SIGNALS:
  52. void currentAxisChanged(ctkAxesWidget::Axis axis);
  53. public slots :
  54. ///
  55. /// Select the current axis and emit the currentAxisChanged signal if it is
  56. /// a new one. Warning, if autoReset is true, the currentAxis will automatically
  57. /// be reset to None.
  58. void setCurrentAxis(Axis axis);
  59. ///
  60. /// Utility slot that set the current axis to none
  61. void setCurrentAxisToNone();
  62. ///
  63. /// Set the autoReset property to None anytime the currentAxis is changed.
  64. void setAutoReset(bool reset);
  65. /// \brief Set the axes \a labels.
  66. ///
  67. /// At least 6 labels are required. If more than 6 labels are given, the
  68. /// additional strings will be ignored.
  69. ///
  70. /// Returns True if the given \a labels are either successfully set or if the
  71. /// current values match the provided ones.
  72. ///
  73. /// \sa axesLabels()
  74. bool setAxesLabels(const QStringList& labels);
  75. /// Get the axes labels
  76. QStringList axesLabels() const;
  77. /// Size hints
  78. virtual QSize minimumSizeHint()const;
  79. virtual QSize sizeHint()const;
  80. virtual bool hasHeightForWidth()const;
  81. virtual int heightForWidth(int width)const;
  82. protected:
  83. void paintEvent(QPaintEvent *);
  84. void mousePressEvent(QMouseEvent *mouseEvent);
  85. void mouseMoveEvent(QMouseEvent *mouseEvent);
  86. void mouseReleaseEvent(QMouseEvent *mouseEvent);
  87. QScopedPointer<ctkAxesWidgetPrivate> d_ptr;
  88. private :
  89. Q_DECLARE_PRIVATE(ctkAxesWidget);
  90. Q_DISABLE_COPY(ctkAxesWidget);
  91. };
  92. Q_DECLARE_METATYPE(ctkAxesWidget::Axis)
  93. #endif