SMTK  @SMTK_VERSION@
Simulation Modeling Tool Kit
qtDescriptivePhraseDelegate.h
1 //=========================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //=========================================================================
10 
11 #ifndef smtk_extension_qtDescriptivePhraseDelegate_h
12 #define smtk_extension_qtDescriptivePhraseDelegate_h
13 
14 #include "smtk/extension/qt/Exports.h"
15 #include "smtk/view/BadgeSet.h"
16 #include "smtk/view/Selection.h"
17 
18 #include <QStyledItemDelegate>
19 
20 namespace smtk
21 {
22 namespace extension
23 {
24 
25 class qtDescriptivePhraseModel;
29 class SMTKQTEXT_EXPORT qtDescriptivePhraseDelegate : public QStyledItemDelegate
30 {
31  Q_OBJECT
32  Q_PROPERTY(int titleFontSize READ titleFontSize WRITE setTitleFontSize)
33  Q_PROPERTY(int subtitleFontSize READ subtitleFontSize WRITE setSubtitleFontSize)
34  Q_PROPERTY(int titleFontWeight READ titleFontWeight WRITE setTitleFontWeight)
35  Q_PROPERTY(int subtitleFontWeight READ subtitleFontWeight WRITE setSubtitleFontWeight)
36  Q_PROPERTY(int textVerticalPad READ textVerticalPad WRITE setTextVerticalPad)
37  Q_PROPERTY(bool drawSubtitle READ drawSubtitle WRITE setDrawSubtitle)
38  Q_PROPERTY(bool visibilityMode READ visibilityMode WRITE setVisibilityMode)
39  Q_PROPERTY(std::shared_ptr<smtk::view::Selection> selection READ selection WRITE setSelection)
40 public:
41  qtDescriptivePhraseDelegate(QWidget* parent = nullptr);
42 
43  int titleFontSize() const;
44  int subtitleFontSize() const;
45  int titleFontWeight() const;
46  int subtitleFontWeight() const;
47  int textVerticalPad() const;
48  bool drawSubtitle() const;
49  bool highlightOnHover() const;
50  bool visibilityMode() const;
51  std::shared_ptr<smtk::view::Selection> selection() const;
52 
53 public Q_SLOTS:
54  void setTitleFontSize(int tfs);
55  void setSubtitleFontSize(int sfs);
56  void setTitleFontWeight(int tfs);
57  void setSubtitleFontWeight(int sfs);
58  void setTextVerticalPad(int tvp);
59  void setDrawSubtitle(bool includeSubtitle);
60  void setVisibilityMode(bool allEditsChangeVisibility);
61  void setHighlightOnHover(bool highlightOnMouseover);
62  void setSelection(const std::shared_ptr<smtk::view::Selection>& seln);
63 
64 public:
65  QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const override;
66 
67  void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index)
68  const override;
69 
70  QWidget* createEditor(
71  QWidget* parent,
72  const QStyleOptionViewItem& option,
73  const QModelIndex& index) const override;
74  void updateEditorGeometry(
75  QWidget* editor,
76  const QStyleOptionViewItem& option,
77  const QModelIndex& index) const override;
78 
79  void setEditorData(QWidget* editor, const QModelIndex& index) const override;
80  void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index)
81  const override;
82 
95  static bool processBadgeClick(QMouseEvent* mouseClickEvent, QAbstractItemView* view);
96 
98  static int pickBadge(
99  const QPoint& pPos,
100  const QStyleOptionViewItem& option,
101  const smtk::view::BadgeSet::BadgeList& badges,
102  const smtk::view::DescriptivePhrase* phrase);
103 
104 protected:
105  bool eventFilter(QObject* editor, QEvent* event) override;
106 
107  int m_titleFontSize{ 14 };
108  int m_subtitleFontSize{ 10 };
109  int m_titleFontWeight{ 2 };
110  int m_subtitleFontWeight{ 1 };
111  int m_textVerticalPad{ 2 };
112  bool m_drawSubtitle{ true };
113  bool m_visibilityMode{ false };
114  bool m_highlightOnHover{ false };
115  std::weak_ptr<smtk::view::Selection> m_selection;
116 };
117 
118 } // namespace extension
119 } // namespace smtk
120 
121 #endif // smtk_extension_qtDescriptivePhraseDelegate_h
smtk
The main namespace for the Simulation Modeling Tool Kit (SMTK).
Definition: doc.h:33
smtk::view::DescriptivePhrase
A base class for phrases describing an SMTK model.
Definition: DescriptivePhrase.h:76
smtk::extension::qtDescriptivePhraseDelegate
Present the contents of an smtk::model::Resource instance via qtDescriptivePhraseModel.
Definition: qtDescriptivePhraseDelegate.h:29