CTK  0.1.0
The Common Toolkit is a community effort to provide support code for medical image analysis, surgical navigation, and related projects.
ctkActionsWidget.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Library: CTK
4 
5  Copyright (c) Kitware Inc.
6 
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10 
11  http://www.apache.org/licenses/LICENSE-2.0.txt
12 
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 
19 =========================================================================*/
20 
21 #ifndef __ctkActionsWidget_h
22 #define __ctkActionsWidget_h
23 
24 // Qt includes
25 #include <QStyledItemDelegate>
26 #include <QSortFilterProxyModel>
27 #include <QWidget>
28 
29 // CTK includes
30 #include "ctkPimpl.h"
31 #include "ctkWidgetsExport.h"
32 class ctkActionsWidgetPrivate;
33 class ctkSortFilterActionsProxyModelPrivate;
34 
35 class QAction;
36 class QStandardItemModel;
37 class QStandardItem;
38 class QTreeView;
39 
50 class CTK_WIDGETS_EXPORT ctkActionsWidget : public QWidget
51 {
52  Q_OBJECT
53  Q_PROPERTY(bool actionsWithNoShortcutVisible READ areActionsWithNoShortcutVisible WRITE setActionsWithNoShortcutVisible)
54  Q_PROPERTY(bool menuActionsVisible READ areMenuActionsVisible WRITE setMenuActionsVisible)
58  Q_PROPERTY(int sortColumn READ sortColumn WRITE setSortColumn)
59 public:
60  explicit ctkActionsWidget(QWidget* parent = 0);
61  virtual ~ctkActionsWidget();
62 
67  void addAction(QAction* action, const QString& group = QString());
68 
70  void addActions(QList<QAction*> actions, const QString& group = QString());
71 
73  void clear();
74 
76  QStandardItem* groupItem(const QString& category);
77 
82 
85  void setMenuActionsVisible(bool show);
86  bool areMenuActionsVisible()const;
87 
90  void setSortColumn(int column);
93  int sortColumn()const;
94 
96  QStandardItemModel* model()const;
97 
99  QTreeView* view()const;
100 
101 protected Q_SLOTS:
102  void updateAction();
103 
104 protected:
106  NameColumn = 0,
109  DetailsColumn
110  };
111 protected:
112  QScopedPointer<ctkActionsWidgetPrivate> d_ptr;
113 
114 private:
115  Q_DECLARE_PRIVATE(ctkActionsWidget);
116  Q_DISABLE_COPY(ctkActionsWidget);
118 };
119 
124 class ctkSortFilterActionsProxyModel : public QSortFilterProxyModel
125 {
126  Q_OBJECT
127 public:
128  explicit ctkSortFilterActionsProxyModel(QObject* parent=0);
130 
133 
136 
137 protected:
138  bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const;
139  QScopedPointer<ctkSortFilterActionsProxyModelPrivate> d_ptr;
140 
141 private:
142  Q_DECLARE_PRIVATE(ctkSortFilterActionsProxyModel);
143  Q_DISABLE_COPY(ctkSortFilterActionsProxyModel);
144 };
145 
150 class ctkRichTextItemDelegate : public QStyledItemDelegate
151 {
152  Q_OBJECT
153 protected:
154  virtual void paint(QPainter * painter, const QStyleOptionViewItem & option,
155  const QModelIndex & index) const;
156  virtual QSize sizeHint(const QStyleOptionViewItem & option,
157  const QModelIndex & index)const;
158 };
159 
160 #endif
virtual ~ctkActionsWidget()
QScopedPointer< ctkActionsWidgetPrivate > d_ptr
void setMenuActionsVisible(bool show)
bool areActionsWithNoShortcutVisible() const
void clear()
Remove all the actions and groups.
QStandardItem * groupItem(const QString &category)
Return a pointer on a group item (you probably have no use for it)
void setActionsWithNoShortcutVisible(bool show)
void addActions(QList< QAction * > actions, const QString &group=QString())
Convenient function to add a list of action at once.
QTreeView * view() const
return the view used to display the action model
int sortColumn() const
bool areMenuActionsVisible() const
void setSortColumn(int column)
void addAction(QAction *action, const QString &group=QString())
QStandardItemModel * model() const
Return the unsorted/unfiltered model of all the actions.
ctkActionsWidget(QWidget *parent=0)
virtual void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
virtual QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
QScopedPointer< ctkSortFilterActionsProxyModelPrivate > d_ptr
bool filterAcceptsRow(int source_row, const QModelIndex &source_parent) const
void setActionsWithNoShortcutVisible(bool)
ctkSortFilterActionsProxyModel(QObject *parent=0)
bool areActionsWithNoShortcutVisible() const