[2] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[561] | 4 | ** All rights reserved.
|
---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
---|
[2] | 6 | **
|
---|
| 7 | ** This file is part of the examples of the Qt Toolkit.
|
---|
| 8 | **
|
---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
---|
| 10 | ** Commercial Usage
|
---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
| 14 | ** a written agreement between you and Nokia.
|
---|
| 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 | **
|
---|
[561] | 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.
|
---|
[2] | 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 | **
|
---|
[561] | 36 | ** If you have questions regarding the use of this file, please contact
|
---|
| 37 | ** Nokia at [email protected].
|
---|
[2] | 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 |
|
---|
[561] | 67 | connect( slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)) );
|
---|
| 68 | connect( edit, SIGNAL(textChanged(QString)), this, SLOT(setText(QString)) );
|
---|
[2] | 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]
|
---|