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 WIDGETBOXTREEWIDGET_H |
30 | #define WIDGETBOXTREEWIDGET_H |
31 | |
32 | #include <qdesigner_widgetbox_p.h> |
33 | |
34 | #include <QtWidgets/qtreewidget.h> |
35 | #include <QtGui/qicon.h> |
36 | #include <QtCore/qlist.h> |
37 | #include <QtCore/qhash.h> |
38 | #include <QtCore/qxmlstream.h> |
39 | |
40 | QT_BEGIN_NAMESPACE |
41 | |
42 | class QDesignerFormEditorInterface; |
43 | class QDesignerDnDItemInterface; |
44 | |
45 | class QTimer; |
46 | |
47 | namespace qdesigner_internal { |
48 | |
49 | class WidgetBoxCategoryListView; |
50 | |
51 | // WidgetBoxTreeWidget: A tree of categories |
52 | |
53 | class WidgetBoxTreeWidget : public QTreeWidget |
54 | { |
55 | Q_OBJECT |
56 | |
57 | public: |
58 | using Widget = QDesignerWidgetBoxInterface::Widget; |
59 | using Category = QDesignerWidgetBoxInterface::Category; |
60 | using CategoryList = QDesignerWidgetBoxInterface::CategoryList; |
61 | |
62 | explicit WidgetBoxTreeWidget(QDesignerFormEditorInterface *core, QWidget *parent = nullptr); |
63 | ~WidgetBoxTreeWidget(); |
64 | |
65 | int categoryCount() const; |
66 | Category category(int cat_idx) const; |
67 | void addCategory(const Category &cat); |
68 | void removeCategory(int cat_idx); |
69 | |
70 | int widgetCount(int cat_idx) const; |
71 | Widget widget(int cat_idx, int wgt_idx) const; |
72 | void addWidget(int cat_idx, const Widget &wgt); |
73 | void removeWidget(int cat_idx, int wgt_idx); |
74 | |
75 | void dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list); |
76 | |
77 | void setFileName(const QString &file_name); |
78 | QString fileName() const; |
79 | bool load(QDesignerWidgetBox::LoadMode loadMode); |
80 | bool loadContents(const QString &contents); |
81 | bool save(); |
82 | QIcon iconForWidget(const QString &iconName) const; |
83 | |
84 | signals: |
85 | void pressed(const QString &name, const QString &dom_xml, const QPoint &global_mouse_pos); |
86 | |
87 | public slots: |
88 | void filter(const QString &); |
89 | |
90 | protected: |
91 | void (QContextMenuEvent *e) override; |
92 | void resizeEvent(QResizeEvent *e) override; |
93 | |
94 | private slots: |
95 | void slotSave(); |
96 | void slotScratchPadItemDeleted(); |
97 | void slotLastScratchPadItemDeleted(); |
98 | |
99 | void handleMousePress(QTreeWidgetItem *item); |
100 | void deleteScratchpad(); |
101 | void slotListMode(); |
102 | void slotIconMode(); |
103 | |
104 | private: |
105 | WidgetBoxCategoryListView *addCategoryView(QTreeWidgetItem *parent, bool iconMode); |
106 | WidgetBoxCategoryListView *categoryViewAt(int idx) const; |
107 | void adjustSubListSize(QTreeWidgetItem *cat_item); |
108 | |
109 | static bool readCategories(const QString &fileName, const QString &xml, CategoryList *cats, QString *errorMessage); |
110 | static bool readWidget(Widget *w, const QString &xml, QXmlStreamReader &r); |
111 | |
112 | CategoryList loadCustomCategoryList() const; |
113 | void writeCategories(QXmlStreamWriter &writer, const CategoryList &cat_list) const; |
114 | |
115 | int indexOfCategory(const QString &name) const; |
116 | int indexOfScratchpad() const; |
117 | int ensureScratchpad(); |
118 | void addCustomCategories(bool replace); |
119 | |
120 | void saveExpandedState() const; |
121 | void restoreExpandedState(); |
122 | void updateViewMode(); |
123 | |
124 | QDesignerFormEditorInterface *m_core; |
125 | QString m_file_name; |
126 | using IconCache = QHash<QString, QIcon>; |
127 | mutable IconCache m_pluginIcons; |
128 | bool m_iconMode; |
129 | QTimer *m_scratchPadDeleteTimer; |
130 | }; |
131 | |
132 | } // namespace qdesigner_internal |
133 | |
134 | QT_END_NAMESPACE |
135 | |
136 | #endif // WIDGETBOXTREEWIDGET_H |
137 | |