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 Qt Designer of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:GPL-EXCEPT$ 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 ** GNU General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU 19 ** General Public License version 3 as published by the Free Software 20 ** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT 21 ** included in the packaging of this file. Please review the following 22 ** information to ensure the GNU General Public License requirements will 23 ** be met: https://www.gnu.org/licenses/gpl-3.0.html. 24 ** 25 ** $QT_END_LICENSE$ 26 ** 27 ****************************************************************************/ 28 29 #ifndef QACTIVEXPLUGINOBJECT_H 30 #define QACTIVEXPLUGINOBJECT_H 31 32 #include <QtCore/qpointer.h> 33 #include <QtCore/qmap.h> 34 #include <QtWidgets/qwidget.h> 35 #include <QtGui/qpixmap.h> 36 37 QT_BEGIN_NAMESPACE 38 39 class QAxWidget; 40 41 /* QDesignerAxWidget aggregates QAxWidget to keep it out of the event loop while applying 42 * properties directly. 43 * Thus, it is possible to set property values in designer that are out of range 44 * for the control, which might cause it to throw exceptions. 45 * 46 * QDesignerAxWidget is the base class following the internal naming 47 * conventions that makes the control property visible to the introspection interface. 48 * 49 * The trick to aggregate a QAxWidget is to overwrite the metaObject() function 50 * generated by moc to return the QMetaObject of QAxWidget. This is what QDesignerAxPluginWidget does. */ 51 52 class QDesignerAxWidget : public QWidget 53 { 54 Q_OBJECT 55 Q_PROPERTY(QString control READ control WRITE setControl RESET resetControl DESIGNABLE true) 56 Q_DISABLE_COPY_MOVE(QDesignerAxWidget) 57 58 protected: 59 explicit QDesignerAxWidget(QWidget *parent); 60 61 public: 62 virtual ~QDesignerAxWidget(); 63 64 bool loadControl(const QString &clsid); 65 66 void resetControl(); 67 void setControl(const QString &clsid); 68 QString control() const; 69 70 QSize sizeHint() const; 71 QSize minimumSizeHint() const; 72 loaded()73 bool loaded() { return (m_axobject != 0); } 74 75 static QPixmap widgetIcon(); 76 77 enum { DrawIndicator = 0x1, DrawFrame = 0x2, DrawControl = 0x4 }; 78 drawFlags()79 unsigned drawFlags() const { return m_drawFlags; } setDrawFlags(unsigned f)80 void setDrawFlags(unsigned f) { m_drawFlags = f; } 81 82 protected: 83 void paintEvent(QPaintEvent *event); axobject()84 QAxWidget *axobject() const { return m_axobject; } 85 86 private: 87 const QSize m_defaultSize { 80, 70 }; 88 unsigned m_drawFlags = DrawIndicator | DrawFrame | DrawControl; 89 QAxWidget *m_axobject = nullptr; 90 QPixmap m_axImage; 91 }; 92 93 class QDesignerAxPluginWidget : public QDesignerAxWidget 94 { 95 // No Q_OBJECT here! - meta functionality is overridden 96 public: 97 explicit QDesignerAxPluginWidget(QWidget *parent); 98 virtual ~QDesignerAxPluginWidget(); 99 100 const QMetaObject *metaObject() const override; 101 int qt_metacall(QMetaObject::Call, int, void **) override; 102 103 private: 104 QMap<int, bool> m_propValues; 105 }; 106 107 template <> inline QDesignerAxWidget *qobject_cast<QDesignerAxWidget*>(QObject *o) 108 { 109 if (!o) 110 return 0; 111 112 // Unloaded state 113 if (strcmp(o->metaObject()->className(), "QDesignerAxWidget") == 0) 114 return static_cast<QDesignerAxPluginWidget*>(o); 115 116 // Loaded state with fake meta object 117 if (strcmp(o->metaObject()->className(), "QAxWidget") == 0) 118 return static_cast<QDesignerAxPluginWidget*>(o); 119 120 return 0; 121 } 122 123 QT_END_NAMESPACE 124 125 #endif // ACTIVEQT_EXTRAINFO_H 126