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 examples of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:BSD$ |
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 | ** BSD License Usage |
18 | ** Alternatively, you may use this file under the terms of the BSD license |
19 | ** as follows: |
20 | ** |
21 | ** "Redistribution and use in source and binary forms, with or without |
22 | ** modification, are permitted provided that the following conditions are |
23 | ** met: |
24 | ** * Redistributions of source code must retain the above copyright |
25 | ** notice, this list of conditions and the following disclaimer. |
26 | ** * Redistributions in binary form must reproduce the above copyright |
27 | ** notice, this list of conditions and the following disclaimer in |
28 | ** the documentation and/or other materials provided with the |
29 | ** distribution. |
30 | ** * Neither the name of The Qt Company Ltd nor the names of its |
31 | ** contributors may be used to endorse or promote products derived |
32 | ** from this software without specific prior written permission. |
33 | ** |
34 | ** |
35 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
36 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
37 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
38 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
39 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
40 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
41 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
42 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
43 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
44 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
45 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." |
46 | ** |
47 | ** $QT_END_LICENSE$ |
48 | ** |
49 | ****************************************************************************/ |
50 | |
51 | #include <QtDesigner/QExtensionFactory> |
52 | #include <QtDesigner/QExtensionManager> |
53 | #include <QtDesigner/QDesignerFormEditorInterface> |
54 | #include <QtDesigner/QDesignerFormWindowInterface> |
55 | #include <QtDesigner/QDesignerContainerExtension> |
56 | #include <QtDesigner/QDesignerPropertySheetExtension> |
57 | |
58 | #include <QIcon> |
59 | #include <QtPlugin> |
60 | |
61 | #include "multipagewidget.h" |
62 | #include "multipagewidgetplugin.h" |
63 | #include "multipagewidgetextensionfactory.h" |
64 | |
65 | //! [0] |
66 | MultiPageWidgetPlugin::MultiPageWidgetPlugin(QObject *parent) |
67 | : QObject(parent) |
68 | { |
69 | } |
70 | |
71 | QString MultiPageWidgetPlugin::name() const |
72 | { |
73 | return QLatin1String("MultiPageWidget" ); |
74 | } |
75 | |
76 | QString MultiPageWidgetPlugin::group() const |
77 | { |
78 | return QLatin1String("Display Widgets [Examples]" ); |
79 | } |
80 | |
81 | QString MultiPageWidgetPlugin::toolTip() const |
82 | { |
83 | return QString(); |
84 | } |
85 | |
86 | QString MultiPageWidgetPlugin::whatsThis() const |
87 | { |
88 | return QString(); |
89 | } |
90 | |
91 | QString MultiPageWidgetPlugin::includeFile() const |
92 | { |
93 | return QLatin1String("multipagewidget.h" ); |
94 | } |
95 | |
96 | QIcon MultiPageWidgetPlugin::icon() const |
97 | { |
98 | return QIcon(); |
99 | } |
100 | |
101 | //! [0] //! [1] |
102 | bool MultiPageWidgetPlugin::isContainer() const |
103 | { |
104 | return true; |
105 | } |
106 | |
107 | //! [1] //! [2] |
108 | QWidget *MultiPageWidgetPlugin::createWidget(QWidget *parent) |
109 | { |
110 | MultiPageWidget *widget = new MultiPageWidget(parent); |
111 | connect(sender: widget, signal: &MultiPageWidget::currentIndexChanged, |
112 | receiver: this, slot: &MultiPageWidgetPlugin::currentIndexChanged); |
113 | connect(sender: widget, signal: &MultiPageWidget::pageTitleChanged, |
114 | receiver: this, slot: &MultiPageWidgetPlugin::pageTitleChanged); |
115 | return widget; |
116 | } |
117 | |
118 | //! [2] //! [3] |
119 | bool MultiPageWidgetPlugin::isInitialized() const |
120 | { |
121 | return initialized; |
122 | } |
123 | //! [3] |
124 | |
125 | //! [4] |
126 | void MultiPageWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor) |
127 | { |
128 | if (initialized) |
129 | return; |
130 | //! [4] |
131 | |
132 | //! [5] |
133 | QExtensionManager *manager = formEditor->extensionManager(); |
134 | //! [5] //! [6] |
135 | QExtensionFactory *factory = new MultiPageWidgetExtensionFactory(manager); |
136 | |
137 | Q_ASSERT(manager != 0); |
138 | manager->registerExtensions(factory, Q_TYPEID(QDesignerContainerExtension)); |
139 | |
140 | initialized = true; |
141 | } |
142 | //! [6] |
143 | |
144 | //! [7] |
145 | QString MultiPageWidgetPlugin::domXml() const |
146 | { |
147 | return QLatin1String("\ |
148 | <ui language=\"c++\">\ |
149 | <widget class=\"MultiPageWidget\" name=\"multipagewidget\">\ |
150 | <widget class=\"QWidget\" name=\"page\" />\ |
151 | </widget>\ |
152 | <customwidgets>\ |
153 | <customwidget>\ |
154 | <class>MultiPageWidget</class>\ |
155 | <extends>QWidget</extends>\ |
156 | <addpagemethod>addPage</addpagemethod>\ |
157 | </customwidget>\ |
158 | </customwidgets>\ |
159 | </ui>" ); |
160 | } |
161 | //! [7] |
162 | |
163 | //! [8] |
164 | void MultiPageWidgetPlugin::currentIndexChanged(int index) |
165 | { |
166 | Q_UNUSED(index); |
167 | MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(object: sender()); |
168 | //! [8] //! [9] |
169 | if (widget) { |
170 | QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(w: widget); |
171 | if (form) |
172 | form->emitSelectionChanged(); |
173 | } |
174 | } |
175 | //! [9] |
176 | |
177 | //! [10] |
178 | void MultiPageWidgetPlugin::pageTitleChanged(const QString &title) |
179 | { |
180 | Q_UNUSED(title); |
181 | MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(object: sender()); |
182 | //! [10] //! [11] |
183 | if (widget) { |
184 | QWidget *page = widget->widget(index: widget->currentIndex()); |
185 | QDesignerFormWindowInterface *form; |
186 | form = QDesignerFormWindowInterface::findFormWindow(w: widget); |
187 | //! [11] |
188 | if (form) { |
189 | //! [12] |
190 | QDesignerFormEditorInterface *editor = form->core(); |
191 | QExtensionManager *manager = editor->extensionManager(); |
192 | //! [12] //! [13] |
193 | QDesignerPropertySheetExtension *sheet; |
194 | sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, object: page); |
195 | const int propertyIndex = sheet->indexOf(name: QLatin1String("windowTitle" )); |
196 | sheet->setChanged(index: propertyIndex, changed: true); |
197 | } |
198 | } |
199 | } |
200 | |
201 | //! [13] |
202 | |