OSDN Git Service

Update license.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / designer / qt_private / qsimpleresource_p.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (info@qt.nokia.com)
8 **
9 **
10 ** GNU Lesser General Public License Usage
11 **
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.
18 **
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.
22 **
23 ** Other Usage
24 **
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.
27 **
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
30 **
31 **************************************************************************/
32
33 //
34 //  W A R N I N G
35 //  -------------
36 //
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.
40 //
41 // We mean it.
42 //
43
44 #ifndef QSIMPLERESOURCE_H
45 #define QSIMPLERESOURCE_H
46
47 #include "shared_global_p.h"
48 #include "abstractformbuilder.h"
49 #include <QtCore/QStringList>
50
51 QT_BEGIN_NAMESPACE
52
53 class DomScript;
54 class DomCustomWidgets;
55 class DomCustomWidget;
56 class DomSlots;
57
58 class QDesignerFormEditorInterface;
59
60 namespace qdesigner_internal {
61
62 class WidgetDataBaseItem;
63
64 class QDESIGNER_SHARED_EXPORT QSimpleResource : public QAbstractFormBuilder
65 {
66 public:
67     explicit QSimpleResource(QDesignerFormEditorInterface *core);
68     virtual ~QSimpleResource();
69
70     QBrush setupBrush(DomBrush *brush);
71     DomBrush *saveBrush(const QBrush &brush);
72
73     inline QDesignerFormEditorInterface *core() const
74     { return m_core; }
75
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,
83                                           bool applyState);
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);
91
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);
96
97 protected:
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;
104
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);
109
110     static bool addFakeMethods(const DomSlots *domSlots, QStringList &fakeSlots, QStringList &fakeSignals);
111
112 private:
113     static void addCustomWidgetsToWidgetDatabase(const QDesignerFormEditorInterface *core,
114                                                  QList<DomCustomWidget*>& custom_widget_list);
115     static void addFakeMethodsToWidgetDataBase(const DomCustomWidget *domCustomWidget, WidgetDataBaseItem *item);
116
117     static bool m_warningsEnabled;
118     QDesignerFormEditorInterface *m_core;
119 };
120
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;
125
126     FormBuilderClipboard() {}
127     FormBuilderClipboard(QWidget *w);
128
129     bool empty() const;
130
131     QWidgetList m_widgets;
132     ActionList m_actions;
133 };
134
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
138 {
139 public:
140     explicit QEditorFormBuilder(QDesignerFormEditorInterface *core) : QSimpleResource(core) {}
141
142     virtual bool copy(QIODevice *dev, const FormBuilderClipboard &selection) = 0;
143     virtual DomUI *copy(const FormBuilderClipboard &selection) = 0;
144
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;
149 };
150
151 } // namespace qdesigner_internal
152
153 QT_END_NAMESPACE
154
155 #endif