tools/designer/src/plugins/activeqt/qdesigneraxwidget.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
child 7 f7bc934e204c
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the Qt Designer of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QACTIVEXPLUGINOBJECT_H
       
    43 #define QACTIVEXPLUGINOBJECT_H
       
    44 
       
    45 #include <QtCore/QPointer>
       
    46 #include <QtCore/QMap>
       
    47 #include <QtGui/QWidget>
       
    48 #include <QtGui/QPixmap>
       
    49 
       
    50 QT_BEGIN_NAMESPACE
       
    51 
       
    52 class QAxWidget;
       
    53 
       
    54 /* QDesignerAxWidget aggregates QAxWidget to keep it out of the event loop while applying
       
    55  * properties directly.
       
    56  * Thus, it is possible to set property values in designer that are out of range
       
    57  * for the control, which might cause it to throw exceptions.
       
    58  *
       
    59  * QDesignerAxWidget is the base class following the internal naming
       
    60  * conventions that makes the control property visible to the introspection interface.
       
    61  *
       
    62  * The trick to aggregate a QAxWidget is to overwrite the metaObject() function
       
    63  * generated by moc to return the QMetaObject of QAxWidget. This is what QDesignerAxPluginWidget does. */
       
    64 
       
    65 class QDesignerAxWidget : public QWidget
       
    66 {
       
    67     Q_OBJECT
       
    68     Q_PROPERTY(QString control READ control WRITE setControl RESET resetControl DESIGNABLE true)
       
    69     Q_DISABLE_COPY(QDesignerAxWidget)
       
    70 
       
    71 protected:
       
    72     explicit QDesignerAxWidget(QWidget *parent);
       
    73 
       
    74 public:
       
    75     virtual ~QDesignerAxWidget();
       
    76 
       
    77     bool loadControl(const QString &clsid);
       
    78 
       
    79     void resetControl();
       
    80     void setControl(const QString &clsid);
       
    81     QString control() const;
       
    82 
       
    83     QSize sizeHint() const;
       
    84     QSize minimumSizeHint() const;
       
    85 
       
    86     bool loaded() { return (m_axobject != 0); }
       
    87 
       
    88     static QPixmap widgetIcon();
       
    89 
       
    90     enum { DrawIndicator = 0x1, DrawFrame = 0x2, DrawControl = 0x4 };
       
    91 
       
    92     unsigned drawFlags() const { return m_drawFlags; }
       
    93     void setDrawFlags(unsigned f)  { m_drawFlags = f; }
       
    94 
       
    95 protected:
       
    96     void paintEvent(QPaintEvent *event);
       
    97     QAxWidget *axobject() const { return m_axobject; }
       
    98 
       
    99 private:
       
   100     const QSize m_defaultSize;
       
   101     unsigned m_drawFlags;
       
   102     QAxWidget *m_axobject;
       
   103     QPixmap m_axImage;
       
   104 };
       
   105 
       
   106 class QDesignerAxPluginWidget : public QDesignerAxWidget
       
   107 {
       
   108    // No Q_OBJECT here! - meta functionality is overriden
       
   109 public:
       
   110     explicit QDesignerAxPluginWidget(QWidget *parent);
       
   111     virtual ~QDesignerAxPluginWidget();
       
   112 
       
   113     virtual const QMetaObject *metaObject() const;
       
   114     virtual int qt_metacall(QMetaObject::Call, int, void **);
       
   115 
       
   116 private:
       
   117     QMap<int, bool> m_propValues;
       
   118 };
       
   119 
       
   120 #if defined Q_CC_MSVC && _MSC_VER < 1300
       
   121 template <> inline QDesignerAxWidget *qobject_cast_helper<QDesignerAxWidget*>(QObject *o,  QDesignerAxWidget*)
       
   122 #else
       
   123 template <> inline QDesignerAxWidget *qobject_cast<QDesignerAxWidget*>(QObject *o)
       
   124 #endif
       
   125 {
       
   126     if (!o)
       
   127         return 0;
       
   128 
       
   129     // Unloaded state
       
   130     if (strcmp(o->metaObject()->className(), "QDesignerAxWidget") == 0)
       
   131         return static_cast<QDesignerAxPluginWidget*>(o);
       
   132 
       
   133     // Loaded state with fake meta object
       
   134     if (strcmp(o->metaObject()->className(), "QAxWidget") == 0)
       
   135         return static_cast<QDesignerAxPluginWidget*>(o);
       
   136 
       
   137     return 0;
       
   138 }
       
   139 
       
   140 QT_END_NAMESPACE
       
   141 
       
   142 #endif // ACTIVEQT_EXTRAINFO_H