ctkThumbnailLabel.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 __ctkThumbnailLabel_h
  15. #define __ctkThumbnailLabel_h
  16. // Qt includes
  17. #include <QWidget>
  18. #include <QModelIndex>
  19. #include "ctkWidgetsExport.h"
  20. class ctkThumbnailLabelPrivate;
  21. /// \ingroup Widgets
  22. /// ctkThumbnailLabel is an advanced label that gives control over
  23. /// the pixmap size and text location.
  24. /// If a pixmap is set, it is resized to fit the available space but its
  25. /// original width/height ratio is always respected.
  26. /// The widget can be selected or not (a rectangle is drawn around)
  27. class CTK_WIDGETS_EXPORT ctkThumbnailLabel : public QWidget
  28. {
  29. Q_OBJECT
  30. /// If the text is empty, the space allocated for the text is hidden
  31. /// Empty by default
  32. Q_PROPERTY(QString text READ text WRITE setText)
  33. /// Position of the text relative to the pixmap.
  34. /// Qt::AlignTop | Qt::AlignHCenter by default.
  35. /// For now, if the alignment is HCenter|VCenter (same location than the
  36. /// pixmap), no text is shown.
  37. Q_PROPERTY(Qt::Alignment textPosition READ textPosition WRITE setTextPosition)
  38. /// Optional pixmap for the label.
  39. /// No pixmap by default
  40. Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap)
  41. /// Controls the quality of the resizing of the pixmap.
  42. /// Qt::FastTransformation by default
  43. Q_PROPERTY(Qt::TransformationMode transformationMode READ transformationMode WRITE setTransformationMode)
  44. /// Control whether or not the label is selected. When selected, a rectangle
  45. /// is drawn around the widget with the \a selectedColor color.
  46. /// Not selected by default
  47. Q_PROPERTY(bool selected READ isSelected WRITE setSelected)
  48. /// Color of the selected rectangle.
  49. /// Palette highlight color by default
  50. Q_PROPERTY(QColor selectedColor READ selectedColor WRITE setSelectedColor)
  51. public:
  52. typedef QWidget Superclass;
  53. explicit ctkThumbnailLabel(QWidget* parent=0);
  54. virtual ~ctkThumbnailLabel();
  55. void setText(const QString& text);
  56. QString text()const;
  57. void setTextPosition(const Qt::Alignment& alignment);
  58. Qt::Alignment textPosition()const;
  59. void setPixmap(const QPixmap& pixmap);
  60. const QPixmap* pixmap()const;
  61. Qt::TransformationMode transformationMode()const;
  62. void setTransformationMode(Qt::TransformationMode mode);
  63. void setSelected(bool selected);
  64. bool isSelected()const;
  65. void setSelectedColor(const QColor& color);
  66. QColor selectedColor()const;
  67. virtual QSize minimumSizeHint()const;
  68. virtual QSize sizeHint()const;
  69. virtual int heightForWidth(int width)const;
  70. protected:
  71. QScopedPointer<ctkThumbnailLabelPrivate> d_ptr;
  72. virtual void paintEvent(QPaintEvent* event);
  73. virtual void mousePressEvent(QMouseEvent* event);
  74. virtual void mouseDoubleClickEvent(QMouseEvent* event);
  75. virtual void resizeEvent(QResizeEvent* event);
  76. private:
  77. Q_DECLARE_PRIVATE(ctkThumbnailLabel);
  78. Q_DISABLE_COPY(ctkThumbnailLabel);
  79. Q_SIGNALS:
  80. void selected(const ctkThumbnailLabel& widget);
  81. void doubleClicked(const ctkThumbnailLabel& widget);
  82. };
  83. #endif