| 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 <QAxBindable>
|
|---|
| 43 | #include <QAxFactory>
|
|---|
| 44 | #include <QApplication>
|
|---|
| 45 | #include <QLayout>
|
|---|
| 46 | #include <QSlider>
|
|---|
| 47 | #include <QLCDNumber>
|
|---|
| 48 | #include <QLineEdit>
|
|---|
| 49 | #include <QMessageBox>
|
|---|
| 50 |
|
|---|
| 51 | //! [0]
|
|---|
| 52 | class QSimpleAX : public QWidget, public QAxBindable
|
|---|
| 53 | {
|
|---|
| 54 | Q_OBJECT
|
|---|
| 55 | Q_PROPERTY( QString text READ text WRITE setText )
|
|---|
| 56 | Q_PROPERTY( int value READ value WRITE setValue )
|
|---|
| 57 | public:
|
|---|
| 58 | QSimpleAX(QWidget *parent = 0)
|
|---|
| 59 | : QWidget(parent)
|
|---|
| 60 | {
|
|---|
| 61 | QVBoxLayout *vbox = new QVBoxLayout( this );
|
|---|
| 62 |
|
|---|
| 63 | slider = new QSlider( Qt::Horizontal, this );
|
|---|
| 64 | LCD = new QLCDNumber( 3, this );
|
|---|
| 65 | edit = new QLineEdit( this );
|
|---|
| 66 |
|
|---|
| 67 | connect( slider, SIGNAL( valueChanged( int ) ), this, SLOT( setValue(int) ) );
|
|---|
| 68 | connect( edit, SIGNAL(textChanged(const QString&)), this, SLOT(setText(const QString&)) );
|
|---|
| 69 |
|
|---|
| 70 | vbox->addWidget( slider );
|
|---|
| 71 | vbox->addWidget( LCD );
|
|---|
| 72 | vbox->addWidget( edit );
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | QString text() const
|
|---|
| 76 | {
|
|---|
| 77 | return edit->text();
|
|---|
| 78 | }
|
|---|
| 79 | int value() const
|
|---|
| 80 | {
|
|---|
| 81 | return slider->value();
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | signals:
|
|---|
| 85 | void someSignal();
|
|---|
| 86 | void valueChanged(int);
|
|---|
| 87 | void textChanged(const QString&);
|
|---|
| 88 |
|
|---|
| 89 | public slots:
|
|---|
| 90 | void setText( const QString &string )
|
|---|
| 91 | {
|
|---|
| 92 | if ( !requestPropertyChange( "text" ) )
|
|---|
| 93 | return;
|
|---|
| 94 |
|
|---|
| 95 | edit->blockSignals( true );
|
|---|
| 96 | edit->setText( string );
|
|---|
| 97 | edit->blockSignals( false );
|
|---|
| 98 | emit someSignal();
|
|---|
| 99 | emit textChanged( string );
|
|---|
| 100 |
|
|---|
| 101 | propertyChanged( "text" );
|
|---|
| 102 | }
|
|---|
| 103 | void about()
|
|---|
| 104 | {
|
|---|
| 105 | QMessageBox::information( this, "About QSimpleAX", "This is a Qt widget, and this slot has been\n"
|
|---|
| 106 | "called through ActiveX/OLE automation!" );
|
|---|
| 107 | }
|
|---|
| 108 | void setValue( int i )
|
|---|
| 109 | {
|
|---|
| 110 | if ( !requestPropertyChange( "value" ) )
|
|---|
| 111 | return;
|
|---|
| 112 | slider->blockSignals( true );
|
|---|
| 113 | slider->setValue( i );
|
|---|
| 114 | slider->blockSignals( false );
|
|---|
| 115 | LCD->display( i );
|
|---|
| 116 | emit valueChanged( i );
|
|---|
| 117 |
|
|---|
| 118 | propertyChanged( "value" );
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | private:
|
|---|
| 122 | QSlider *slider;
|
|---|
| 123 | QLCDNumber *LCD;
|
|---|
| 124 | QLineEdit *edit;
|
|---|
| 125 | };
|
|---|
| 126 |
|
|---|
| 127 | //! [0]
|
|---|
| 128 | #include "main.moc"
|
|---|
| 129 |
|
|---|
| 130 | //! [1]
|
|---|
| 131 | QAXFACTORY_DEFAULT(QSimpleAX,
|
|---|
| 132 | "{DF16845C-92CD-4AAB-A982-EB9840E74669}",
|
|---|
| 133 | "{616F620B-91C5-4410-A74E-6B81C76FFFE0}",
|
|---|
| 134 | "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}",
|
|---|
| 135 | "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}",
|
|---|
| 136 | "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}")
|
|---|
| 137 | //! [1]
|
|---|