| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2011 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 examples of the Qt Toolkit. | 
|---|
| 8 | ** | 
|---|
| 9 | ** $QT_BEGIN_LICENSE:BSD$ | 
|---|
| 10 | ** You may use this file under the terms of the BSD license as follows: | 
|---|
| 11 | ** | 
|---|
| 12 | ** "Redistribution and use in source and binary forms, with or without | 
|---|
| 13 | ** modification, are permitted provided that the following conditions are | 
|---|
| 14 | ** met: | 
|---|
| 15 | **   * Redistributions of source code must retain the above copyright | 
|---|
| 16 | **     notice, this list of conditions and the following disclaimer. | 
|---|
| 17 | **   * Redistributions in binary form must reproduce the above copyright | 
|---|
| 18 | **     notice, this list of conditions and the following disclaimer in | 
|---|
| 19 | **     the documentation and/or other materials provided with the | 
|---|
| 20 | **     distribution. | 
|---|
| 21 | **   * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor | 
|---|
| 22 | **     the names of its contributors may be used to endorse or promote | 
|---|
| 23 | **     products derived from this software without specific prior written | 
|---|
| 24 | **     permission. | 
|---|
| 25 | ** | 
|---|
| 26 | ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
|---|
| 27 | ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
|---|
| 28 | ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 
|---|
| 29 | ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
|---|
| 30 | ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 
|---|
| 31 | ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 
|---|
| 32 | ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 
|---|
| 33 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 
|---|
| 34 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
|---|
| 35 | ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 
|---|
| 36 | ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." | 
|---|
| 37 | ** $QT_END_LICENSE$ | 
|---|
| 38 | ** | 
|---|
| 39 | ****************************************************************************/ | 
|---|
| 40 |  | 
|---|
| 41 | #include <QAxBindable> | 
|---|
| 42 | #include <QAxFactory> | 
|---|
| 43 | #include <QApplication> | 
|---|
| 44 | #include <QLayout> | 
|---|
| 45 | #include <QSlider> | 
|---|
| 46 | #include <QLCDNumber> | 
|---|
| 47 | #include <QLineEdit> | 
|---|
| 48 | #include <QMessageBox> | 
|---|
| 49 |  | 
|---|
| 50 | //! [0] | 
|---|
| 51 | class QSimpleAX : public QWidget, public QAxBindable | 
|---|
| 52 | { | 
|---|
| 53 | Q_OBJECT | 
|---|
| 54 | Q_PROPERTY( QString text READ text WRITE setText ) | 
|---|
| 55 | Q_PROPERTY( int value READ value WRITE setValue ) | 
|---|
| 56 | public: | 
|---|
| 57 | QSimpleAX(QWidget *parent = 0) | 
|---|
| 58 | : QWidget(parent) | 
|---|
| 59 | { | 
|---|
| 60 | QVBoxLayout *vbox = new QVBoxLayout( this ); | 
|---|
| 61 |  | 
|---|
| 62 | slider = new QSlider( Qt::Horizontal, this ); | 
|---|
| 63 | LCD = new QLCDNumber( 3, this ); | 
|---|
| 64 | edit = new QLineEdit( this ); | 
|---|
| 65 |  | 
|---|
| 66 | connect( slider, SIGNAL(valueChanged(int)), this, SLOT(setValue(int)) ); | 
|---|
| 67 | connect( edit, SIGNAL(textChanged(QString)), this, SLOT(setText(QString)) ); | 
|---|
| 68 |  | 
|---|
| 69 | vbox->addWidget( slider ); | 
|---|
| 70 | vbox->addWidget( LCD ); | 
|---|
| 71 | vbox->addWidget( edit ); | 
|---|
| 72 | } | 
|---|
| 73 |  | 
|---|
| 74 | QString text() const | 
|---|
| 75 | { | 
|---|
| 76 | return edit->text(); | 
|---|
| 77 | } | 
|---|
| 78 | int value() const | 
|---|
| 79 | { | 
|---|
| 80 | return slider->value(); | 
|---|
| 81 | } | 
|---|
| 82 |  | 
|---|
| 83 | signals: | 
|---|
| 84 | void someSignal(); | 
|---|
| 85 | void valueChanged(int); | 
|---|
| 86 | void textChanged(const QString&); | 
|---|
| 87 |  | 
|---|
| 88 | public slots: | 
|---|
| 89 | void setText( const QString &string ) | 
|---|
| 90 | { | 
|---|
| 91 | if ( !requestPropertyChange( "text" ) ) | 
|---|
| 92 | return; | 
|---|
| 93 |  | 
|---|
| 94 | edit->blockSignals( true ); | 
|---|
| 95 | edit->setText( string ); | 
|---|
| 96 | edit->blockSignals( false ); | 
|---|
| 97 | emit someSignal(); | 
|---|
| 98 | emit textChanged( string ); | 
|---|
| 99 |  | 
|---|
| 100 | propertyChanged( "text" ); | 
|---|
| 101 | } | 
|---|
| 102 | void about() | 
|---|
| 103 | { | 
|---|
| 104 | QMessageBox::information( this, "About QSimpleAX", "This is a Qt widget, and this slot has been\n" | 
|---|
| 105 | "called through ActiveX/OLE automation!" ); | 
|---|
| 106 | } | 
|---|
| 107 | void setValue( int i ) | 
|---|
| 108 | { | 
|---|
| 109 | if ( !requestPropertyChange( "value" ) ) | 
|---|
| 110 | return; | 
|---|
| 111 | slider->blockSignals( true ); | 
|---|
| 112 | slider->setValue( i ); | 
|---|
| 113 | slider->blockSignals( false ); | 
|---|
| 114 | LCD->display( i ); | 
|---|
| 115 | emit valueChanged( i ); | 
|---|
| 116 |  | 
|---|
| 117 | propertyChanged( "value" ); | 
|---|
| 118 | } | 
|---|
| 119 |  | 
|---|
| 120 | private: | 
|---|
| 121 | QSlider *slider; | 
|---|
| 122 | QLCDNumber *LCD; | 
|---|
| 123 | QLineEdit *edit; | 
|---|
| 124 | }; | 
|---|
| 125 |  | 
|---|
| 126 | //! [0] | 
|---|
| 127 | #include "main.moc" | 
|---|
| 128 |  | 
|---|
| 129 | //! [1] | 
|---|
| 130 | QAXFACTORY_DEFAULT(QSimpleAX, | 
|---|
| 131 | "{DF16845C-92CD-4AAB-A982-EB9840E74669}", | 
|---|
| 132 | "{616F620B-91C5-4410-A74E-6B81C76FFFE0}", | 
|---|
| 133 | "{E1816BBA-BF5D-4A31-9855-D6BA432055FF}", | 
|---|
| 134 | "{EC08F8FC-2754-47AB-8EFE-56A54057F34E}", | 
|---|
| 135 | "{A095BA0C-224F-4933-A458-2DD7F6B85D8F}") | 
|---|
| 136 | //! [1] | 
|---|