FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
item_view_buttons.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 class QAbstractItemView;
19 class QIcon;
20 class QPainter;
21 class QStyledItemDelegate;
22 class QStyleOptionViewItem;
23 
24 #include "gui.h"
25 
26 #include <QtCore/QHash>
27 #include <QtCore/QModelIndex>
28 #include <QtCore/QObject>
29 #include <QtCore/QFlags>
30 #include <QtGui/QIcon>
31 
32 namespace qtgui {
33 
34 class QTTOOLS_GUI_EXPORT ItemViewButtons : public QObject
35 {
36  Q_OBJECT
37 
38 public:
39  // Types
40  enum ItemSide
41  {
43  ItemRightSide
44  };
45 
47  {
48  DisplayOnDetection = 0x01,
49  DisplayPermanent = 0x02,
50  DisplayWhenItemSelected = 0x04
51  };
52  typedef QFlags<DisplayMode> DisplayModes;
53 
54  // Ctor & dtor
55  ItemViewButtons(QAbstractItemView* view, QObject* parent = NULL);
56  ~ItemViewButtons();
57 
58  // View control
59  QAbstractItemView* itemView() const;
60 
61  bool eventFilter(QObject *object, QEvent *event) Q_DECL_OVERRIDE;
62  void paint(
63  QPainter* painter,
64  const QStyleOptionViewItem& option,
65  const QModelIndex& index) const;
66 
67  // Button management
68  void addButton(
69  int btnId,
70  const QIcon& icon = QIcon(),
71  const QString& toolTip = QString());
72  void copyButtonProperties(int srcBtnId, int dstBtnId);
73 
74  int buttonDetectionMatchRole(int btnId) const;
75  QVariant buttonDetectionMatchData(int btnId) const;
76  void setButtonDetection(int btnId, int matchRole, const QVariant& matchData);
77 
78  int buttonDisplayColumn(int btnId) const;
79  void setButtonDisplayColumn(int btnId, int col = -1);
80 
81  int buttonItemSide(int btnId) const;
82  void setButtonItemSide(int btnId, ItemSide side);
83 
84  DisplayModes buttonDisplayModes(int btnId) const;
85  void setButtonDisplayModes(int btnId, DisplayModes modes);
86 
87  QIcon buttonIcon(int btnId) const;
88  void setButtonIcon(int btnId, const QIcon& icon);
89 
90  QSize buttonIconSize(int btnId) const;
91  void setButtonIconSize(int btnId, const QSize& size);
92 
93  QString buttonToolTip(int btnId) const;
94  void setButtonToolTip(int btnId, const QString& toolTip);
95 
96  // Delegates
97  void installDefaultItemDelegate();
98  QStyledItemDelegate* createProxyItemDelegate(
99  QStyledItemDelegate *sourceDelegate,
100  QObject* parent = NULL) const;
101 
102 signals:
103  void buttonClicked(int btnId, const QModelIndex& index);
104 
105 public slots:
106  void reset();
107 
108 protected:
109  virtual int buttonAtModelIndex(const QModelIndex& index) const;
110 
111 private:
112  class Private;
113  friend class Private;
114  Private* const d;
115 };
116 
117 } // namespace qtgui
118 
119 Q_DECLARE_OPERATORS_FOR_FLAGS(qtgui::ItemViewButtons::DisplayModes)
DisplayMode
Definition: item_view_buttons.h:46
Definition: abstract_length_editor.cpp:20
Provides buttons integrated to items displayed by QAbstractItemView.
Definition: item_view_buttons.h:34
QFlags< DisplayMode > DisplayModes
Definition: item_view_buttons.h:52
#define QTTOOLS_GUI_EXPORT
Definition: gui.h:27
Definition: item_view_buttons.h:42
ItemSide
Definition: item_view_buttons.h:40