ctkThumbnailListWidget.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 __ctkThumbnailListWidget_h
  15. #define __ctkThumbnailListWidget_h
  16. // Qt includes
  17. #include <QWidget>
  18. class QResizeEvent;
  19. // CTK includes
  20. #include "ctkWidgetsExport.h"
  21. class ctkThumbnailListWidgetPrivate;
  22. class ctkThumbnailLabel;
  23. /// \ingroup Widgets
  24. class CTK_WIDGETS_EXPORT ctkThumbnailListWidget : public QWidget
  25. {
  26. Q_OBJECT
  27. Q_PROPERTY(int currentThumbnail READ currentThumbnail WRITE setCurrentThumbnail)
  28. Q_PROPERTY(Qt::Orientation flow READ flow WRITE setFlow)
  29. Q_PROPERTY(QSize thumbnailSize READ thumbnailSize WRITE setThumbnailSize)
  30. public:
  31. typedef QWidget Superclass;
  32. explicit ctkThumbnailListWidget(QWidget* parent=0);
  33. virtual ~ctkThumbnailListWidget();
  34. /// Add a thumbnail to the widget
  35. void addThumbnail(const QPixmap& thumbnail, const QString& label = QString());
  36. /// Add multiple thumbnails to the widget
  37. void addThumbnails(const QList<QPixmap>& thumbnails);
  38. /// Set current thumbnail
  39. void setCurrentThumbnail(int index);
  40. /// Get current thumbnail
  41. int currentThumbnail();
  42. /// Clear all the thumbnails
  43. void clearThumbnails();
  44. /// Flow of the layout
  45. /// - Qt::Horizontal: left to right
  46. /// - Qt::Vertical: top to bottom
  47. void setFlow(Qt::Orientation orientation);
  48. Qt::Orientation flow()const;
  49. /// Get thumbnail width
  50. QSize thumbnailSize()const;
  51. virtual bool eventFilter(QObject* watched, QEvent* event);
  52. public Q_SLOTS:
  53. /// Set thumbnail width
  54. void setThumbnailSize(QSize size);
  55. Q_SIGNALS:
  56. void selected(const ctkThumbnailLabel& widget);
  57. void doubleClicked(const ctkThumbnailLabel& widget);
  58. protected Q_SLOTS:
  59. void onThumbnailSelected(const ctkThumbnailLabel& widget);
  60. void updateLayout();
  61. protected:
  62. explicit ctkThumbnailListWidget(ctkThumbnailListWidgetPrivate* ptr, QWidget* parent=0);
  63. ctkThumbnailListWidgetPrivate* d_ptr;
  64. virtual void resizeEvent(QResizeEvent* event);
  65. private:
  66. Q_DECLARE_PRIVATE(ctkThumbnailListWidget);
  67. Q_DISABLE_COPY(ctkThumbnailListWidget);
  68. };
  69. #endif