1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
10 ** GNU Lesser General Public License Usage
12 ** This file may be used under the terms of the GNU Lesser General Public
13 ** License version 2.1 as published by the Free Software Foundation and
14 ** appearing in the file LICENSE.LGPL included in the packaging of this file.
15 ** Please review the following information to ensure the GNU Lesser General
16 ** Public License version 2.1 requirements will be met:
17 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
19 ** In addition, as a special exception, Nokia gives you certain additional
20 ** rights. These rights are described in the Nokia Qt LGPL Exception
21 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
25 ** Alternatively, this file may be used in accordance with the terms and
26 ** conditions contained in a signed written agreement between you and Nokia.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
31 **************************************************************************/
37 // This file is not part of the Qt API. It exists for the convenience
38 // of Qt Designer. This header
39 // file may change from version to version without notice, or even be removed.
44 #ifndef QSIMPLERESOURCE_H
45 #define QSIMPLERESOURCE_H
47 #include "shared_global_p.h"
48 #include "abstractformbuilder.h"
49 #include <QtCore/QStringList>
54 class DomCustomWidgets;
55 class DomCustomWidget;
58 class QDesignerFormEditorInterface;
60 namespace qdesigner_internal {
62 class WidgetDataBaseItem;
64 class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder
67 explicit QSimpleResource(QDesignerFormEditorInterface *core);
68 virtual ~QSimpleResource();
70 QBrush setupBrush(DomBrush *brush);
71 DomBrush *saveBrush(const QBrush &brush);
73 inline QDesignerFormEditorInterface *core() const
76 // Query extensions for additional data
77 static void addExtensionDataToDOM(QAbstractFormBuilder *afb,
78 QDesignerFormEditorInterface *core,
79 DomWidget *ui_widget, QWidget *widget);
80 static void applyExtensionDataFromDOM(QAbstractFormBuilder *afb,
81 QDesignerFormEditorInterface *core,
82 DomWidget *ui_widget, QWidget *widget,
84 // Enable warnings while saving. Turn off for backups.
85 static bool setWarningsEnabled(bool warningsEnabled);
86 static bool warningsEnabled();
87 // Return the script returned by the CustomWidget codeTemplate API
88 static QString customWidgetScript(QDesignerFormEditorInterface *core, QObject *object);
89 static QString customWidgetScript(QDesignerFormEditorInterface *core, const QString &className);
90 static bool hasCustomWidgetScript(QDesignerFormEditorInterface *core, QObject *object);
92 // Implementation for FormBuilder::createDomCustomWidgets() that adds
93 // the custom widgets to the widget database
94 static void handleDomCustomWidgets(const QDesignerFormEditorInterface *core,
95 const DomCustomWidgets *dom_custom_widgets);
98 virtual QIcon nameToIcon(const QString &filePath, const QString &qrcPath);
99 virtual QString iconToFilePath(const QIcon &pm) const;
100 virtual QString iconToQrcPath(const QIcon &pm) const;
101 virtual QPixmap nameToPixmap(const QString &filePath, const QString &qrcPath);
102 virtual QString pixmapToFilePath(const QPixmap &pm) const;
103 virtual QString pixmapToQrcPath(const QPixmap &pm) const;
105 enum ScriptSource { ScriptDesigner, ScriptExtension, ScriptCustomWidgetPlugin };
106 static DomScript*createScript(const QString &script, ScriptSource source);
107 typedef QList<DomScript*> DomScripts;
108 static void addScript(const QString &script, ScriptSource source, DomScripts &domScripts);
110 static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals);
113 static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
114 QList<DomCustomWidget*>& custom_widget_list);
115 static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item);
117 static bool m_warningsEnabled;
118 QDesignerFormEditorInterface *m_core;
121 // Contents of clipboard for formbuilder copy and paste operations
122 // (Actions and widgets)
123 struct QDESIGNER_SHARED_EXPORT FormBuilderClipboard {
124 typedef QList<QAction*> ActionList;
126 FormBuilderClipboard() {}
127 FormBuilderClipboard(QWidget *w);
131 QWidgetList m_widgets;
132 ActionList m_actions;
135 // Base class for a form builder used in the editor that
136 // provides copy and paste.(move into base interface)
137 class QDESIGNER_SHARED_EXPORT QEditorFormBuilder : public QSimpleResource
140 explicit QEditorFormBuilder(QDesignerFormEditorInterface *core) : QSimpleResource(core) {}
142 virtual bool copy(QIODevice *dev, const FormBuilderClipboard &selection) = 0;
143 virtual DomUI *copy(const FormBuilderClipboard &selection) = 0;
145 // A widget parent needs to be specified, otherwise, the widget factory cannot locate the form window via parent
146 // and thus is not able to construct special widgets (QLayoutWidget).
147 virtual FormBuilderClipboard paste(DomUI *ui, QWidget *widgetParent, QObject *actionParent = 0) = 0;
148 virtual FormBuilderClipboard paste(QIODevice *dev, QWidget *widgetParent, QObject *actionParent = 0) = 0;
151 } // namespace qdesigner_internal