diff options
Diffstat (limited to 'tools/designer/src/plugins/activeqt')
11 files changed, 1427 insertions, 0 deletions
diff --git a/tools/designer/src/plugins/activeqt/activeqt.pro b/tools/designer/src/plugins/activeqt/activeqt.pro new file mode 100644 index 0000000..f58df8a --- /dev/null +++ b/tools/designer/src/plugins/activeqt/activeqt.pro @@ -0,0 +1,32 @@ +TARGET = $$qtLibraryTarget(qaxwidget) +TEMPLATE = lib +QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/designer + +CONFIG += qt warn_on qaxcontainer plugin designer debug_and_release +build_all:!build_pass { + CONFIG -= build_all + CONFIG += release +} + +INCLUDEPATH += $$QT_SOURCE_TREE/src/activeqt/shared/ \ + $$QT_BUILD_TREE/src/activeqt/container \ + ../../lib/uilib + +# Input +SOURCES += qaxwidgetextrainfo.cpp \ +qaxwidgetplugin.cpp \ +qdesigneraxwidget.cpp \ +qaxwidgetpropertysheet.cpp \ +qaxwidgettaskmenu.cpp \ + $$QT_SOURCE_TREE/src/activeqt/shared/qaxtypes.cpp + +HEADERS += qaxwidgetextrainfo.h \ +qaxwidgetplugin.h \ +qdesigneraxwidget.h \ +qaxwidgetpropertysheet.h \ +qaxwidgettaskmenu.h \ + $$QT_SOURCE_TREE/src/activeqt/shared/qaxtypes.h + +# install +target.path = $$[QT_INSTALL_PLUGINS]/designer +INSTALLS += target diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.cpp b/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.cpp new file mode 100644 index 0000000..369cd7f --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaxwidgetextrainfo.h" +#include "qdesigneraxwidget.h" +#include "qaxwidgetpropertysheet.h" + +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/private/ui4_p.h> + +QT_BEGIN_NAMESPACE + +QAxWidgetExtraInfo::QAxWidgetExtraInfo(QDesignerAxWidget *widget, QDesignerFormEditorInterface *core, QObject *parent) + : QObject(parent), m_widget(widget), m_core(core) +{ +} + +QWidget *QAxWidgetExtraInfo::widget() const +{ + return m_widget; +} + +QDesignerFormEditorInterface *QAxWidgetExtraInfo::core() const +{ + return m_core; +} + +bool QAxWidgetExtraInfo::saveUiExtraInfo(DomUI *) +{ + return false; +} + +bool QAxWidgetExtraInfo::loadUiExtraInfo(DomUI *) +{ + return false; +} + +bool QAxWidgetExtraInfo::saveWidgetExtraInfo(DomWidget *ui_widget) +{ + /* Turn off standard setters and make sure "control" is in front, + * otherwise, previews will not work as the properties are not applied via + * the caching property sheet, them. */ + typedef QList<DomProperty *> DomPropertyList; + DomPropertyList props = ui_widget->elementProperty(); + const int size = props.size(); + const QString controlProperty = QLatin1String(QAxWidgetPropertySheet::controlPropertyName); + for (int i = 0; i < size; i++) { + props.at(i)->setAttributeStdset(false); + if (i > 0 && props.at(i)->attributeName() == controlProperty) { + qSwap(props[0], props[i]); + ui_widget->setElementProperty(props); + } + + } + return true; +} + +bool QAxWidgetExtraInfo::loadWidgetExtraInfo(DomWidget *) +{ + return false; +} + +QAxWidgetExtraInfoFactory::QAxWidgetExtraInfoFactory(QDesignerFormEditorInterface *core, QExtensionManager *parent) + : QExtensionFactory(parent), m_core(core) +{ +} + +QObject *QAxWidgetExtraInfoFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const +{ + if (iid != Q_TYPEID(QDesignerExtraInfoExtension)) + return 0; + + if (QDesignerAxWidget *w = qobject_cast<QDesignerAxWidget*>(object)) + return new QAxWidgetExtraInfo(w, m_core, parent); + + return 0; +} + +QT_END_NAMESPACE diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.h b/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.h new file mode 100644 index 0000000..343bb76 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetextrainfo.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ACTIVEQT_EXTRAINFO_H +#define ACTIVEQT_EXTRAINFO_H + +#include <QtDesigner/QDesignerExtraInfoExtension> +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QExtensionFactory> + +#include <QtCore/QPointer> + +QT_BEGIN_NAMESPACE + +class QDesignerAxWidget; + +class QAxWidgetExtraInfo: public QObject, public QDesignerExtraInfoExtension +{ + Q_OBJECT + Q_INTERFACES(QDesignerExtraInfoExtension) +public: + QAxWidgetExtraInfo(QDesignerAxWidget *widget, QDesignerFormEditorInterface *core, QObject *parent); + + virtual QWidget *widget() const; + virtual QDesignerFormEditorInterface *core() const; + + virtual bool saveUiExtraInfo(DomUI *ui); + virtual bool loadUiExtraInfo(DomUI *ui); + + virtual bool saveWidgetExtraInfo(DomWidget *ui_widget); + virtual bool loadWidgetExtraInfo(DomWidget *ui_widget); + +private: + QPointer<QDesignerAxWidget> m_widget; + QPointer<QDesignerFormEditorInterface> m_core; +}; + +class QAxWidgetExtraInfoFactory: public QExtensionFactory +{ + Q_OBJECT +public: + QAxWidgetExtraInfoFactory(QDesignerFormEditorInterface *core, QExtensionManager *parent = 0); + +protected: + virtual QObject *createExtension(QObject *object, const QString &iid, QObject *parent) const; + +private: + QDesignerFormEditorInterface *m_core; +}; + +QT_END_NAMESPACE + +#endif // ACTIVEQT_EXTRAINFO_H diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetplugin.cpp b/tools/designer/src/plugins/activeqt/qaxwidgetplugin.cpp new file mode 100644 index 0000000..f80df14 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetplugin.cpp @@ -0,0 +1,146 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaxwidgetplugin.h" +#include "qaxwidgetextrainfo.h" +#include "qdesigneraxwidget.h" +#include "qaxwidgetpropertysheet.h" +#include "qaxwidgettaskmenu.h" + +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QDesignerFormWindowInterface> + +#include <QtCore/qplugin.h> +#include <QtGui/QIcon> +#include <ActiveQt/QAxWidget> + +QT_BEGIN_NAMESPACE + +QAxWidgetPlugin::QAxWidgetPlugin(QObject *parent) : + QObject(parent), + m_core(0) +{ +} + +QString QAxWidgetPlugin::name() const +{ + return QLatin1String("QAxWidget"); +} + +QString QAxWidgetPlugin::group() const +{ + return QLatin1String("Containers"); +} + +QString QAxWidgetPlugin::toolTip() const +{ + return tr("ActiveX control"); +} + +QString QAxWidgetPlugin::whatsThis() const +{ + return tr("ActiveX control widget"); +} + +QString QAxWidgetPlugin::includeFile() const +{ + return QLatin1String("qaxwidget.h"); +} + +QIcon QAxWidgetPlugin::icon() const +{ + return QIcon(QDesignerAxWidget::widgetIcon()); +} + +bool QAxWidgetPlugin::isContainer() const +{ + return false; +} + +QWidget *QAxWidgetPlugin::createWidget(QWidget *parent) +{ + // Construction from Widget box or on a form? + const bool isFormEditor = parent != 0 && QDesignerFormWindowInterface::findFormWindow(parent) != 0; + QDesignerAxWidget *rc = new QDesignerAxPluginWidget(parent); + if (!isFormEditor) + rc->setDrawFlags(QDesignerAxWidget::DrawFrame|QDesignerAxWidget::DrawControl); + return rc; +} + +bool QAxWidgetPlugin::isInitialized() const +{ + return m_core != 0; +} + +void QAxWidgetPlugin::initialize(QDesignerFormEditorInterface *core) +{ + if (m_core != 0) + return; + + m_core = core; + + QExtensionManager *mgr = core->extensionManager(); + ActiveXPropertySheetFactory::registerExtension(mgr); + ActiveXTaskMenuFactory::registerExtension(mgr, Q_TYPEID(QDesignerTaskMenuExtension)); + QAxWidgetExtraInfoFactory *extraInfoFactory = new QAxWidgetExtraInfoFactory(core, mgr); + mgr->registerExtensions(extraInfoFactory, Q_TYPEID(QDesignerExtraInfoExtension)); +} + +QString QAxWidgetPlugin::domXml() const +{ + return QLatin1String("\ +<ui language=\"c++\">\ + <widget class=\"QAxWidget\" name=\"axWidget\">\ + <property name=\"geometry\">\ + <rect>\ + <x>0</x>\ + <y>0</y>\ + <width>80</width>\ + <height>70</height>\ + </rect>\ + </property>\ + </widget>\ +</ui>"); +} + +Q_EXPORT_PLUGIN(QAxWidgetPlugin) + +QT_END_NAMESPACE diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetplugin.h b/tools/designer/src/plugins/activeqt/qaxwidgetplugin.h new file mode 100644 index 0000000..662c490 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetplugin.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef ACTIVEXPLUGIN_H +#define ACTIVEXPLUGIN_H + +#include <QtDesigner/QDesignerCustomWidgetInterface> +#include <QtCore/QObject> + +QT_BEGIN_NAMESPACE + +class QDesignerFormEditorInterface; + +class QAxWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface +{ + Q_OBJECT + Q_INTERFACES(QDesignerCustomWidgetInterface) +public: + explicit inline QAxWidgetPlugin(QObject *parent = 0); + + virtual QString name() const; + virtual QString group() const; + virtual QString toolTip() const; + virtual QString whatsThis() const; + virtual QString includeFile() const; + virtual QIcon icon() const; + virtual bool isContainer() const; + virtual QWidget *createWidget(QWidget *parent); + virtual bool isInitialized() const; + virtual void initialize(QDesignerFormEditorInterface *core); + virtual QString domXml() const; + +private: + QDesignerFormEditorInterface *m_core; +}; + +QT_END_NAMESPACE + +#endif diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp b/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp new file mode 100644 index 0000000..f94da88 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.cpp @@ -0,0 +1,189 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaxwidgetpropertysheet.h" +#include "qdesigneraxwidget.h" + +#include <QtDesigner/QDesignerMemberSheetExtension> +#include <QtDesigner/QDesignerFormWindowInterface> +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QDesignerPropertyEditorInterface> + +#include <QtDesigner/QExtensionManager> +#include <QtCore/QDebug> +#include <QtCore/QTimer> + +static const char *geometryPropertyC = "geometry"; + +QT_BEGIN_NAMESPACE + +const char *QAxWidgetPropertySheet::controlPropertyName = "control"; + +QAxWidgetPropertySheet::QAxWidgetPropertySheet(QDesignerAxWidget *object, QObject *parent) : + QDesignerPropertySheet(object, parent), + m_controlProperty(controlPropertyName), + m_propertyGroup(QLatin1String("QAxWidget")) +{ + if (!axWidget()->loaded()) { // For some obscure reason.... + const int controlIndex = QDesignerPropertySheet::indexOf(m_controlProperty); + setPropertyGroup(controlIndex, m_propertyGroup); + } +} + +bool QAxWidgetPropertySheet::isEnabled(int index) const +{ + if (propertyName(index) == m_controlProperty) + return false; + return QDesignerPropertySheet::isEnabled(index); +} + +bool QAxWidgetPropertySheet::dynamicPropertiesAllowed() const +{ + return false; +} + +QDesignerAxWidget *QAxWidgetPropertySheet::axWidget() const +{ + return static_cast<QDesignerAxWidget*>(object()); +} + +// Reload as the meta object changes. +bool QAxWidgetPropertySheet::reset(int index) +{ + const QString name = propertyName(index); + QMap<QString, QVariant>::iterator it = m_currentProperties.changedProperties.find(name); + if (it != m_currentProperties.changedProperties.end()) + m_currentProperties.changedProperties.erase(it); + if (name != m_controlProperty) + return QDesignerPropertySheet::reset(index); + axWidget()->resetControl(); + QTimer::singleShot(0, this, SLOT(updatePropertySheet())); + return true; +} + +void QAxWidgetPropertySheet::setProperty(int index, const QVariant &value) +{ + + // take care of all changed properties + const QString name = propertyName(index); + m_currentProperties.changedProperties[name] = value; + if (name != m_controlProperty) { + QDesignerPropertySheet::setProperty(index, value); + return; + } + // Loading forms: Reload + if (name == m_controlProperty) { + const QString clsid = value.toString(); + if (clsid.isEmpty() || !axWidget()->loadControl(clsid)) + reset(index); + else + QTimer::singleShot(100, this, SLOT(updatePropertySheet())); + } +} + +int QAxWidgetPropertySheet::indexOf(const QString &name) const +{ + const int index = QDesignerPropertySheet::indexOf(name); + if (index != -1) + return index; + // Loading before recreation of sheet in timer slot: Add a fake property to store the value + const QVariant dummValue(0); + QAxWidgetPropertySheet *that = const_cast<QAxWidgetPropertySheet *>(this); + const int newIndex = that->createFakeProperty(name, dummValue); + that->setPropertyGroup(newIndex, m_propertyGroup); + return newIndex; +} + +void QAxWidgetPropertySheet::updatePropertySheet() +{ + // refresh the property sheet (we are deleting m_currentProperties) + struct SavedProperties tmp = m_currentProperties; + QDesignerAxWidget *axw = axWidget(); + QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(axw); + Q_ASSERT(formWin != 0); + tmp.widget = axw; + tmp.clsid = axw->control(); + // Delete the sheets as they cache the meta object and other information + delete this; + delete qt_extension<QDesignerMemberSheetExtension *>(formWin->core()->extensionManager(), axw); + reloadPropertySheet(tmp, formWin); +} + +void QAxWidgetPropertySheet::reloadPropertySheet(const struct SavedProperties &properties, QDesignerFormWindowInterface *formWin) +{ + QDesignerFormEditorInterface *core = formWin->core(); + //Recreation of the property sheet + QDesignerPropertySheetExtension *sheet = qt_extension<QDesignerPropertySheetExtension *>(core->extensionManager(), properties.widget); + + bool foundGeometry = false; + const QString geometryProperty = QLatin1String(geometryPropertyC); + const SavedProperties::NamePropertyMap::const_iterator cend = properties.changedProperties.constEnd(); + for (SavedProperties::NamePropertyMap::const_iterator i = properties.changedProperties.constBegin(); i != cend; ++i) { + const QString name = i.key(); + const int index = sheet->indexOf(name); + if (index == -1) + continue; + // filter out geometry as this will resize the control + // to is default size even if it is attached to an layout + // but set the changed flag to work around preview bug... + if (name == geometryProperty) { + sheet->setChanged(index, true); + foundGeometry = true; + continue; + } + if (name == QLatin1String(controlPropertyName)) { + sheet->setChanged(index, !i.value().toString().isEmpty()); + continue; + } + sheet->setChanged(index, true); + sheet->setProperty(index, i.value()); + } + + if (!foundGeometry) // Make sure geometry is always changed in Designer + sheet->setChanged(sheet->indexOf(geometryProperty), true); + + if (core->propertyEditor()->object() == properties.widget) { + formWin->clearSelection(true); + formWin->selectWidget(properties.widget); + } +} + +QT_END_NAMESPACE diff --git a/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.h b/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.h new file mode 100644 index 0000000..64caf3c --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgetpropertysheet.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QACTIVEXPROPERTYSHEET_H +#define QACTIVEXPROPERTYSHEET_H + +#include <QtDesigner/private/qdesigner_propertysheet_p.h> + +QT_BEGIN_NAMESPACE + +class QDesignerAxWidget; +class QDesignerFormWindowInterface; + +/* The propertysheet has a method to delete itself and repopulate + * if the "control" property changes. Pre 4.5, the control property + * might not be the first one, so, the properties are stored and + * re-applied. If the "control" is the first one, it should be + * sufficient to reapply the changed flags, however, care must be taken when + * resetting the control. + * Resetting a control: The current behaviour is that the modified Active X properties are added again + * as Fake-Properties, which is a nice side-effect as not cause a loss. */ + +class QAxWidgetPropertySheet: public QDesignerPropertySheet +{ + Q_OBJECT + Q_INTERFACES(QDesignerPropertySheetExtension) +public: + explicit QAxWidgetPropertySheet(QDesignerAxWidget *object, QObject *parent = 0); + + virtual bool isEnabled(int index) const; + virtual void setProperty(int index, const QVariant &value); + virtual bool reset(int index); + int indexOf(const QString &name) const; + bool dynamicPropertiesAllowed() const; + + static const char *controlPropertyName; + +public slots: + void updatePropertySheet(); + +private: + QDesignerAxWidget *axWidget() const; + + const QString m_controlProperty; + const QString m_propertyGroup; + int m_controlIndex; + struct SavedProperties { + typedef QMap<QString, QVariant> NamePropertyMap; + NamePropertyMap changedProperties; + QWidget *widget; + QString clsid; + } m_currentProperties; + + static void reloadPropertySheet(const struct SavedProperties &properties, QDesignerFormWindowInterface *formWin); +}; + +typedef QDesignerPropertySheetFactory<QDesignerAxWidget, QAxWidgetPropertySheet> ActiveXPropertySheetFactory; + +QT_END_NAMESPACE + +#endif diff --git a/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp b/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp new file mode 100644 index 0000000..96b209f --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.cpp @@ -0,0 +1,186 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qaxwidgettaskmenu.h" +#include "qdesigneraxwidget.h" +#include "qaxwidgetpropertysheet.h" + +#include <QtDesigner/QDesignerFormWindowInterface> +#include <QtDesigner/QDesignerFormWindowCursorInterface> +#include <QtDesigner/QDesignerFormEditorInterface> +#include <QtDesigner/QExtensionManager> + +#include <QtGui/QUndoCommand> +#include <QtGui/QMessageBox> +#include <QtGui/QUndoStack> +#include <QtCore/QUuid> +#include <ActiveQt/qaxselect.h> + +#include <olectl.h> +#include <qaxtypes.h> + +QT_BEGIN_NAMESPACE + +/* SetControlCommand: An undo commands that sets a control bypassing + Designer's property system which cannot handle the changing + of the 'control' property's index and other cached information + when modifying it. */ + +class SetControlCommand : public QUndoCommand +{ +public: + SetControlCommand(QDesignerAxWidget *ax, QDesignerFormWindowInterface *core, const QString &newClsid = QString()); + + virtual void redo() { apply(m_newClsid); } + virtual void undo() { apply(m_oldClsid); } + +private: + bool apply(const QString &clsid); + + QDesignerAxWidget *m_axWidget; + QDesignerFormWindowInterface *m_formWindow; + QString m_oldClsid; + QString m_newClsid; +}; + +SetControlCommand::SetControlCommand(QDesignerAxWidget *ax, QDesignerFormWindowInterface *fw, const QString &newClsid) : + m_axWidget(ax), + m_formWindow(fw), + m_oldClsid(ax->control()), + m_newClsid(newClsid) +{ + if (m_newClsid.isEmpty()) + setText(QDesignerAxWidget::tr("Reset control")); + else + setText(QDesignerAxWidget::tr("Set control")); +} + +bool SetControlCommand::apply(const QString &clsid) +{ + if (m_oldClsid == m_newClsid) + return true; + + QObject *ext = m_formWindow->core()->extensionManager()->extension(m_axWidget, Q_TYPEID(QDesignerPropertySheetExtension)); + QAxWidgetPropertySheet *sheet = qobject_cast<QAxWidgetPropertySheet*>(ext); + if (!sheet) + return false; + + const bool hasClsid = !clsid.isEmpty(); + const int index = sheet->indexOf(QLatin1String(QAxWidgetPropertySheet::controlPropertyName)); + if (hasClsid) + sheet->setProperty(index, clsid); + else + sheet->reset(index); + return true; +} + +// -------------------- QAxWidgetTaskMenu +QAxWidgetTaskMenu::QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent) : + QObject(parent), + m_axwidget(object), + m_setAction(new QAction(tr("Set Control"), this)), + m_resetAction(new QAction(tr("Reset Control"), this)) +{ + connect(m_setAction, SIGNAL(triggered()), this, SLOT(setActiveXControl())); + connect(m_resetAction, SIGNAL(triggered()), this, SLOT(resetActiveXControl())); + m_taskActions.push_back(m_setAction); + m_taskActions.push_back(m_resetAction); +} + +QAxWidgetTaskMenu::~QAxWidgetTaskMenu() +{ +} + +QList<QAction*> QAxWidgetTaskMenu::taskActions() const +{ + const bool loaded = m_axwidget->loaded(); + m_setAction->setEnabled(!loaded); + m_resetAction->setEnabled(loaded); + return m_taskActions; +} + +void QAxWidgetTaskMenu::resetActiveXControl() +{ + QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); + Q_ASSERT(formWin != 0); + formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin)); +} + +void QAxWidgetTaskMenu::setActiveXControl() +{ + QAxSelect *dialog = new QAxSelect(m_axwidget->topLevelWidget()); + if (dialog->exec()) { + QUuid clsid = dialog->clsid(); + QString key; + + IClassFactory2 *cf2 = 0; + CoGetClassObject(clsid, CLSCTX_SERVER, 0, IID_IClassFactory2, (void**)&cf2); + + if (cf2) { + BSTR bKey; + HRESULT hres = cf2->RequestLicKey(0, &bKey); + if (hres == CLASS_E_NOTLICENSED) { + QMessageBox::warning(m_axwidget->topLevelWidget(), tr("Licensed Control"), + tr("The control requires a design-time license")); + clsid = QUuid(); + } else { + key = QString::fromUtf16((ushort *)bKey); + } + + cf2->Release(); + } + + if (!clsid.isNull()) { + QDesignerFormWindowInterface *formWin = QDesignerFormWindowInterface::findFormWindow(m_axwidget); + + Q_ASSERT(formWin != 0); + QString value = clsid.toString(); + if (!key.isEmpty()) { + value += QLatin1Char(':'); + value += key; + } + formWin->commandHistory()->push(new SetControlCommand(m_axwidget, formWin, value)); + } + } + delete dialog; +} + +QT_END_NAMESPACE diff --git a/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.h b/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.h new file mode 100644 index 0000000..9520673 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qaxwidgettaskmenu.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QACTIVEXTASKMENU_H +#define QACTIVEXTASKMENU_H + +#include <QtDesigner/QDesignerTaskMenuExtension> +#include <QtDesigner/private/extensionfactory_p.h> + +QT_BEGIN_NAMESPACE + +class QDesignerAxWidget; + +class QAxWidgetTaskMenu: public QObject, public QDesignerTaskMenuExtension +{ + Q_OBJECT + Q_INTERFACES(QDesignerTaskMenuExtension) +public: + explicit QAxWidgetTaskMenu(QDesignerAxWidget *object, QObject *parent = 0); + virtual ~QAxWidgetTaskMenu(); + virtual QList<QAction*> taskActions() const; + +private slots: + void setActiveXControl(); + void resetActiveXControl(); + +private: + QDesignerAxWidget *m_axwidget; + QAction *m_setAction; + QAction *m_resetAction; + QList<QAction*> m_taskActions; +}; + +typedef qdesigner_internal::ExtensionFactory<QDesignerTaskMenuExtension, QDesignerAxWidget, QAxWidgetTaskMenu> ActiveXTaskMenuFactory; + +QT_END_NAMESPACE + +#endif // QACTIVEXTASKMENU diff --git a/tools/designer/src/plugins/activeqt/qdesigneraxwidget.cpp b/tools/designer/src/plugins/activeqt/qdesigneraxwidget.cpp new file mode 100644 index 0000000..48245f1 --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qdesigneraxwidget.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qdesigneraxwidget.h" + +#include <QtCore/QMetaProperty> +#include <QtCore/QDebug> +#include <QtGui/QIcon> +#include <QtGui/QPainter> +#include <QtGui/QResizeEvent> + +#include <ActiveQt/QAxWidget> + +#include <olectl.h> +#include <qaxtypes.h> + +enum { debugAxWidget = 0 }; + +QT_BEGIN_NAMESPACE + +/* XPM */ +const char *widgetIconXPM[]={ +"22 22 6 1", +"a c #000000", +"# c #808080", +"+ c #aaa5a0", +"b c #dddddd", +"* c #d4d0c8", +". c none", +".........#aa#...#aa#..", +".........abba...abba..", +".........abba...abba..", +".........#aa#...#aa#..", +"..........aa.....aa...", +"..........aa.....aa...", +"..........aa.....aa...", +".......aaaaaaaaaaaaaaa", +".......a*************a", +".......a************#a", +".......a***********+#a", +".......a***********+#a", +".......a***********+#a", +"#aa#...a***********+#a", +"abbaaaaa***********+#a", +"abbaaaaa***********+#a", +"#aa#...a***********+#a", +".......a***********+#a", +".......a***********+#a", +".......a**++++++++++#a", +".......a*############a", +".......aaaaaaaaaaaaaaa"}; + +QDesignerAxWidget::QDesignerAxWidget(QWidget *parent) : + QWidget(parent), + m_defaultSize(80, 70), + m_drawFlags(DrawIndicator|DrawFrame|DrawControl), + m_axobject(0), + m_axImage(widgetIcon()) +{ +} + +QDesignerAxWidget::~QDesignerAxWidget() +{ + delete m_axobject; +} + +QPixmap QDesignerAxWidget::widgetIcon() +{ + return QPixmap(widgetIconXPM); +} + +QString QDesignerAxWidget::control() const +{ + if (m_axobject) + return m_axobject->control(); + return QString(); +} + +void QDesignerAxWidget::setControl(const QString &clsid) +{ + if (clsid == control()) + return; + if (clsid.isEmpty()) { + resetControl(); + } else { + loadControl(clsid); + } +} +void QDesignerAxWidget::resetControl() +{ + if (!m_axobject) + return; + delete m_axobject; + m_axobject = 0; + update(); +} + +bool QDesignerAxWidget::loadControl(const QString &clsid) +{ + if (clsid.isEmpty()) + return false; + if (m_axobject) + resetControl(); + m_axobject = new QAxWidget(); + + if (!m_axobject->setControl(clsid)) { + delete m_axobject; + m_axobject = 0; + return false; + } + update(); + return true; +} + +QSize QDesignerAxWidget::sizeHint() const +{ + if (m_axobject) + return m_axobject->sizeHint(); + return m_defaultSize; +} + +QSize QDesignerAxWidget::minimumSizeHint() const +{ + if (m_axobject) + return m_axobject->minimumSizeHint(); + return QWidget::minimumSizeHint(); +} + +void QDesignerAxWidget::paintEvent(QPaintEvent * /*event */) +{ + QPainter p(this); + const QRect r = contentsRect(); + const int contentsWidth = r.width(); + const int contentsHeight= r.height(); + if (m_axobject) { // QAxWidget has no concept of sizeHint() + if (m_drawFlags & DrawControl) { + m_axobject->resize(size()); + m_axobject->render(&p); + } + if (m_drawFlags & DrawIndicator) { + static const QString loaded = tr("Control loaded"); + QColor patternColor(Qt::green); + if (m_drawFlags & DrawControl) + patternColor.setAlpha(80); + p.setBrush(QBrush(patternColor, Qt::BDiagPattern)); + p.setPen(Qt::black); + if (r.height() > 5) + p.drawText(5,contentsHeight - 5, loaded); + } + } + if (m_drawFlags & DrawFrame) { + p.drawRect(r.adjusted(0, 0, -1, -1)); + } + if (m_drawFlags & DrawIndicator) { + if (contentsWidth > m_axImage.width() && contentsHeight > m_axImage.height()) + p.drawPixmap((contentsWidth - m_axImage.width()) / 2, + (contentsHeight-m_axImage.height()) / 2, m_axImage); + } +} + +// --------- QDesignerAxPluginWidget +QDesignerAxPluginWidget::QDesignerAxPluginWidget(QWidget *parent) : + QDesignerAxWidget(parent) +{ +} + +QDesignerAxPluginWidget::~QDesignerAxPluginWidget() +{ +} + +const QMetaObject *QDesignerAxPluginWidget::metaObject() const +{ + if (const QAxWidget *aw = axobject()) + return aw->metaObject(); + + return QDesignerAxWidget::metaObject(); +} + +static QString msgComException(const QObject *o, const QMetaObject::Call call, int index) +{ + return QDesignerAxWidget::tr("A COM exception occurred when executing a meta call of type %1, index %2 of \"%3\"."). + arg(call).arg(index).arg(o->objectName()); +} + +int QDesignerAxPluginWidget::qt_metacall(QMetaObject::Call call, int signal, void **argv) +{ + QAxWidget *aw = axobject(); + if (!aw) + return QDesignerAxWidget::qt_metacall(call,signal,argv); + + + const QMetaObject *mo = metaObject(); + // Have base class handle inherited stuff (geometry, enabled...) + const bool inherited = call == QMetaObject::InvokeMetaMethod ? + (signal < mo->methodOffset()) : (signal < mo->propertyOffset()); + if (inherited) + return QDesignerAxWidget::qt_metacall(call, signal, argv); + + int rc = -1; +#ifndef QT_NO_EXCEPTIONS + try { +#endif + if (debugAxWidget) + if (call != QMetaObject::InvokeMetaMethod) + qDebug() << objectName() << call << signal << mo->property(signal).name(); + switch (call) { + case QMetaObject::QueryPropertyStored: // Pretend all changed properties are stored for them to be saved + if (m_propValues.contains(signal)) + if (argv[0]) + *reinterpret_cast< bool*>(argv[0]) = true; + break; + case QMetaObject::ResetProperty: + rc = aw->qt_metacall(call, signal, argv); + update(); + m_propValues.remove(signal); + break; + case QMetaObject::WriteProperty: + rc = aw->qt_metacall(call, signal, argv); + update(); + m_propValues.insert(signal, true); + break; + default: + rc = aw->qt_metacall(call, signal, argv); + break; + } +#ifndef QT_NO_EXCEPTIONS + } catch(...) { + qWarning(msgComException(this, call, signal).toUtf8()); + } +#endif + return rc; +} + +QT_END_NAMESPACE diff --git a/tools/designer/src/plugins/activeqt/qdesigneraxwidget.h b/tools/designer/src/plugins/activeqt/qdesigneraxwidget.h new file mode 100644 index 0000000..290ce8f --- /dev/null +++ b/tools/designer/src/plugins/activeqt/qdesigneraxwidget.h @@ -0,0 +1,142 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the Qt Designer of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain +** additional rights. These rights are described in the Nokia Qt LGPL +** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QACTIVEXPLUGINOBJECT_H +#define QACTIVEXPLUGINOBJECT_H + +#include <QtCore/QPointer> +#include <QtCore/QMap> +#include <QtGui/QWidget> +#include <QtGui/QPixmap> + +QT_BEGIN_NAMESPACE + +class QAxWidget; + +/* QDesignerAxWidget aggregates QAxWidget to keep it out of the event loop while applying + * properties directly. + * Thus, it is possible to set property values in designer that are out of range + * for the control, which might cause it to throw exceptions. + * + * QDesignerAxWidget is the base class following the internal naming + * conventions that makes the control property visible to the introspection interface. + * + * The trick to aggregate a QAxWidget is to overwrite the metaObject() function + * generated by moc to return the QMetaObject of QAxWidget. This is what QDesignerAxPluginWidget does. */ + +class QDesignerAxWidget : public QWidget +{ + Q_OBJECT + Q_PROPERTY(QString control READ control WRITE setControl RESET resetControl DESIGNABLE true) + Q_DISABLE_COPY(QDesignerAxWidget) + +protected: + explicit QDesignerAxWidget(QWidget *parent); + +public: + virtual ~QDesignerAxWidget(); + + bool loadControl(const QString &clsid); + + void resetControl(); + void setControl(const QString &clsid); + QString control() const; + + QSize sizeHint() const; + QSize minimumSizeHint() const; + + bool loaded() { return (m_axobject != 0); } + + static QPixmap widgetIcon(); + + enum { DrawIndicator = 0x1, DrawFrame = 0x2, DrawControl = 0x4 }; + + unsigned drawFlags() const { return m_drawFlags; } + void setDrawFlags(unsigned f) { m_drawFlags = f; } + +protected: + void paintEvent(QPaintEvent *event); + QAxWidget *axobject() const { return m_axobject; } + +private: + const QSize m_defaultSize; + unsigned m_drawFlags; + QAxWidget *m_axobject; + QPixmap m_axImage; +}; + +class QDesignerAxPluginWidget : public QDesignerAxWidget +{ + // No Q_OBJECT here! - meta functionality is overriden +public: + explicit QDesignerAxPluginWidget(QWidget *parent); + virtual ~QDesignerAxPluginWidget(); + + virtual const QMetaObject *metaObject() const; + virtual int qt_metacall(QMetaObject::Call, int, void **); + +private: + QMap<int, bool> m_propValues; +}; + +#if defined Q_CC_MSVC && _MSC_VER < 1300 +template <> inline QDesignerAxWidget *qobject_cast_helper<QDesignerAxWidget*>(QObject *o, QDesignerAxWidget*) +#else +template <> inline QDesignerAxWidget *qobject_cast<QDesignerAxWidget*>(QObject *o) +#endif +{ + if (!o) + return 0; + + // Unloaded state + if (strcmp(o->metaObject()->className(), "QDesignerAxWidget") == 0) + return static_cast<QDesignerAxPluginWidget*>(o); + + // Loaded state with fake meta object + if (strcmp(o->metaObject()->className(), "QAxWidget") == 0) + return static_cast<QDesignerAxPluginWidget*>(o); + + return 0; +} + +QT_END_NAMESPACE + +#endif // ACTIVEQT_EXTRAINFO_H |