ctkCoordinatesWidget.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 "ctkWidgetsExport.h"
  20. /// \ingroup Widgets
  21. ///
  22. /// ctkCoordinatesWidget is a simple container of dimension coordinates.
  23. /// For each coordinate a double spinbox is associated, everytime a value is
  24. /// modified, the signal valueChanged is fired.
  25. /// TODO: use pimpl
  26. class CTK_WIDGETS_EXPORT ctkCoordinatesWidget : public QWidget
  27. {
  28. Q_OBJECT
  29. Q_PROPERTY(int dimension READ dimension WRITE setDimension)
  30. /// This property controls whether the coordinates must be normalized.
  31. /// If true, the norm of the coordinates is enforced to be 1.
  32. /// False by default.
  33. Q_PROPERTY(bool normalized READ isNormalized WRITE setNormalized)
  34. Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
  35. Q_PROPERTY(double singleStep READ singleStep WRITE setSingleStep STORED false)
  36. Q_PROPERTY(double minimum READ minimum WRITE setMinimum)
  37. Q_PROPERTY(double maximum READ maximum WRITE setMaximum)
  38. Q_PROPERTY(QString coordinates READ coordinatesAsString WRITE setCoordinatesAsString)
  39. public:
  40. explicit ctkCoordinatesWidget(QWidget* parent = 0);
  41. virtual ~ctkCoordinatesWidget();
  42. /// Set/Get the dimension of the point
  43. /// The default dimension is 3
  44. void setDimension(int dim);
  45. int dimension() const;
  46. /// Set/Get the number of decimals of each coordinate QDoubleSpinBoxes
  47. /// The default number of decimals is 3.
  48. void setDecimals(int decimals);
  49. int decimals() const;
  50. /// Set/Get the single step of each coordinate QDoubleSpinBoxes
  51. /// The default single step is 1.
  52. void setSingleStep(double step);
  53. double singleStep() const;
  54. /// Set/Get the minimum value of each coordinate QDoubleSpinBoxes
  55. /// The default minimum is -100000.
  56. void setMinimum(double minimum);
  57. double minimum() const;
  58. /// Set/Get the maximum value of each coordinate QDoubleSpinBoxes
  59. /// The default maximum is 100000.
  60. void setMaximum(double minimum);
  61. double maximum() const;
  62. /// Change the normalized property. If \a normalize is true, it normalizes
  63. /// the current coordinates, the range of possible values is reset to [-1, 1].
  64. /// \sa isNormalized
  65. void setNormalized(bool normalize);
  66. bool isNormalized()const;
  67. /// Return the norm of the coordinates.
  68. double norm()const;
  69. /// Set/Get the coordinates. Use commas to separate elements, spaces are
  70. /// allowed: e.g. "0,0.0, 0."
  71. void setCoordinatesAsString(QString pos);
  72. QString coordinatesAsString()const;
  73. /// Set/Get the coordinates
  74. /// The default values are 0.
  75. void setCoordinates(double* pos);
  76. double const * coordinates()const;
  77. /// Convenient function that sets up to 4 elements of the coordinates.
  78. void setCoordinates(double x, double y = 0., double z = 0., double w = 0.);
  79. public Q_SLOTS:
  80. void normalize();
  81. Q_SIGNALS:
  82. ///
  83. /// valueChanged is fired anytime a coordinate is modified, the returned
  84. /// value is the point coordinates
  85. /// TODO: Don't fire the signal if the new values are not changed
  86. void coordinatesChanged(double* pos);
  87. protected Q_SLOTS:
  88. void updateCoordinate(double);
  89. void updateCoordinates();
  90. protected:
  91. void addSpinBox();
  92. /// Normalize coordinates vector and return the previous norm.
  93. static double normalize(double* coordinates, int dimension);
  94. /// Compute the norm of a coordinates \a dimension vector
  95. static double norm(double* coordinates, int dimension);
  96. int Decimals;
  97. double SingleStep;
  98. double Minimum;
  99. double Maximum;
  100. bool Normalized;
  101. int Dimension;
  102. double* Coordinates;
  103. };
  104. #endif