|
| 1 | +#include <QtDesigner/QExtensionFactory> |
| 2 | +#include <QtDesigner/QExtensionManager> |
| 3 | +#include <QtDesigner/QDesignerFormEditorInterface> |
| 4 | +#include <QtDesigner/QDesignerFormWindowInterface> |
| 5 | +#include <QtDesigner/QDesignerContainerExtension> |
| 6 | +#include <QtDesigner/QDesignerPropertySheetExtension> |
| 7 | + |
| 8 | +#include "qtmaterialtabwidgetplugin.h" |
| 9 | +#include "qtmaterialtabwidget.h" |
| 10 | +#include "qtmaterialtabwidgetextensionfactory.h" |
| 11 | + |
| 12 | +QtMaterialTabWidgetPlugin::QtMaterialTabWidgetPlugin(QObject *parent) |
| 13 | + : QObject(parent) |
| 14 | +{ |
| 15 | +} |
| 16 | + |
| 17 | +QString QtMaterialTabWidgetPlugin::name() const |
| 18 | +{ |
| 19 | + return QLatin1String("QtMaterialTabWidget"); |
| 20 | +} |
| 21 | + |
| 22 | +QString QtMaterialTabWidgetPlugin::group() const |
| 23 | +{ |
| 24 | + return QLatin1String("Qt Material Widgets"); |
| 25 | +} |
| 26 | + |
| 27 | +QString QtMaterialTabWidgetPlugin::toolTip() const |
| 28 | +{ |
| 29 | + return QString(); |
| 30 | +} |
| 31 | + |
| 32 | +QString QtMaterialTabWidgetPlugin::whatsThis() const |
| 33 | +{ |
| 34 | + return QString(); |
| 35 | +} |
| 36 | + |
| 37 | +QString QtMaterialTabWidgetPlugin::includeFile() const |
| 38 | +{ |
| 39 | + return QLatin1String("qtmaterialtabwidget.h"); |
| 40 | +} |
| 41 | + |
| 42 | +QIcon QtMaterialTabWidgetPlugin::icon() const |
| 43 | +{ |
| 44 | + return QIcon(); |
| 45 | +} |
| 46 | + |
| 47 | +//! [0] //! [1] |
| 48 | +bool QtMaterialTabWidgetPlugin::isContainer() const |
| 49 | +{ |
| 50 | + return true; |
| 51 | +} |
| 52 | + |
| 53 | +//! [1] //! [2] |
| 54 | +QWidget *QtMaterialTabWidgetPlugin::createWidget(QWidget *parent) |
| 55 | +{ |
| 56 | + QtMaterialTabWidget *widget = new QtMaterialTabWidget(parent); |
| 57 | + connect(widget, &QtMaterialTabWidget::currentIndexChanged, |
| 58 | + this, &QtMaterialTabWidgetPlugin::currentIndexChanged); |
| 59 | + connect(widget, &QtMaterialTabWidget::pageTitleChanged, |
| 60 | + this, &QtMaterialTabWidgetPlugin::pageTitleChanged); |
| 61 | + return widget; |
| 62 | +} |
| 63 | + |
| 64 | +//! [2] //! [3] |
| 65 | +bool QtMaterialTabWidgetPlugin::isInitialized() const |
| 66 | +{ |
| 67 | + return initialized; |
| 68 | +} |
| 69 | +//! [3] |
| 70 | + |
| 71 | +//! [4] |
| 72 | +void QtMaterialTabWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor) |
| 73 | +{ |
| 74 | + if (initialized) |
| 75 | + return; |
| 76 | +//! [4] |
| 77 | + |
| 78 | +//! [5] |
| 79 | + QExtensionManager *manager = formEditor->extensionManager(); |
| 80 | +//! [5] //! [6] |
| 81 | + QExtensionFactory *factory = new QtMaterialTabWidgetExtensionFactory(manager); |
| 82 | + |
| 83 | + Q_ASSERT(manager != 0); |
| 84 | + manager->registerExtensions(factory, Q_TYPEID(QDesignerContainerExtension)); |
| 85 | + |
| 86 | + initialized = true; |
| 87 | +} |
| 88 | +//! [6] |
| 89 | + |
| 90 | +//! [7] |
| 91 | +QString QtMaterialTabWidgetPlugin::domXml() const |
| 92 | +{ |
| 93 | + return QLatin1String("\ |
| 94 | +<ui language=\"c++\">\ |
| 95 | + <widget class=\"QtMaterialTabWidget\" name=\"tabwidget\">\ |
| 96 | + <widget class=\"QWidget\" name=\"page\" />\ |
| 97 | + </widget>\ |
| 98 | + <customwidgets>\ |
| 99 | + <customwidget>\ |
| 100 | + <class>QtMaterialTabWidget</class>\ |
| 101 | + <extends>QWidget</extends>\ |
| 102 | + <addpagemethod>addPage</addpagemethod>\ |
| 103 | + </customwidget>\ |
| 104 | + </customwidgets>\ |
| 105 | +</ui>"); |
| 106 | +} |
| 107 | +//! [7] |
| 108 | + |
| 109 | +//! [8] |
| 110 | +void QtMaterialTabWidgetPlugin::currentIndexChanged(int index) |
| 111 | +{ |
| 112 | + Q_UNUSED(index); |
| 113 | + QtMaterialTabWidget *widget = qobject_cast<QtMaterialTabWidget*>(sender()); |
| 114 | +//! [8] //! [9] |
| 115 | + if (widget) { |
| 116 | + QDesignerFormWindowInterface *form = QDesignerFormWindowInterface::findFormWindow(widget); |
| 117 | + if (form) |
| 118 | + form->emitSelectionChanged(); |
| 119 | + } |
| 120 | +} |
| 121 | +//! [9] |
| 122 | + |
| 123 | +//! [10] |
| 124 | +void QtMaterialTabWidgetPlugin::pageTitleChanged(const QString &title) |
| 125 | +{ |
| 126 | + Q_UNUSED(title); |
| 127 | + QtMaterialTabWidget *widget = qobject_cast<QtMaterialTabWidget*>(sender()); |
| 128 | +//! [10] //! [11] |
| 129 | + if (widget) { |
| 130 | + QWidget *page = widget->widget(widget->currentIndex()); |
| 131 | + QDesignerFormWindowInterface *form; |
| 132 | + form = QDesignerFormWindowInterface::findFormWindow(widget); |
| 133 | +//! [11] |
| 134 | + if (form) { |
| 135 | +//! [12] |
| 136 | + QDesignerFormEditorInterface *editor = form->core(); |
| 137 | + QExtensionManager *manager = editor->extensionManager(); |
| 138 | +//! [12] //! [13] |
| 139 | + QDesignerPropertySheetExtension *sheet; |
| 140 | + sheet = qt_extension<QDesignerPropertySheetExtension*>(manager, page); |
| 141 | + const int propertyIndex = sheet->indexOf(QLatin1String("windowTitle")); |
| 142 | + sheet->setChanged(propertyIndex, true); |
| 143 | + } |
| 144 | + } |
| 145 | +} |
0 commit comments