source: trunk/examples/designer/containerextension/multipagewidgetplugin.cpp@ 846

Last change on this file since 846 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

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