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 ABSTRACTWIDGETBOX_H
30#define ABSTRACTWIDGETBOX_H
31
32#include <QtDesigner/sdk_global.h>
33
34#include <QtCore/qshareddata.h>
35#include <QtCore/qmetatype.h>
36#include <QtWidgets/qwidget.h>
37#include <QtGui/qicon.h>
38
39QT_BEGIN_NAMESPACE
40
41class DomUI;
42class QDesignerDnDItemInterface;
43
44class QDesignerWidgetBoxWidgetData;
45
46class QDESIGNER_SDK_EXPORT QDesignerWidgetBoxInterface : public QWidget
47{
48 Q_OBJECT
49public:
50 class QDESIGNER_SDK_EXPORT Widget {
51 public:
52 enum Type { Default, Custom };
53 Widget(const QString &aname = QString(), const QString &xml = QString(),
54 const QString &icon_name = QString(), Type atype = Default);
55 ~Widget();
56 Widget(const Widget &w);
57 Widget &operator=(const Widget &w);
58
59 QString name() const;
60 void setName(const QString &aname);
61 QString domXml() const;
62 void setDomXml(const QString &xml);
63 QString iconName() const;
64 void setIconName(const QString &icon_name);
65 Type type() const;
66 void setType(Type atype);
67
68 bool isNull() const;
69
70 private:
71 QSharedDataPointer<QDesignerWidgetBoxWidgetData> m_data;
72 };
73
74 class Category {
75 public:
76 enum Type { Default, Scratchpad };
77
78 Category(const QString &aname = QString(), Type atype = Default)
79 : m_name(aname), m_type(atype) {}
80
81 QString name() const { return m_name; }
82 void setName(const QString &aname) { m_name = aname; }
83 int widgetCount() const { return m_widget_list.size(); }
84 Widget widget(int idx) const { return m_widget_list.at(idx); }
85 void removeWidget(int idx) { m_widget_list.removeAt(idx); }
86 void addWidget(const Widget &awidget) { m_widget_list.append(awidget); }
87 Type type() const { return m_type; }
88 void setType(Type atype) { m_type = atype; }
89
90 bool isNull() const { return m_name.isEmpty(); }
91
92 private:
93 QString m_name;
94 Type m_type;
95 QList<Widget> m_widget_list;
96 };
97 using CategoryList = QList<Category>;
98
99 explicit QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags());
100 virtual ~QDesignerWidgetBoxInterface();
101
102 virtual int categoryCount() const = 0;
103 virtual Category category(int cat_idx) const = 0;
104 virtual void addCategory(const Category &cat) = 0;
105 virtual void removeCategory(int cat_idx) = 0;
106
107 virtual int widgetCount(int cat_idx) const = 0;
108 virtual Widget widget(int cat_idx, int wgt_idx) const = 0;
109 virtual void addWidget(int cat_idx, const Widget &wgt) = 0;
110 virtual void removeWidget(int cat_idx, int wgt_idx) = 0;
111
112 int findOrInsertCategory(const QString &categoryName);
113
114 virtual void dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list,
115 const QPoint &global_mouse_pos) = 0;
116
117 virtual void setFileName(const QString &file_name) = 0;
118 virtual QString fileName() const = 0;
119 virtual bool load() = 0;
120 virtual bool save() = 0;
121};
122
123QT_END_NAMESPACE
124
125Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QDesignerWidgetBoxInterface::Widget))
126
127#endif // ABSTRACTWIDGETBOX_H
128