1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt Designer of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT |
21 | ** included in the packaging of this file. Please review the following |
22 | ** information to ensure the GNU General Public License requirements will |
23 | ** be met: https://www.gnu.org/licenses/gpl-3.0.html. |
24 | ** |
25 | ** $QT_END_LICENSE$ |
26 | ** |
27 | ****************************************************************************/ |
28 | |
29 | #ifndef WIDGETBOXCATEGORYLISTVIEW_H |
30 | #define WIDGETBOXCATEGORYLISTVIEW_H |
31 | |
32 | #include <QtDesigner/abstractwidgetbox.h> |
33 | |
34 | #include <QtWidgets/qlistview.h> |
35 | #include <QtCore/qlist.h> |
36 | |
37 | QT_BEGIN_NAMESPACE |
38 | |
39 | class QDesignerFormEditorInterface; |
40 | class QDesignerDnDItemInterface; |
41 | |
42 | class QSortFilterProxyModel; |
43 | class QRegExp; |
44 | |
45 | namespace qdesigner_internal { |
46 | |
47 | class WidgetBoxCategoryModel; |
48 | |
49 | // List view of a category, switchable between icon and list mode. |
50 | // Provides a filtered view. |
51 | class WidgetBoxCategoryListView : public QListView |
52 | { |
53 | Q_OBJECT |
54 | public: |
55 | // Whether to access the filtered or unfiltered view |
56 | enum AccessMode { FilteredAccess, UnfilteredAccess }; |
57 | |
58 | explicit WidgetBoxCategoryListView(QDesignerFormEditorInterface *core, QWidget *parent = nullptr); |
59 | void setViewMode(ViewMode vm); |
60 | |
61 | void dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list); |
62 | |
63 | using QListView::contentsSize; |
64 | |
65 | // These methods operate on the filtered/unfiltered model according to accessmode |
66 | int count(AccessMode am) const; |
67 | QDesignerWidgetBoxInterface::Widget widgetAt(AccessMode am, const QModelIndex &index) const; |
68 | QDesignerWidgetBoxInterface::Widget widgetAt(AccessMode am, int row) const; |
69 | void removeRow(AccessMode am, int row); |
70 | void setCurrentItem(AccessMode am, int row); |
71 | |
72 | // These methods operate on the unfiltered model and are used for serialization |
73 | void addWidget(const QDesignerWidgetBoxInterface::Widget &widget, const QIcon &icon, bool editable); |
74 | bool containsWidget(const QString &name); |
75 | QDesignerWidgetBoxInterface::Category category() const; |
76 | bool removeCustomWidgets(); |
77 | |
78 | // Helper: Ensure a <ui> tag in the case of empty XML |
79 | static QString widgetDomXml(const QDesignerWidgetBoxInterface::Widget &widget); |
80 | |
81 | signals: |
82 | void scratchPadChanged(); |
83 | void pressed(const QString &name, const QString &xml, const QPoint &globalPos); |
84 | void itemRemoved(); |
85 | void lastItemRemoved(); |
86 | |
87 | public slots: |
88 | void filter(const QRegExp &re); |
89 | void removeCurrentItem(); |
90 | void editCurrentItem(); |
91 | |
92 | private slots: |
93 | void slotPressed(const QModelIndex &index); |
94 | |
95 | private: |
96 | int mapRowToSource(int filterRow) const; |
97 | QSortFilterProxyModel *m_proxyModel; |
98 | WidgetBoxCategoryModel *m_model; |
99 | }; |
100 | |
101 | } // namespace qdesigner_internal |
102 | |
103 | QT_END_NAMESPACE |
104 | |
105 | #endif // WIDGETBOXCATEGORYLISTVIEW_H |
106 | |