ctkCoordinatesWidget.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 __ctkCoordinatesWidget_h
  15. #define __ctkCoordinatesWidget_h
  16. // Qt includes
  17. #include <QWidget>
  18. // CTK includes
  19. #include "ctkDoubleSpinBox.h"
  20. #include "ctkWidgetsExport.h"
  21. class ctkCoordinatesWidgetPrivate;
  22. /// \ingroup Widgets
  23. ///
  24. /// ctkCoordinatesWidget is a simple container of dimension coordinates.
  25. /// For each coordinate a double spinbox is associated, everytime a value is
  26. /// modified, the signal valueChanged is fired.
  27. /// TODO: use pimpl
  28. class CTK_WIDGETS_EXPORT ctkCoordinatesWidget : public QWidget
  29. {
  30. Q_OBJECT
  31. Q_PROPERTY(int dimension READ dimension WRITE setDimension)
  32. /// This property controls whether the coordinates must be normalized.
  33. /// If true, the norm of the coordinates is enforced to be 1.
  34. /// False by default.
  35. Q_PROPERTY(bool normalized READ isNormalized WRITE setNormalized)
  36. /// This property controls how many decimals should be displayed by the
  37. /// spinboxes. This number might not be used depending on decimalsOption.
  38. /// In general, the coordinatesWidget tries to use the same number of
  39. /// decimals for all the spinboxes except if numbers require more decimals.
  40. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  41. /// This property provides more controls over the decimals.
  42. /// \sa ctkDoubleSpinBox::DecimalsOptions, decimals
  43. Q_PROPERTY(ctkDoubleSpinBox::DecimalsOptions decimalsOption READ decimalsOption WRITE setDecimalsOption)
  44. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep STORED false)
  45. /// This property controls the minimum value of the spinboxes.
  46. /// No limit (-max double) by default.
  47. /// \sa minimum(), setMinimum(), maximum, sizeHintPolicy
  48. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  49. /// This property the maximum value of the spinboxes.
  50. /// No limit (max double) by default.
  51. /// \sa maximum(), setMaximum(), minimum, sizeHintPolicy
  52. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  53. Q_PROPERTY(QString coordinates READ coordinatesAsString WRITE setCoordinatesAsString)
  54. /// This property controls the size hint of the spinboxes.
  55. /// ctkDoubleSpinBox::SizeHintByValue by default
  56. /// \sa ctkDoubleSpinBox::SizeHintPolicy
  57. Q_PROPERTY(ctkDoubleSpinBox::SizeHintPolicy sizeHintPolicy READ sizeHintPolicy WRITE setSizeHintPolicy)
  58. public:
  59. explicit ctkCoordinatesWidget(QWidget* parent = 0);
  60. virtual ~ctkCoordinatesWidget();
  61. /// Set/Get the dimension of the point
  62. /// The default dimension is 3
  63. void setDimension(int dim);
  64. int dimension() const;
  65. /// Get the number of decimals of each coordinate spin box
  66. /// The default number of decimals is 3.
  67. int decimals() const;
  68. /// Return the decimalsOption property value
  69. /// \sa decimalsOption
  70. ctkDoubleSpinBox::DecimalsOptions decimalsOption()const;
  71. /// Set the decimalsOption property value.
  72. /// \sa decimalsOption
  73. void setDecimalsOption(ctkDoubleSpinBox::DecimalsOptions option);
  74. /// Set/Get the single step of each coordinate spin box
  75. /// The default single step is 1.
  76. void setSingleStep(double step);
  77. double singleStep() const;
  78. /// Set/Get the minimum value of each coordinate spin box
  79. /// The default minimum is -100000.
  80. void setMinimum(double minimum);
  81. double minimum() const;
  82. /// Set/Get the maximum value of each coordinate spin box
  83. /// The default maximum is 100000.
  84. void setMaximum(double minimum);
  85. double maximum() const;
  86. /// Set the minimum and maximum of each coordinate spinbox at once.
  87. /// \sa minimum, maximum
  88. void setRange(double minimum, double maximum);
  89. /// Change the normalized property. If \a normalize is true, it normalizes
  90. /// the current coordinates, the range of possible values is reset to [-1, 1].
  91. /// \sa isNormalized
  92. void setNormalized(bool normalize);
  93. bool isNormalized()const;
  94. /// Return the norm of the coordinates.
  95. double norm()const;
  96. /// Return the squared norm of the coordinates.
  97. double squaredNorm()const;
  98. /// Set/Get the coordinates. Use commas to separate elements, spaces are
  99. /// allowed: e.g. "0,0.0, 0."
  100. void setCoordinatesAsString(QString pos);
  101. QString coordinatesAsString()const;
  102. /// Set/Get the coordinates
  103. /// The default values are 0.
  104. void setCoordinates(double* pos);
  105. double const * coordinates()const;
  106. /// Convenient function that sets up to 4 elements of the coordinates.
  107. void setCoordinates(double x, double y = 0., double z = 0., double w = 0.);
  108. /// Set the sizeHintPolicy property value.
  109. /// \sa sizeHintPolicy
  110. void setSizeHintPolicy(ctkDoubleSpinBox::SizeHintPolicy newSizeHintPolicy);
  111. /// Return the sizeHintPolicy property value.
  112. /// \sa sizeHintPolicy
  113. ctkDoubleSpinBox::SizeHintPolicy sizeHintPolicy()const;
  114. /// Set/Get the value proxy of the spinboxes used to display the coordinates.
  115. /// \sa setValueProxy(), valueProxy()
  116. void setValueProxy(ctkValueProxy* proxy);
  117. ctkValueProxy* valueProxy() const;
  118. /// Return the spinbox identitfied by id
  119. ctkDoubleSpinBox* spinBox(int id);
  120. public Q_SLOTS:
  121. void normalize();
  122. /// Set the number of decimals of each coordinate spin box.
  123. void setDecimals(int decimals);
  124. Q_SIGNALS:
  125. ///
  126. /// valueChanged is fired anytime a coordinate is modified, the returned
  127. /// value is the point coordinates
  128. /// TODO: Don't fire the signal if the new values are not changed
  129. void coordinatesChanged(double* pos);
  130. protected Q_SLOTS:
  131. void updateCoordinates();
  132. void updateCoordinate(double coordinate);
  133. protected:
  134. QScopedPointer<ctkCoordinatesWidgetPrivate> d_ptr;
  135. private:
  136. Q_DECLARE_PRIVATE(ctkCoordinatesWidget);
  137. Q_DISABLE_COPY(ctkCoordinatesWidget);
  138. };
  139. #endif