itom  3.0.0
menuComboBox.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom and its software development toolkit (SDK).
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  In addition, as a special exception, the Institut fuer Technische
15  Optik (ITO) gives you certain additional rights.
16  These rights are described in the ITO LGPL Exception version 1.0,
17  which can be found in the file LGPL_EXCEPTION.txt in this package.
18 
19  itom is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
22  General Public Licence for more details.
23 
24  You should have received a copy of the GNU Library General Public License
25  along with itom. If not, see <http://www.gnu.org/licenses/>.
26 
27  This file is a port and modified version of the
28  Common framework (http://www.commontk.org)
29 *********************************************************************** */
30 
31 #ifndef MENUCOMBOBOX_H
32 #define MENUCOMBOBOX_H
33 
34 // Qt includes
35 #include <QMenu>
36 #include <QMetaType>
37 #include <QWidget>
38 class QComboBox;
39 class QToolButton;
40 
41 // CTK includes
42 #include "commonWidgets.h"
43 class Completer;
45 
58 
62 
63 class ITOMWIDGETS_EXPORT MenuComboBox : public QWidget
64 {
65  Q_OBJECT
66 
67 #if QT_VERSION < 0x050500
68  //for >= Qt 5.5.0 see Q_ENUM definition below
69  Q_ENUMS(EditableBehavior)
70 #endif
71 
75  Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
79  Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
85  Q_PROPERTY(EditableBehavior editBehavior READ editableBehavior WRITE setEditableBehavior)
88  Q_PROPERTY(bool searchIconVisible READ isSearchIconVisible WRITE setSearchIconVisible)
93  Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
94 public:
95  enum EditableBehavior{
96  NotEditable = 0,
97  Editable,
98  EditableOnFocus,
99  EditableOnPopup
100  };
101 
102 #if QT_VERSION >= 0x050500
103  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
104  //values are always accessible.
105  Q_ENUM(EditableBehavior)
106 #endif
107 
109  typedef QWidget Superclass;
110 
112  MenuComboBox(QWidget* parent = 0);
113  virtual ~MenuComboBox();
114 
116  void setMenu(QMenu* menu);
117  QMenu* menu()const;
118 
119  void setDefaultText(const QString&);
120  QString defaultText()const;
121 
122  void setDefaultIcon(const QIcon&);
123  QIcon defaultIcon()const;
124 
125  void setEditableBehavior(EditableBehavior editBehavior);
126  EditableBehavior editableBehavior()const;
127 
128  void setSearchIconVisible(bool state);
129  bool isSearchIconVisible() const;
130 
131  Qt::ToolButtonStyle toolButtonStyle() const;
132 
135  void setMinimumContentsLength(int characters);
136 
138  QComboBox* menuComboBoxInternal() const;
139 
141  QToolButton* toolButtonInternal() const;
142 
144  Completer* searchCompleter() const;
145 
146 protected:
147  virtual bool eventFilter(QObject* target, QEvent* event);
148 
149 public Q_SLOTS:
150  void clearActiveAction();
151  void setToolButtonStyle(Qt::ToolButtonStyle style);
152 
153 Q_SIGNALS:
154  void actionChanged(QAction* action);
155  void popupShown();
156 
157 protected Q_SLOTS:
161  void onActionSelected(QAction* action);
163  void onEditingFinished();
164 
165 protected:
166  QScopedPointer<MenuComboBoxPrivate> d_ptr;
167 
168 private:
169  Q_DECLARE_PRIVATE(MenuComboBox);
170  Q_DISABLE_COPY(MenuComboBox);
171 };
172 
173 Q_DECLARE_METATYPE(MenuComboBox::EditableBehavior)
174 
175 #endif
Definition: menuComboBox.h:63
Definition: menuComboBox_p.h:64
QWidget Superclass
Superclass typedef.
Definition: menuComboBox.h:109
Definition: completer.h:63