ctkCrosshairLabel.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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 __ctkCrosshairLabel_h
  15. #define __ctkCrosshairLabel_h
  16. // QT includes
  17. #include <QLabel>
  18. #include <QPen>
  19. class QColor;
  20. class QSize;
  21. // CTK includes
  22. #include "ctkWidgetsExport.h"
  23. class ctkCrosshairLabelPrivate;
  24. /// \ingroup Widgets
  25. /// Draws a crosshair onto a QLabel. This widget is designed to be used to show
  26. /// a crosshair overlaid onto an image (the QLabel's pixmap).
  27. /// Since painting must be done in discrete pixels, this widget looks best
  28. /// when the widget size and the crosshair line width are both either even or odd.
  29. /// If using a bulls-eye crosshair, this widget looks best if the crosshair line
  30. /// width and the bullsEyeWidth are both either even or odd.
  31. class CTK_WIDGETS_EXPORT ctkCrosshairLabel : public QLabel
  32. {
  33. Q_OBJECT
  34. Q_FLAGS(CrosshairType CrosshairTypes)
  35. Q_PROPERTY(bool showCrosshair READ showCrosshair WRITE setShowCrosshair)
  36. // QT designer does not yet support QPen properties, so we provide the
  37. // temporary properties crosshairColor and lineWidth.
  38. Q_PROPERTY(QPen crosshairPen READ crosshairPen WRITE setCrosshairPen
  39. DESIGNABLE false)
  40. Q_PROPERTY(QColor crosshairColor READ crosshairColor WRITE setCrosshairColor)
  41. Q_PROPERTY(int lineWidth READ lineWidth WRITE setLineWidth)
  42. Q_PROPERTY(CrosshairTypes crosshairType READ crosshairType WRITE setCrosshairType)
  43. Q_PROPERTY(QColor marginColor READ marginColor WRITE setMarginColor)
  44. Q_PROPERTY(int bullsEyeWidth READ bullsEyeWidth WRITE setBullsEyeWidth)
  45. public:
  46. /// Constructors
  47. typedef QLabel Superclass;
  48. explicit ctkCrosshairLabel(QWidget* parent = 0);
  49. virtual ~ctkCrosshairLabel();
  50. /// Enumeration over types of crosshairs
  51. enum CrosshairType {
  52. SimpleCrosshair = 0,
  53. BullsEyeCrosshair
  54. };
  55. Q_DECLARE_FLAGS(CrosshairTypes, CrosshairType)
  56. /// Set/get whether or not to draw the crosshair. Default True.
  57. bool showCrosshair() const;
  58. void setShowCrosshair(bool newShow);
  59. /// Set/get the pen used to draw the crosshair. Default color is from the
  60. /// widget's palette's Highlight role, default width is 0 (which draws
  61. /// at 1 pixel wide regardless of painter transformation). Since painting
  62. /// must be done in discrete pixels, this widget looks best when the widget
  63. /// size and the crosshair pen width are both either even or odd.
  64. QPen crosshairPen() const;
  65. void setCrosshairPen(const QPen& newPen);
  66. /// Temporary: Set/get the crosshair color (via QPen). This will be removed once
  67. /// Qt Designer supports QPen properties.
  68. QColor crosshairColor() const;
  69. void setCrosshairColor(const QColor& newColor);
  70. /// Temporary: Set/get the crosshair line width (via QPen). This will be removed
  71. /// once Qt Designer supports QPen properties. Since painting
  72. /// must be done in discrete pixels, this widget looks best when the widget
  73. /// size and the crosshair pen width are both either even or odd.
  74. int lineWidth() const;
  75. void setLineWidth(int newWidth);
  76. /// Set/get the crosshair type. Default SimpleCrosshair.
  77. CrosshairTypes crosshairType() const;
  78. void setCrosshairType(const CrosshairTypes& newType);
  79. /// Set/get color to set the widget to when not magnifying or when label
  80. /// size is larger than pixmap size. Default is the color from the widget's
  81. /// palette Window role. Note that the Window role is overridden if you
  82. /// set this property. Does not support transparent colors.
  83. QColor marginColor() const;
  84. void setMarginColor(const QColor& newColor);
  85. /// Set/get the width of the crosshair when in BullsEye mode.
  86. /// Looks best when the BullsEye width and the widget size are both either
  87. /// even or odd, preferably odd. Default 15. Since painting must be done
  88. /// in discrete pixels, this widget looks best if the crosshair pen width and
  89. /// the bullsEyeWidth are both either even or odd.
  90. int bullsEyeWidth() const;
  91. void setBullsEyeWidth(int newWidth);
  92. /// Size hints
  93. virtual QSize minimumSizeHint()const;
  94. virtual QSize sizeHint()const;
  95. virtual bool hasHeightForWidth()const;
  96. virtual int heightForWidth(int width)const;
  97. protected:
  98. QScopedPointer<ctkCrosshairLabelPrivate> d_ptr;
  99. // Draws the crosshair on top of the widget.
  100. virtual void paintEvent(QPaintEvent * event);
  101. private:
  102. Q_DECLARE_PRIVATE(ctkCrosshairLabel)
  103. Q_DISABLE_COPY(ctkCrosshairLabel)
  104. };
  105. #endif