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 39 QT_BEGIN_NAMESPACE 40 41 class DomUI; 42 class QDesignerDnDItemInterface; 43 44 class QDesignerWidgetBoxWidgetData; 45 46 class QDESIGNER_SDK_EXPORT QDesignerWidgetBoxInterface : public QWidget 47 { 48 Q_OBJECT 49 public: 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 #if QT_VERSION < QT_VERSION_CHECK(6,0,0) 75 using WidgetList = QList<Widget>; 76 #endif 77 78 class Category { 79 public: 80 enum Type { Default, Scratchpad }; 81 82 Category(const QString &aname = QString(), Type atype = Default) m_name(aname)83 : m_name(aname), m_type(atype) {} 84 name()85 QString name() const { return m_name; } setName(const QString & aname)86 void setName(const QString &aname) { m_name = aname; } widgetCount()87 int widgetCount() const { return m_widget_list.size(); } widget(int idx)88 Widget widget(int idx) const { return m_widget_list.at(idx); } removeWidget(int idx)89 void removeWidget(int idx) { m_widget_list.removeAt(idx); } addWidget(const Widget & awidget)90 void addWidget(const Widget &awidget) { m_widget_list.append(awidget); } type()91 Type type() const { return m_type; } setType(Type atype)92 void setType(Type atype) { m_type = atype; } 93 isNull()94 bool isNull() const { return m_name.isEmpty(); } 95 96 private: 97 QString m_name; 98 Type m_type; 99 QList<Widget> m_widget_list; 100 }; 101 using CategoryList = QList<Category>; 102 103 explicit QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags()); 104 virtual ~QDesignerWidgetBoxInterface(); 105 106 virtual int categoryCount() const = 0; 107 virtual Category category(int cat_idx) const = 0; 108 virtual void addCategory(const Category &cat) = 0; 109 virtual void removeCategory(int cat_idx) = 0; 110 111 virtual int widgetCount(int cat_idx) const = 0; 112 virtual Widget widget(int cat_idx, int wgt_idx) const = 0; 113 virtual void addWidget(int cat_idx, const Widget &wgt) = 0; 114 virtual void removeWidget(int cat_idx, int wgt_idx) = 0; 115 116 int findOrInsertCategory(const QString &categoryName); 117 118 virtual void dropWidgets(const QList<QDesignerDnDItemInterface*> &item_list, 119 const QPoint &global_mouse_pos) = 0; 120 121 virtual void setFileName(const QString &file_name) = 0; 122 virtual QString fileName() const = 0; 123 virtual bool load() = 0; 124 virtual bool save() = 0; 125 }; 126 127 QT_END_NAMESPACE 128 129 Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QDesignerWidgetBoxInterface::Widget)) 130 131 #endif // ABSTRACTWIDGETBOX_H 132