itom  4.1.0
menuComboBox.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, 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 
70  Q_PROPERTY(QString defaultText READ defaultText WRITE setDefaultText)
74  Q_PROPERTY(QIcon defaultIcon READ defaultIcon WRITE setDefaultIcon)
80  Q_PROPERTY(EditableBehavior editBehavior READ editableBehavior WRITE setEditableBehavior)
83  Q_PROPERTY(bool searchIconVisible READ isSearchIconVisible WRITE setSearchIconVisible)
88  Q_PROPERTY(Qt::ToolButtonStyle toolButtonStyle READ toolButtonStyle WRITE setToolButtonStyle)
89 public:
90  enum EditableBehavior{
91  NotEditable = 0,
92  Editable,
93  EditableOnFocus,
94  EditableOnPopup
95  };
96 
97  //Q_ENUM exposes a meta object to the enumeration types, such that the key names for the enumeration
98  //values are always accessible.
99  Q_ENUM(EditableBehavior)
100 
101 
102  typedef QWidget Superclass;
103 
105  MenuComboBox(QWidget* parent = 0);
106  virtual ~MenuComboBox();
107 
110  Q_INVOKABLE void setMenu(QMenu* menu);
111  Q_INVOKABLE QMenu* menu()const;
112 
118  Q_INVOKABLE void setCompleterMenu(QMenu* menu);
119  Q_INVOKABLE QMenu* completerMenu()const;
120 
121  void setDefaultText(const QString&);
122  QString defaultText()const;
123 
124  void setDefaultIcon(const QIcon&);
125  QIcon defaultIcon()const;
126 
127  void setEditableBehavior(EditableBehavior editBehavior);
128  EditableBehavior editableBehavior()const;
129 
130  void setSearchIconVisible(bool state);
131  bool isSearchIconVisible() const;
132 
133  Qt::ToolButtonStyle toolButtonStyle() const;
134 
137  void setMinimumContentsLength(int characters);
138 
140  QComboBox* menuComboBoxInternal() const;
141 
143  QToolButton* toolButtonInternal() const;
144 
146  Completer* searchCompleter() const;
147 
148 protected:
149  virtual bool eventFilter(QObject* target, QEvent* event);
150 
151 public Q_SLOTS:
152  void clearActiveAction();
153  void setToolButtonStyle(Qt::ToolButtonStyle style);
154 
155 Q_SIGNALS:
156  void actionChanged(QAction* action);
157  void popupShown();
158 
159 protected Q_SLOTS:
163  void onActionSelected(QAction* action);
165  void onEditingFinished();
166 
167 protected:
168  QScopedPointer<MenuComboBoxPrivate> d_ptr;
169 
170 private:
171  Q_DECLARE_PRIVATE(MenuComboBox);
172  Q_DISABLE_COPY(MenuComboBox);
173 };
174 
175 Q_DECLARE_METATYPE(MenuComboBox::EditableBehavior)
176 
177 #endif
Definition: menuComboBox.h:63
Definition: menuComboBox_p.h:64
QWidget Superclass
Superclass typedef.
Definition: menuComboBox.h:102
Definition: completer.h:63