| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the examples of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include <QtDesigner/QExtensionFactory>
|
|---|
| 43 | #include <QtDesigner/QExtensionManager>
|
|---|
| 44 | #include <QtDesigner/QDesignerFormEditorInterface>
|
|---|
| 45 | #include <QtDesigner/QDesignerFormWindowInterface>
|
|---|
| 46 | #include <QtDesigner/QDesignerContainerExtension>
|
|---|
| 47 | #include <QtDesigner/QDesignerPropertySheetExtension>
|
|---|
| 48 |
|
|---|
| 49 | #include <QIcon>
|
|---|
| 50 | #include <QtPlugin>
|
|---|
| 51 |
|
|---|
| 52 | #include "multipagewidget.h"
|
|---|
| 53 | #include "multipagewidgetplugin.h"
|
|---|
| 54 | #include "multipagewidgetextensionfactory.h"
|
|---|
| 55 |
|
|---|
| 56 | //! [0]
|
|---|
| 57 | MultiPageWidgetPlugin::MultiPageWidgetPlugin(QObject *parent)
|
|---|
| 58 | :QObject(parent)
|
|---|
| 59 | {
|
|---|
| 60 | initialized = false;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | QString MultiPageWidgetPlugin::name() const
|
|---|
| 64 | {
|
|---|
| 65 | return QLatin1String("MultiPageWidget");
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 | QString MultiPageWidgetPlugin::group() const
|
|---|
| 69 | {
|
|---|
| 70 | return QLatin1String("Display Widgets [Examples]");
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | QString MultiPageWidgetPlugin::toolTip() const
|
|---|
| 74 | {
|
|---|
| 75 | return QString();
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | QString MultiPageWidgetPlugin::whatsThis() const
|
|---|
| 79 | {
|
|---|
| 80 | return QString();
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | QString MultiPageWidgetPlugin::includeFile() const
|
|---|
| 84 | {
|
|---|
| 85 | return QLatin1String("multipagewidget.h");
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | QIcon MultiPageWidgetPlugin::icon() const
|
|---|
| 89 | {
|
|---|
| 90 | return QIcon();
|
|---|
| 91 | }
|
|---|
| 92 |
|
|---|
| 93 | //! [0] //! [1]
|
|---|
| 94 | bool MultiPageWidgetPlugin::isContainer() const
|
|---|
| 95 | {
|
|---|
| 96 | return true;
|
|---|
| 97 | }
|
|---|
| 98 |
|
|---|
| 99 | //! [1] //! [2]
|
|---|
| 100 | QWidget *MultiPageWidgetPlugin::createWidget(QWidget *parent)
|
|---|
| 101 | {
|
|---|
| 102 | MultiPageWidget *widget = new MultiPageWidget(parent);
|
|---|
| 103 | connect(widget, SIGNAL(currentIndexChanged(int)),
|
|---|
| 104 | this, SLOT(currentIndexChanged(int)));
|
|---|
| 105 | connect(widget, SIGNAL(pageTitleChanged(const QString &)),
|
|---|
| 106 | this, SLOT(pageTitleChanged(const QString &)));
|
|---|
| 107 | return widget;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | //! [2] //! [3]
|
|---|
| 111 | bool MultiPageWidgetPlugin::isInitialized() const
|
|---|
| 112 | {
|
|---|
| 113 | return initialized;
|
|---|
| 114 | }
|
|---|
| 115 | //! [3]
|
|---|
| 116 |
|
|---|
| 117 | //! [4]
|
|---|
| 118 | void MultiPageWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor)
|
|---|
| 119 | {
|
|---|
| 120 | if (initialized)
|
|---|
| 121 | return;
|
|---|
| 122 | //! [4]
|
|---|
| 123 |
|
|---|
| 124 | //! [5]
|
|---|
| 125 | QExtensionManager *manager = formEditor->extensionManager();
|
|---|
| 126 | //! [5] //! [6]
|
|---|
| 127 | QExtensionFactory *factory = new MultiPageWidgetExtensionFactory(manager);
|
|---|
| 128 |
|
|---|
| 129 | Q_ASSERT(manager != 0);
|
|---|
| 130 | manager->registerExtensions(factory, Q_TYPEID(QDesignerContainerExtension));
|
|---|
| 131 |
|
|---|
| 132 | initialized = true;
|
|---|
| 133 | }
|
|---|
| 134 | //! [6]
|
|---|
| 135 |
|
|---|
| 136 | //! [7]
|
|---|
| 137 | QString MultiPageWidgetPlugin::domXml() const
|
|---|
| 138 | {
|
|---|
| 139 | return QLatin1String("\
|
|---|
| 140 | <ui language=\"c++\">\
|
|---|
| 141 | <widget class=\"MultiPageWidget\" name=\"multipagewidget\">\
|
|---|
| 142 | <widget class=\"QWidget\" name=\"page\" />\
|
|---|
| 143 | </widget>\
|
|---|
| 144 | <customwidgets>\
|
|---|
| 145 | <customwidget>\
|
|---|
| 146 | <class>MultiPageWidget</class>\
|
|---|
| 147 | <extends>QWidget</extends>\
|
|---|
| 148 | <addpagemethod>addPage</addpagemethod>\
|
|---|
| 149 | </customwidget>\
|
|---|
| 150 | </customwidgets>\
|
|---|
| 151 | </ui>");
|
|---|
| 152 | }
|
|---|
| 153 | //! [7]
|
|---|
| 154 |
|
|---|
| 155 | //! [8]
|
|---|
| 156 | void MultiPageWidgetPlugin::currentIndexChanged(int index)
|
|---|
| 157 | {
|
|---|
| 158 | Q_UNUSED(index);
|
|---|
| 159 | MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(sender());
|
|---|
| 160 | //! [8] //! [9]
|
|---|
| 161 | if (widget) {
|
|---|
| 162 | QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(widget);
|
|---|
| 163 | if (form)
|
|---|
| 164 | form->emitSelectionChanged();
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 | //! [9]
|
|---|
| 168 |
|
|---|
| 169 | //! [10]
|
|---|
| 170 | void MultiPageWidgetPlugin::pageTitleChanged(const QString &title)
|
|---|
| 171 | {
|
|---|
| 172 | Q_UNUSED(title);
|
|---|
| 173 | MultiPageWidget *widget = qobject_cast<MultiPageWidget*>(sender());
|
|---|
| 174 | //! [10] //! [11]
|
|---|
| 175 | if (widget) {
|
|---|
| 176 | QWidget *page = widget->widget(widget->currentIndex());
|
|---|
| 177 | QDesignerFormWindowInterface *form;
|
|---|
| 178 | form = QDesignerFormWindowInterface::findFormWindow(widget);
|
|---|
| 179 | //! [11]
|
|---|
| 180 | if (form) {
|
|---|
| 181 | //! [12]
|
|---|
| 182 | QDesignerFormEditorInterface *editor = form->core();
|
|---|
| 183 | QExtensionManager *manager = editor->extensionManager();
|
|---|
| 184 | //! [12] //! [13]
|
|---|
| 185 | QDesignerPropertySheetExtension *sheet;
|
|---|
| 186 | sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, page);
|
|---|
| 187 | const int propertyIndex = sheet->indexOf(QLatin1String("windowTitle"));
|
|---|
| 188 | sheet->setChanged(propertyIndex, true);
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|
| 192 |
|
|---|
| 193 | //! [13]
|
|---|
| 194 |
|
|---|
| 195 | //! [14]
|
|---|
| 196 | Q_EXPORT_PLUGIN2(containerextension, MultiPageWidgetPlugin)
|
|---|
| 197 | //! [14]
|
|---|