digiKam
comboboxutilities.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2008-03-14
7  * Description : User interface for searches
8  *
9  * Copyright (C) 2008-2012 by Marcel Wiesweg <marcel dot wiesweg at gmx dot de>
10  *
11  * This program is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU General
13  * Public License as published by the Free Software Foundation;
14  * either version 2, or (at your option)
15  * any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  * GNU General Public License for more details.
21  *
22  * ============================================================ */
23 
24 #ifndef DIGIKAM_COMBOBOX_UTILITIES_H
25 #define DIGIKAM_COMBOBOX_UTILITIES_H
26 
27 // Qt includes
28 
29 #include <QLabel>
30 #include <QListView>
31 #include <QComboBox>
32 #include <QPersistentModelIndex>
33 #include <QLineEdit>
34 
35 // Local includes
36 
37 #include "digikam_export.h"
38 
39 class QVBoxLayout;
40 class QTreeView;
41 
42 namespace Digikam
43 {
44 
45 class DIGIKAM_EXPORT ProxyLineEdit : public QLineEdit
46 {
47  Q_OBJECT
48 
49 public:
50 
58  explicit ProxyLineEdit(QWidget* const parent = nullptr);
59 
63  virtual void setWidget(QWidget* widget);
64 
65  void setClearButtonShown(bool show);
66 
67 Q_SIGNALS:
68 
70 
71 private Q_SLOTS:
72 
73  void slotTextChanged(const QString& text);
74 
75 protected:
76 
77  QSize minimumSizeHint() const override;
78  QSize sizeHint() const override;
79 
80  void mousePressEvent(QMouseEvent* event) override;
81  void mouseMoveEvent(QMouseEvent* event) override;
82  void mouseReleaseEvent(QMouseEvent* event) override;
83  void mouseDoubleClickEvent(QMouseEvent* event) override;
84  void keyPressEvent(QKeyEvent* event) override;
85  void focusInEvent(QFocusEvent* event) override;
86  void focusOutEvent(QFocusEvent* event) override;
87  void paintEvent(QPaintEvent* event) override;
88  void dragEnterEvent(QDragEnterEvent* event) override;
89  void dragMoveEvent(QDragMoveEvent* e) override;
90  void dragLeaveEvent(QDragLeaveEvent* e) override;
91  void dropEvent(QDropEvent* event) override;
92  void changeEvent(QEvent* event) override;
93  void contextMenuEvent(QContextMenuEvent* event) override;
94  void inputMethodEvent(QInputMethodEvent* event) override;
95 
96 protected:
97 
98  QWidget* m_widget;
99  QVBoxLayout* m_layout;
100 };
101 
102 // -------------------------------------------------------------------------
103 
104 class DIGIKAM_EXPORT ProxyClickLineEdit : public ProxyLineEdit
105 {
106  Q_OBJECT
107 
108 public:
109 
116  explicit ProxyClickLineEdit(QWidget* const parent = nullptr);
117 
118 Q_SIGNALS:
119 
120  void leftClicked();
121 
122 protected:
123 
124  void mouseReleaseEvent(QMouseEvent* event) override;
125 };
126 
127 // -------------------------------------------------------------------------
128 
129 class DIGIKAM_EXPORT ModelIndexBasedComboBox : public QComboBox
130 {
131  Q_OBJECT
132 
133 public:
134 
141  explicit ModelIndexBasedComboBox(QWidget* const parent = nullptr);
142 
143  QModelIndex currentIndex() const;
144  void setCurrentIndex(const QModelIndex& index);
145 
146  void hidePopup() override;
147  void showPopup() override;
148 
149 protected:
150 
151  QPersistentModelIndex m_currentIndex;
152 };
153 
154 // -------------------------------------------------------------------------
155 
156 class DIGIKAM_EXPORT StayPoppedUpComboBox : public ModelIndexBasedComboBox
157 {
158  Q_OBJECT
159 
160 public:
161 
173  explicit StayPoppedUpComboBox(QWidget* const parent = nullptr);
174 
175 protected:
176 
182  void installView(QAbstractItemView* view);
183 
192  virtual void sendViewportEventToView(QEvent* e) = 0;
193 
194  bool eventFilter(QObject* watched, QEvent* event) override;
195 
196 protected:
197 
198  QAbstractItemView* m_view;
199 };
200 
201 // -------------------------------------------------------------------------
202 
203 class DIGIKAM_EXPORT TreeViewComboBox : public StayPoppedUpComboBox
204 {
205  Q_OBJECT
206 
207 public:
208 
217  explicit TreeViewComboBox(QWidget* parent = nullptr);
218 
223  virtual void installView(QAbstractItemView* view = nullptr);
224 
228  QTreeView* view() const;
229 
230 protected:
231 
232  void sendViewportEventToView(QEvent* e) override;
233 };
234 
235 // -------------------------------------------------------------------------
236 
237 class DIGIKAM_EXPORT ListViewComboBox : public StayPoppedUpComboBox
238 {
239  Q_OBJECT
240 
241 public:
242 
251  explicit ListViewComboBox(QWidget* parent = nullptr);
252 
256  QListView* view() const;
257 
262  virtual void installView(QAbstractItemView* view = nullptr);
263 
264 protected:
265 
266  void sendViewportEventToView(QEvent* e) override;
267 };
268 
269 // -------------------------------------------------------------------------
270 
271 class DIGIKAM_EXPORT TreeViewLineEditComboBox : public TreeViewComboBox
272 {
273  Q_OBJECT
274 
275 public:
276 
287  explicit TreeViewLineEditComboBox(QWidget* const parent = nullptr);
288 
294  void setLineEditText(const QString& text);
295 
296  void setLineEdit(QLineEdit* edit);
297 
302  void installView(QAbstractItemView* view = nullptr) override;
303 
304 protected:
305 
311  virtual void installLineEdit();
312 
313 protected:
314 
315  QLineEdit* m_comboLineEdit;
316 };
317 
318 } // namespace Digikam
319 
320 #endif // DIGIKAM_COMBOBOX_UTILITIES_H
Definition: comboboxutilities.h:238
Definition: comboboxutilities.h:130
QPersistentModelIndex m_currentIndex
Definition: comboboxutilities.h:151
Definition: comboboxutilities.h:105
Definition: comboboxutilities.h:46
QWidget * m_widget
Definition: comboboxutilities.h:98
QVBoxLayout * m_layout
Definition: comboboxutilities.h:99
Definition: comboboxutilities.h:157
virtual void sendViewportEventToView(QEvent *e)=0
QAbstractItemView * m_view
Definition: comboboxutilities.h:198
Definition: comboboxutilities.h:204
Definition: comboboxutilities.h:272
QLineEdit * m_comboLineEdit
Definition: comboboxutilities.h:315
Definition: datefolderview.cpp:43