diff options
author | axis <qt-info@nokia.com> | 2010-02-23 15:23:05 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2010-02-23 15:23:05 (GMT) |
commit | f67062af3a076468442c29127cb48bb13937ce0e (patch) | |
tree | a12cd4c644fb528dd5f95cb58559732a0b8b6311 /examples | |
parent | a670009fd378d48ff891602ec31204614e8a476f (diff) | |
parent | c15307e9e916aa613096275919ca91deba64454f (diff) | |
download | Qt-f67062af3a076468442c29127cb48bb13937ce0e.zip Qt-f67062af3a076468442c29127cb48bb13937ce0e.tar.gz Qt-f67062af3a076468442c29127cb48bb13937ce0e.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-s60-public
Conflicts:
mkspecs/features/symbian/qt.prf
qmake/Makefile.unix
qmake/Makefile.win32
qmake/Makefile.win32-g++
qmake/Makefile.win32-g++-sh
qmake/generators/symbian/initprojectdeploy_symbian.cpp
src/src.pro
Diffstat (limited to 'examples')
87 files changed, 839 insertions, 494 deletions
diff --git a/examples/declarative/anchors/anchor-changes.qml b/examples/declarative/anchors/anchor-changes.qml index 2ebe1c0..99ca3db 100644 --- a/examples/declarative/anchors/anchor-changes.qml +++ b/examples/declarative/anchors/anchor-changes.qml @@ -25,7 +25,7 @@ Item { Text { text: "Bottom"; anchors.bottom: parent.bottom } } - MouseRegion { + MouseArea { anchors.fill: content onPressed: window.state = "FullScreen" onReleased: window.state = "" @@ -41,6 +41,6 @@ Item { } transitions : Transition { - NumberAnimation { matchProperties: "y,height" } + NumberAnimation { properties: "y,height" } } } diff --git a/examples/declarative/animations/easing.qml b/examples/declarative/animations/easing.qml index a9ba05f..9b5bcc6 100644 --- a/examples/declarative/animations/easing.qml +++ b/examples/declarative/animations/easing.qml @@ -68,7 +68,7 @@ Rectangle { border.color: "White"; border.width: 2 height: 32; width: 32; radius: 8; anchors.verticalCenter: parent.verticalCenter - MouseRegion { + MouseArea { onClicked: if (rect.state == '') rect.state = "right"; else rect.state = '' anchors.fill: parent } @@ -80,8 +80,8 @@ Rectangle { transitions: Transition { ParallelAnimation { - NumberAnimation { matchProperties: "x"; easing: type; duration: 1000 } - ColorAnimation { matchProperties: "color"; easing: type; duration: 1000 } + NumberAnimation { properties: "x"; easing: type; duration: 1000 } + ColorAnimation { properties: "color"; easing: type; duration: 1000 } } } } diff --git a/examples/declarative/aspectratio/face_fit.qml b/examples/declarative/aspectratio/face_fit.qml index 482d1b7..6a031a4 100644 --- a/examples/declarative/aspectratio/face_fit.qml +++ b/examples/declarative/aspectratio/face_fit.qml @@ -16,6 +16,7 @@ Rectangle { Image { id: face smooth: true + anchors.centerIn: parent source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 80a762b..90ea516 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -14,6 +14,7 @@ Rectangle { Image { id: face smooth: true + anchors.centerIn: parent source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 diff --git a/examples/declarative/aspectratio/scale_and_crop.qml b/examples/declarative/aspectratio/scale_and_crop.qml index 283e24b..2e2b6ed 100644 --- a/examples/declarative/aspectratio/scale_and_crop.qml +++ b/examples/declarative/aspectratio/scale_and_crop.qml @@ -12,6 +12,7 @@ Rectangle { Image { id: face smooth: true + anchors.centerIn: parent source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 diff --git a/examples/declarative/aspectratio/scale_and_sidecrop.qml b/examples/declarative/aspectratio/scale_and_sidecrop.qml index c3ef859..8230e49 100644 --- a/examples/declarative/aspectratio/scale_and_sidecrop.qml +++ b/examples/declarative/aspectratio/scale_and_sidecrop.qml @@ -13,6 +13,7 @@ Rectangle { Image { id: face smooth: true + anchors.centerIn: parent source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 diff --git a/examples/declarative/aspectratio/scale_to_fit.qml b/examples/declarative/aspectratio/scale_to_fit.qml index 961ac04..eae4d16 100644 --- a/examples/declarative/aspectratio/scale_to_fit.qml +++ b/examples/declarative/aspectratio/scale_to_fit.qml @@ -13,6 +13,7 @@ Rectangle { Image { id: face smooth: true + anchors.centerIn: parent source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 diff --git a/examples/declarative/behaviours/MyRect.qml b/examples/declarative/behaviours/MyRect.qml index a272e1f..caf0d83 100644 --- a/examples/declarative/behaviours/MyRect.qml +++ b/examples/declarative/behaviours/MyRect.qml @@ -6,7 +6,7 @@ Rectangle { width: 100 height: 100 id: page - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { bluerect.parent = page; bluerect.x=0 } } diff --git a/examples/declarative/behaviours/SideRect.qml b/examples/declarative/behaviours/SideRect.qml index c7c7ebf..63b7db2 100644 --- a/examples/declarative/behaviours/SideRect.qml +++ b/examples/declarative/behaviours/SideRect.qml @@ -9,7 +9,7 @@ Rectangle { width: 75; height: 50 radius: 5 border.width: 10; border.color: "white"; - MouseRegion { + MouseArea { anchors.fill: parent hoverEnabled: true onEntered: { focusRect.x = myRect.x; focusRect.y = myRect.y; focusRect.text = myRect.text } diff --git a/examples/declarative/behaviours/test.qml b/examples/declarative/behaviours/test.qml index 1869c45..fc3f4bf 100644 --- a/examples/declarative/behaviours/test.qml +++ b/examples/declarative/behaviours/test.qml @@ -5,7 +5,7 @@ Rectangle { width: 800 height: 600 id: page - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { bluerect.parent = page; console.log(mouseX); bluerect.x = mouseX; } } diff --git a/examples/declarative/connections/content/Button.qml b/examples/declarative/connections/content/Button.qml index 1d46acc..0e33c78 100644 --- a/examples/declarative/connections/content/Button.qml +++ b/examples/declarative/connections/content/Button.qml @@ -8,5 +8,5 @@ Item { signal clicked Image { id: icon } - MouseRegion { anchors.fill: icon; onClicked: button.clicked() } + MouseArea { anchors.fill: icon; onClicked: button.clicked() } } diff --git a/examples/declarative/dial/dial.qml b/examples/declarative/dial/dial.qml index c7b7659..3aed70e 100644 --- a/examples/declarative/dial/dial.qml +++ b/examples/declarative/dial/dial.qml @@ -26,7 +26,7 @@ Rectangle { GradientStop { position: 0.0; color: "#424242" } GradientStop { position: 1.0; color: "black" } } - MouseRegion { + MouseArea { anchors.fill: parent drag.target: parent; drag.axis: "XAxis"; drag.minimumX: 2; drag.maximumX: container.width - 32 } diff --git a/examples/declarative/dynamic/qml/Button.qml b/examples/declarative/dynamic/qml/Button.qml index cf2ffa7..757e295 100644 --- a/examples/declarative/dynamic/qml/Button.qml +++ b/examples/declarative/dynamic/qml/Button.qml @@ -19,6 +19,6 @@ Rectangle { color: if(!mr.pressed){activePalette.button;}else{activePalette.dark;} } } - MouseRegion { id:mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id:mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: text; anchors.centerIn:parent; font.pointSize: 10; text: parent.text; color: activePalette.buttonText } } diff --git a/examples/declarative/dynamic/qml/PaletteItem.qml b/examples/declarative/dynamic/qml/PaletteItem.qml index bb6036d..8a9a9ee 100644 --- a/examples/declarative/dynamic/qml/PaletteItem.qml +++ b/examples/declarative/dynamic/qml/PaletteItem.qml @@ -4,7 +4,7 @@ GenericItem { id: itemButton property string file Script { source: "itemCreation.js" } - MouseRegion { + MouseArea { anchors.fill: parent; onPressed: startDrag(mouse); onPositionChanged: moveDrag(mouse); diff --git a/examples/declarative/dynamic/qml/PerspectiveItem.qml b/examples/declarative/dynamic/qml/PerspectiveItem.qml index 728c3a5..a0dfad3 100644 --- a/examples/declarative/dynamic/qml/PerspectiveItem.qml +++ b/examples/declarative/dynamic/qml/PerspectiveItem.qml @@ -6,6 +6,7 @@ Image { property double scaleFactor: Math.max((y+height-250)*0.01, 0.3) property double scaledBottom: y + (height+height*scaleFactor)/2 property bool onLand: scaledBottom > window.height/2 + property string image //Needed for compatibility with GenericItem opacity: onLand ? 1 : 0.25 onCreatedChanged: if (created && !onLand) { tree.destroy() } else { z = scaledBottom } scale: scaleFactor diff --git a/examples/declarative/effects/effects.qml b/examples/declarative/effects/effects.qml index 51658ff..0674433 100644 --- a/examples/declarative/effects/effects.qml +++ b/examples/declarative/effects/effects.qml @@ -20,7 +20,7 @@ Rectangle { } } - MouseRegion { anchors.fill: parent; onClicked: blurEffect.running = !blurEffect.running } + MouseArea { anchors.fill: parent; onClicked: blurEffect.running = !blurEffect.running } } Text { text: "Blur"; anchors.top: blur.bottom; anchors.horizontalCenter: blur.horizontalCenter } @@ -36,7 +36,7 @@ Rectangle { offset.y: NumberAnimation { id: dropShadowEffect; from: 0; to: 10; duration: 1000; running: false; repeat: true; } } - MouseRegion { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } + MouseArea { anchors.fill: parent; onClicked: dropShadowEffect.running = !dropShadowEffect.running } } Image { diff --git a/examples/declarative/extending/attached/birthdayparty.cpp b/examples/declarative/extending/attached/birthdayparty.cpp index 9dc13de..ffdda57 100644 --- a/examples/declarative/extending/attached/birthdayparty.cpp +++ b/examples/declarative/extending/attached/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } BirthdayPartyAttached *BirthdayParty::qmlAttachedProperties(QObject *object) diff --git a/examples/declarative/extending/attached/birthdayparty.h b/examples/declarative/extending/attached/birthdayparty.h index bd8952b..9ba0f8b 100644 --- a/examples/declarative/extending/attached/birthdayparty.h +++ b/examples/declarative/extending/attached/birthdayparty.h @@ -65,7 +65,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -73,12 +73,14 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; static BirthdayPartyAttached *qmlAttachedProperties(QObject *); private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/attached/main.cpp b/examples/declarative/extending/attached/main.cpp index 2ec783f..27a9287 100644 --- a/examples/declarative/extending/attached/main.cpp +++ b/examples/declarative/extending/attached/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/binding/birthdayparty.cpp b/examples/declarative/extending/binding/birthdayparty.cpp index 8a409af..62b9c7b 100644 --- a/examples/declarative/extending/binding/birthdayparty.cpp +++ b/examples/declarative/extending/binding/birthdayparty.cpp @@ -77,9 +77,19 @@ void BirthdayParty::setCelebrant(Person *c) emit celebrantChanged(); } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/binding/birthdayparty.h b/examples/declarative/extending/binding/birthdayparty.h index 5651c65..8bdb76a 100644 --- a/examples/declarative/extending/binding/birthdayparty.h +++ b/examples/declarative/extending/binding/birthdayparty.h @@ -71,7 +71,7 @@ Q_OBJECT // ![0] Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant NOTIFY celebrantChanged) // ![0] -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) Q_CLASSINFO("DefaultProperty", "guests") public: @@ -80,7 +80,9 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; QString speaker() const; void setSpeaker(const QString &); @@ -94,7 +96,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/binding/main.cpp b/examples/declarative/extending/binding/main.cpp index 4ad9929..ba38e82 100644 --- a/examples/declarative/extending/binding/main.cpp +++ b/examples/declarative/extending/binding/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/coercion/birthdayparty.cpp b/examples/declarative/extending/coercion/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/coercion/birthdayparty.cpp +++ b/examples/declarative/extending/coercion/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/coercion/birthdayparty.h b/examples/declarative/extending/coercion/birthdayparty.h index 8563ec3..5a9eb08 100644 --- a/examples/declarative/extending/coercion/birthdayparty.h +++ b/examples/declarative/extending/coercion/birthdayparty.h @@ -50,7 +50,7 @@ class BirthdayParty : public QObject Q_OBJECT // ![0] Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) // ![0] public: BirthdayParty(QObject *parent = 0); @@ -58,11 +58,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/coercion/main.cpp b/examples/declarative/extending/coercion/main.cpp index c6cc847..ccbee83 100644 --- a/examples/declarative/extending/coercion/main.cpp +++ b/examples/declarative/extending/coercion/main.cpp @@ -60,8 +60,9 @@ int main(int argc, char ** argv) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/default/birthdayparty.cpp b/examples/declarative/extending/default/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/default/birthdayparty.cpp +++ b/examples/declarative/extending/default/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/default/birthdayparty.h b/examples/declarative/extending/default/birthdayparty.h index 869b32c..f25f8c2 100644 --- a/examples/declarative/extending/default/birthdayparty.h +++ b/examples/declarative/extending/default/birthdayparty.h @@ -50,7 +50,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -58,11 +58,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; // ![0] QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/default/main.cpp b/examples/declarative/extending/default/main.cpp index c6cc847..ccbee83 100644 --- a/examples/declarative/extending/default/main.cpp +++ b/examples/declarative/extending/default/main.cpp @@ -60,8 +60,9 @@ int main(int argc, char ** argv) qWarning() << "He is inviting:"; else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/grouped/birthdayparty.cpp b/examples/declarative/extending/grouped/birthdayparty.cpp index 014d307..15a4ca9 100644 --- a/examples/declarative/extending/grouped/birthdayparty.cpp +++ b/examples/declarative/extending/grouped/birthdayparty.cpp @@ -55,9 +55,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } QML_DEFINE_TYPE(People, 1,0, BirthdayParty, BirthdayParty); diff --git a/examples/declarative/extending/grouped/birthdayparty.h b/examples/declarative/extending/grouped/birthdayparty.h index 3f4a3a6..fd0d955 100644 --- a/examples/declarative/extending/grouped/birthdayparty.h +++ b/examples/declarative/extending/grouped/birthdayparty.h @@ -49,7 +49,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -57,11 +57,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPE(BirthdayParty); diff --git a/examples/declarative/extending/grouped/main.cpp b/examples/declarative/extending/grouped/main.cpp index 23ba8bf..79aaab5 100644 --- a/examples/declarative/extending/grouped/main.cpp +++ b/examples/declarative/extending/grouped/main.cpp @@ -62,8 +62,8 @@ int main(int argc, char ** argv) qWarning() << "She is inviting:"; Person *bestShoe = 0; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); qWarning() << " " << guest->name(); if (!bestShoe || bestShoe->shoe()->price() < guest->shoe()->price()) diff --git a/examples/declarative/extending/properties/birthdayparty.cpp b/examples/declarative/extending/properties/birthdayparty.cpp index 332b090..23e6e58 100644 --- a/examples/declarative/extending/properties/birthdayparty.cpp +++ b/examples/declarative/extending/properties/birthdayparty.cpp @@ -56,9 +56,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } // ![0] diff --git a/examples/declarative/extending/properties/birthdayparty.h b/examples/declarative/extending/properties/birthdayparty.h index ceefd5b..e5d316c 100644 --- a/examples/declarative/extending/properties/birthdayparty.h +++ b/examples/declarative/extending/properties/birthdayparty.h @@ -54,7 +54,7 @@ Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) // ![1] // ![2] -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) // ![2] // ![3] public: @@ -63,11 +63,13 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPE(BirthdayParty); // ![3] diff --git a/examples/declarative/extending/properties/main.cpp b/examples/declarative/extending/properties/main.cpp index 229e59a..97d7905 100644 --- a/examples/declarative/extending/properties/main.cpp +++ b/examples/declarative/extending/properties/main.cpp @@ -56,8 +56,8 @@ int main(int argc, char ** argv) if (party && party->celebrant()) { qWarning() << party->celebrant()->name() << "is having a birthday!"; qWarning() << "They are inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) - qWarning() << " " << party->guests()->at(ii)->name(); + for (int ii = 0; ii < party->guestCount(); ++ii) + qWarning() << " " << party->guest(ii)->name(); } else { qWarning() << "An error occured"; } diff --git a/examples/declarative/extending/signal/birthdayparty.cpp b/examples/declarative/extending/signal/birthdayparty.cpp index 88c5459..d8686f0 100644 --- a/examples/declarative/extending/signal/birthdayparty.cpp +++ b/examples/declarative/extending/signal/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/signal/birthdayparty.h b/examples/declarative/extending/signal/birthdayparty.h index 8ce5d7b..30ed43b 100644 --- a/examples/declarative/extending/signal/birthdayparty.h +++ b/examples/declarative/extending/signal/birthdayparty.h @@ -65,7 +65,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) Q_CLASSINFO("DefaultProperty", "guests") public: BirthdayParty(QObject *parent = 0); @@ -73,7 +73,9 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; static BirthdayPartyAttached *qmlAttachedProperties(QObject *); @@ -85,7 +87,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/signal/main.cpp b/examples/declarative/extending/signal/main.cpp index 4e981c5..eb3bb4b 100644 --- a/examples/declarative/extending/signal/main.cpp +++ b/examples/declarative/extending/signal/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/extending/valuesource/birthdayparty.cpp b/examples/declarative/extending/valuesource/birthdayparty.cpp index b483f68..a5b3fab 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.cpp +++ b/examples/declarative/extending/valuesource/birthdayparty.cpp @@ -72,9 +72,19 @@ void BirthdayParty::setCelebrant(Person *c) m_celebrant = c; } -QmlList<Person *> *BirthdayParty::guests() +QmlListProperty<Person> BirthdayParty::guests() { - return &m_guests; + return QmlListProperty<Person>(this, m_guests); +} + +int BirthdayParty::guestCount() const +{ + return m_guests.count(); +} + +Person *BirthdayParty::guest(int index) const +{ + return m_guests.at(index); } void BirthdayParty::startParty() diff --git a/examples/declarative/extending/valuesource/birthdayparty.h b/examples/declarative/extending/valuesource/birthdayparty.h index e7ca461..b5a0522 100644 --- a/examples/declarative/extending/valuesource/birthdayparty.h +++ b/examples/declarative/extending/valuesource/birthdayparty.h @@ -66,7 +66,7 @@ class BirthdayParty : public QObject { Q_OBJECT Q_PROPERTY(Person *celebrant READ celebrant WRITE setCelebrant) -Q_PROPERTY(QmlList<Person *> *guests READ guests) +Q_PROPERTY(QmlListProperty<Person> guests READ guests) // ![0] Q_PROPERTY(QString speaker READ speaker WRITE setSpeaker) // ![0] @@ -77,7 +77,10 @@ public: Person *celebrant() const; void setCelebrant(Person *); - QmlList<Person *> *guests(); + QmlListProperty<Person> guests(); + int guestCount() const; + Person *guest(int) const; + QString speaker() const; void setSpeaker(const QString &); @@ -90,7 +93,7 @@ signals: private: Person *m_celebrant; - QmlConcreteList<Person *> m_guests; + QList<Person *> m_guests; }; QML_DECLARE_TYPEINFO(BirthdayParty, QML_HAS_ATTACHED_PROPERTIES) diff --git a/examples/declarative/extending/valuesource/main.cpp b/examples/declarative/extending/valuesource/main.cpp index 4ad9929..ba38e82 100644 --- a/examples/declarative/extending/valuesource/main.cpp +++ b/examples/declarative/extending/valuesource/main.cpp @@ -61,8 +61,8 @@ int main(int argc, char ** argv) else qWarning() << "She is inviting:"; - for (int ii = 0; ii < party->guests()->count(); ++ii) { - Person *guest = party->guests()->at(ii); + for (int ii = 0; ii < party->guestCount(); ++ii) { + Person *guest = party->guest(ii); QDate rsvpDate; QObject *attached = diff --git a/examples/declarative/imageprovider/imageprovider.pro b/examples/declarative/imageprovider/imageprovider.pro new file mode 100644 index 0000000..60423ab --- /dev/null +++ b/examples/declarative/imageprovider/imageprovider.pro @@ -0,0 +1,9 @@ +TEMPLATE = app +TARGET = imageprovider +DEPENDPATH += . +INCLUDEPATH += . +QT += declarative + +# Input +SOURCES += main.cpp +RESOURCES += imageprovider.qrc diff --git a/examples/declarative/imageprovider/imageprovider.qrc b/examples/declarative/imageprovider/imageprovider.qrc new file mode 100644 index 0000000..17e9301 --- /dev/null +++ b/examples/declarative/imageprovider/imageprovider.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>view.qml</file> +</qresource> +</RCC> diff --git a/examples/declarative/imageprovider/main.cpp b/examples/declarative/imageprovider/main.cpp new file mode 100644 index 0000000..9526105 --- /dev/null +++ b/examples/declarative/imageprovider/main.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the demonstration applications of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QApplication> + +#include <qmlengine.h> +#include <qmlcontext.h> +#include <qml.h> +#include <qmlgraphicsitem.h> +#include <qmlimageprovider.h> +#include <qmlview.h> +#include <QImage> +#include <QPainter> + +/* + This example illustrates using a QmlImageProvider to serve + images asynchronously. +*/ + +//![0] +class ColorImageProvider : public QmlImageProvider +{ +public: + // This is run in a low priority thread. + QImage request(const QString &id) { + QImage image(100, 50, QImage::Format_RGB32); + image.fill(QColor(id).rgba()); + QPainter p(&image); + p.setPen(Qt::black); + p.drawText(QRectF(0,0,100,50),Qt::AlignCenter,id); + return image; + } +}; + +int main(int argc, char ** argv) +{ + QApplication app(argc, argv); + + QmlView view; + view.setSource(QUrl("qrc:view.qml")); + + view.engine()->addImageProvider("colors", new ColorImageProvider); + + QStringList dataList; + dataList.append("image://colors/red"); + dataList.append("image://colors/green"); + dataList.append("image://colors/blue"); + dataList.append("image://colors/brown"); + dataList.append("image://colors/orange"); + dataList.append("image://colors/purple"); + dataList.append("image://colors/yellow"); + + QmlContext *ctxt = view.rootContext(); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); + + view.execute(); + view.show(); + + return app.exec(); +} +//![0] diff --git a/examples/declarative/imageprovider/view.qml b/examples/declarative/imageprovider/view.qml new file mode 100644 index 0000000..2ab729d --- /dev/null +++ b/examples/declarative/imageprovider/view.qml @@ -0,0 +1,22 @@ +import Qt 4.6 +//![0] +ListView { + width: 100 + height: 100 + anchors.fill: parent + model: myModel + delegate: Component { + Item { + width: 100 + height: 50 + Text { + text: "Loading..." + anchors.centerIn: parent + } + Image { + source: modelData + } + } + } +} +//![0] diff --git a/examples/declarative/layouts/Button.qml b/examples/declarative/layouts/Button.qml index 215b536..0bdb9fc 100644 --- a/examples/declarative/layouts/Button.qml +++ b/examples/declarative/layouts/Button.qml @@ -7,7 +7,7 @@ Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.wid Image { id: pix; x: 5; y:5; source: parent.icon} Text { id: textelement; text: page.text; color: "white"; x:pix.width+pix.x+3; anchors.verticalCenter: pix.verticalCenter;} - MouseRegion{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} + MouseArea{ id:mr; anchors.fill: parent; onClicked: {parent.focus = true; page.clicked()}} states: State{ name:"pressed"; when:mr.pressed @@ -17,6 +17,6 @@ Rectangle { border.color: "black"; color: "steelblue"; radius: 5; width: pix.wid transitions: Transition{ - NumberAnimation { matchProperties:"x,left"; easing:"easeInOutQuad"; duration:200 } + NumberAnimation { properties:"x,left"; easing:"easeInOutQuad"; duration:200 } } } diff --git a/examples/declarative/layouts/positioners.qml b/examples/declarative/layouts/positioners.qml index 46762f7..fefd964 100644 --- a/examples/declarative/layouts/positioners.qml +++ b/examples/declarative/layouts/positioners.qml @@ -11,12 +11,12 @@ Rectangle { y: 0 move: Transition { NumberAnimation { - matchProperties: "y"; easing: "easeOutBounce" + properties: "y"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - matchProperties: "y"; easing: "easeOutQuad" + properties: "y"; easing: "easeOutQuad" } } Rectangle { color: "red"; width: 100; height: 50; border.color: "black"; radius: 15 } @@ -35,12 +35,12 @@ Rectangle { y: 300 move: Transition { NumberAnimation { - matchProperties: "x"; easing: "easeOutBounce" + properties: "x"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - matchProperties: "x"; easing: "easeOutQuad" + properties: "x"; easing: "easeOutQuad" } } Rectangle { color: "red"; width: 50; height: 100; border.color: "black"; radius: 15 } @@ -101,13 +101,13 @@ Rectangle { move: Transition { NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing: "easeOutBounce" } } @@ -136,13 +136,13 @@ Rectangle { move: Transition { NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing: "easeOutBounce" } } add: Transition { NumberAnimation { - matchProperties: "x,y"; easing: "easeOutBounce" + properties: "x,y"; easing: "easeOutBounce" } } Rectangle { color: "red"; width: 50; height: 50; border.color: "black"; radius: 15 } diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml index 796f9e3..0850f4e 100644 --- a/examples/declarative/listview/content/ClickAutoRepeating.qml +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -11,6 +11,7 @@ Item { signal clicked isPressed: SequentialAnimation { + running: false id: autoRepeat PropertyAction { target: page; property: "isPressed"; value: true } ScriptAction { script: page.pressed() } @@ -22,7 +23,7 @@ Item { PauseAnimation { duration: repeatperiod } } } - MouseRegion { + MouseArea { anchors.fill: parent onPressed: autoRepeat.start() onReleased: { autoRepeat.stop(); parent.isPressed = false; page.released() } diff --git a/examples/declarative/listview/content/MediaButton.qml b/examples/declarative/listview/content/MediaButton.qml index 1c88844..e9065c1 100644 --- a/examples/declarative/listview/content/MediaButton.qml +++ b/examples/declarative/listview/content/MediaButton.qml @@ -14,7 +14,7 @@ Item { source: "pics/button-pressed.png" opacity: 0 } - MouseRegion { + MouseArea { id: clickRegion anchors.fill: normal onClicked: { container.clicked(); } diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 101b708..81550d7 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -24,7 +24,6 @@ Rectangle { } ListElement { name: "Cumquat"; cost: 3.25 - types: [ "Small", "Smaller" ] attributes: [ ListElement { description: "Citrus" } ] @@ -58,10 +57,10 @@ Rectangle { Column { id: moveButtons; x: 5; width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter Image { source: "content/pics/go-up.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index-1,1) } } Image { source: "content/pics/go-down.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } + MouseArea { anchors.fill: parent; onClicked: fruitModel.move(index,index+1,1) } } } @@ -82,19 +81,19 @@ Rectangle { anchors.right: removeButton.left; anchors.rightMargin: 35; spacing: 10 width: childrenRect.width; anchors.verticalCenter: parent.verticalCenter Image { source: "content/pics/list-add.png" - ClickAutoRepeating { id: clickUp; anchors.fill: parent; onClicked: fruitModel.set(index,"cost",Number(cost)+0.25) } + ClickAutoRepeating { id: clickUp; anchors.fill: parent; onClicked: fruitModel.setProperty(index,"cost",cost+0.25) } scale: clickUp.isPressed ? 0.9 : 1; transformOrigin: Item.Center } Text { id: costText; text: '$'+Number(cost).toFixed(2); font.pixelSize: 15; color: "White"; font.bold: true; } Image { source: "content/pics/list-remove.png" - ClickAutoRepeating { id: clickDown; anchors.fill: parent; onClicked: fruitModel.set(index,"cost",Math.max(0,Number(cost)-0.25)) } + ClickAutoRepeating { id: clickDown; anchors.fill: parent; onClicked: fruitModel.setProperty(index,"cost",Math.max(0,cost-0.25)) } scale: clickDown.isPressed ? 0.9 : 1; transformOrigin: Item.Center } } Image { id: removeButton; source: "content/pics/archive-remove.png" anchors { verticalCenter: parent.verticalCenter; right: parent.right; rightMargin: 10 } - MouseRegion { anchors.fill:parent; onClicked: fruitModel.remove(index) } + MouseArea { anchors.fill:parent; onClicked: fruitModel.remove(index) } } } } @@ -122,7 +121,7 @@ Rectangle { PropertyChanges { target: verticalScrollBar; opacity: 1 } } ] - transitions: [ Transition { NumberAnimation { matchProperties: "opacity"; duration: 400 } } ] + transitions: [ Transition { NumberAnimation { properties: "opacity"; duration: 400 } } ] } Row { @@ -132,7 +131,7 @@ Rectangle { spacing: 8 id: buttons Image { source: "content/pics/archive-insert.png" - MouseRegion { anchors.fill: parent; + MouseArea { anchors.fill: parent; onClicked: { fruitModel.append({ "name":"Pizza Margarita", @@ -143,7 +142,7 @@ Rectangle { } } Image { source: "content/pics/archive-insert.png" - MouseRegion { anchors.fill: parent; + MouseArea { anchors.fill: parent; onClicked: { fruitModel.insert(0,{ "name":"Pizza Supreme", @@ -154,7 +153,7 @@ Rectangle { } } Image { source: "content/pics/archive-remove.png" - MouseRegion { anchors.fill: parent; onClicked: fruitModel.clear() } + MouseArea { anchors.fill: parent; onClicked: fruitModel.clear() } } } } diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 9665499..be1f62d 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -31,7 +31,7 @@ Rectangle { transitions: [ Transition { NumberAnimation { - matchProperties: "x"; duration: 200 + properties: "x"; duration: 200 } } ] diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 6392153..54981b7 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -51,7 +51,7 @@ Rectangle { Rectangle { width: 5; height: 5 radius: 3 - MouseRegion { width: 20; height: 20; anchors.centerIn: parent; onClicked: view.currentIndex = index } + MouseArea { width: 20; height: 20; anchors.centerIn: parent; onClicked: view.currentIndex = index } color: view.currentIndex == index ? "blue" : "white" } } diff --git a/examples/declarative/listview/recipes.qml b/examples/declarative/listview/recipes.qml index c133351..f848be0 100644 --- a/examples/declarative/listview/recipes.qml +++ b/examples/declarative/listview/recipes.qml @@ -32,7 +32,7 @@ Rectangle { // This mouse region covers the entire delegate. // When clicked it changes mode to 'Details'. If we are already // in Details mode, then no change will happen. - MouseRegion { + MouseArea { id: pageMouse anchors.fill: parent onClicked: wrapper.state = 'Details'; @@ -124,7 +124,7 @@ Rectangle { ParallelAnimation { ColorAnimation { property: "color"; duration: 500 } NumberAnimation { - duration: 300; matchProperties: "detailsOpacity,x,viewportY,height,width" + duration: 300; properties: "detailsOpacity,x,viewportY,height,width" } } } diff --git a/examples/declarative/mouseregion/mouse.qml b/examples/declarative/mouseregion/mouse.qml index d07d471..9191f8a 100644 --- a/examples/declarative/mouseregion/mouse.qml +++ b/examples/declarative/mouseregion/mouse.qml @@ -7,7 +7,7 @@ Rectangle { width: 50; height: 50 color: "red" Text { text: "Click"; anchors.centerIn: parent } - MouseRegion { + MouseArea { hoverEnabled: true acceptedButtons: Qt.LeftButton | Qt.RightButton onPressed: { console.log('press (x: ' + mouse.x + ' y: ' + mouse.y + ' button: ' + (mouse.button == Qt.RightButton ? 'right' : 'left') + ' Shift: ' + (mouse.modifiers & Qt.ShiftModifier ? 'true' : 'false') + ')') } @@ -24,7 +24,7 @@ Rectangle { y: 100; width: 50; height: 50 color: "blue" Text { text: "Drag"; anchors.centerIn: parent } - MouseRegion { + MouseArea { drag.target: parent drag.axis: "XAxis" drag.minimumX: 0 diff --git a/examples/declarative/objectlistmodel/main.cpp b/examples/declarative/objectlistmodel/main.cpp index 8231538..9e38bea 100644 --- a/examples/declarative/objectlistmodel/main.cpp +++ b/examples/declarative/objectlistmodel/main.cpp @@ -59,7 +59,7 @@ int main(int argc, char ** argv) QApplication app(argc, argv); QmlView view; - view.setUrl(QUrl("qrc:view.qml")); + view.setSource(QUrl("qrc:view.qml")); QList<QObject*> dataList; dataList.append(new DataObject("Item 1", "red")); @@ -68,7 +68,7 @@ int main(int argc, char ** argv) dataList.append(new DataObject("Item 4", "yellow")); QmlContext *ctxt = view.rootContext(); - ctxt->setContextProperty("myModel", QVariant::fromValue(&dataList)); + ctxt->setContextProperty("myModel", QVariant::fromValue(dataList)); view.execute(); view.show(); diff --git a/examples/declarative/parallax/qml/ParallaxView.qml b/examples/declarative/parallax/qml/ParallaxView.qml index ff4a85a..811891b 100644 --- a/examples/declarative/parallax/qml/ParallaxView.qml +++ b/examples/declarative/parallax/qml/ParallaxView.qml @@ -58,7 +58,7 @@ Item { transformOrigin: "Center" } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { root.currentIndex = index } } @@ -74,7 +74,7 @@ Item { } transitions: Transition { NumberAnimation { - matchProperties: "scale,y" + properties: "scale,y" } } } diff --git a/examples/declarative/scrollbar/ScrollBar.qml b/examples/declarative/scrollbar/ScrollBar.qml index f68775c..802b537 100644 --- a/examples/declarative/scrollbar/ScrollBar.qml +++ b/examples/declarative/scrollbar/ScrollBar.qml @@ -2,7 +2,7 @@ import Qt 4.6 Item { id: scrollBar - // The matchProperties that define the scrollbar's state. + // The properties that define the scrollbar's state. // position and pageSize are in the range 0.0 - 1.0. They are relative to the // height of the page, i.e. a pageSize of 0.5 means that you can see 50% // of the height of the view. diff --git a/examples/declarative/scrollbar/display.qml b/examples/declarative/scrollbar/display.qml index 0b9f95a..536a8b7 100644 --- a/examples/declarative/scrollbar/display.qml +++ b/examples/declarative/scrollbar/display.qml @@ -27,7 +27,7 @@ Rectangle { from: "*" to: "*" NumberAnimation { - matchProperties: "opacity" + properties: "opacity" duration: 400 } } diff --git a/examples/declarative/searchbox/SearchBox.qml b/examples/declarative/searchbox/SearchBox.qml index 42b5d67..524b652 100644 --- a/examples/declarative/searchbox/SearchBox.qml +++ b/examples/declarative/searchbox/SearchBox.qml @@ -23,7 +23,7 @@ FocusScope { text: "Type something..."; color: "gray"; font.italic: true } - MouseRegion { anchors.fill: parent; onClicked: focusScope.focus = true } + MouseArea { anchors.fill: parent; onClicked: focusScope.focus = true } TextInput { id: textInput @@ -38,7 +38,7 @@ FocusScope { anchors.verticalCenter: parent.verticalCenter source: "images/edit-clear-locationbar-rtl.png"; opacity: 0 - MouseRegion { anchors.fill: parent; onClicked: { textInput.text = ''; focusScope.focus = true } } + MouseArea { anchors.fill: parent; onClicked: { textInput.text = ''; focusScope.focus = true } } } states: State { @@ -50,11 +50,11 @@ FocusScope { transitions: [ Transition { from: ""; to: "hasText" - NumberAnimation { exclude: typeSomething; matchProperties: "opacity" } + NumberAnimation { exclude: typeSomething; properties: "opacity" } }, Transition { from: "hasText"; to: "" - NumberAnimation { matchProperties: "opacity" } + NumberAnimation { properties: "opacity" } } ] } diff --git a/examples/declarative/slideswitch/content/Switch.qml b/examples/declarative/slideswitch/content/Switch.qml index 29a62f7..930f471 100644 --- a/examples/declarative/slideswitch/content/Switch.qml +++ b/examples/declarative/slideswitch/content/Switch.qml @@ -32,7 +32,7 @@ Item { //![4] Image { id: background; source: "background.svg" - MouseRegion { anchors.fill: parent; onClicked: toggle() } + MouseArea { anchors.fill: parent; onClicked: toggle() } } //![4] @@ -40,7 +40,7 @@ Item { Image { id: knob; source: "knob.svg"; x: 1; y: 2 - MouseRegion { + MouseArea { anchors.fill: parent drag.target: knob; drag.axis: "XAxis"; drag.minimumX: 1; drag.maximumX: 78 onClicked: toggle() @@ -66,7 +66,7 @@ Item { //![7] transitions: Transition { - NumberAnimation { matchProperties: "x"; easing: "easeInOutQuad"; duration: 200 } + NumberAnimation { properties: "x"; easing: "easeInOutQuad"; duration: 200 } } //![7] } diff --git a/examples/declarative/snow/ImageBatch.qml b/examples/declarative/snow/ImageBatch.qml index 1d738b2..c2a2674 100644 --- a/examples/declarative/snow/ImageBatch.qml +++ b/examples/declarative/snow/ImageBatch.qml @@ -23,7 +23,7 @@ GridView { transitions: Transition { SequentialAnimation { PauseAnimation { duration: 150 } - PropertyAction { matchProperties: "z" } + PropertyAction { properties: "z" } } } model: XmlListModel { @@ -55,15 +55,15 @@ GridView { to: "selected" SequentialAnimation { PauseAnimation { duration: 150 } - PropertyAction { matchProperties: "z" } - NumberAnimation { matchProperties: "scale"; duration: 150; } + PropertyAction { properties: "z" } + NumberAnimation { properties: "scale"; duration: 150; } } }, Transition { from: "selected" SequentialAnimation { - NumberAnimation { matchProperties: "scale"; duration: 150 } - PropertyAction { matchProperties: "z" } + NumberAnimation { properties: "scale"; duration: 150 } + PropertyAction { properties: "z" } } } ] diff --git a/examples/declarative/states/states.qml b/examples/declarative/states/states.qml index 6f6b40f..89f2421 100644 --- a/examples/declarative/states/states.qml +++ b/examples/declarative/states/states.qml @@ -10,7 +10,7 @@ Rectangle { anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = '' } + MouseArea { anchors.fill: parent; onClicked: page.state = '' } } // Another target region. Clicking in here sets the state to 'Position1' @@ -19,7 +19,7 @@ Rectangle { anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } } // Another target region. Clicking in here sets the state to 'Position2' @@ -28,7 +28,7 @@ Rectangle { anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } } // The image which will be moved when my state changes diff --git a/examples/declarative/states/transitions.qml b/examples/declarative/states/transitions.qml index 925d90e..48d5f60 100644 --- a/examples/declarative/states/transitions.qml +++ b/examples/declarative/states/transitions.qml @@ -10,7 +10,7 @@ Rectangle { anchors { left: parent.left; top: parent.top; leftMargin: 10; topMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = '' } + MouseArea { anchors.fill: parent; onClicked: page.state = '' } } // Another target region. Clicking in here sets the state to 'Position1' @@ -19,7 +19,7 @@ Rectangle { anchors { right: parent.right; verticalCenter: parent.verticalCenter; rightMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position1' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position1' } } // Another target region. Clicking in here sets the state to 'Position2' @@ -28,7 +28,7 @@ Rectangle { anchors { left: parent.left; bottom: parent.bottom; leftMargin: 10; bottomMargin: 20 } width: 64; height: 64; radius: 6 color: "Transparent"; border.color: "Gray" - MouseRegion { anchors.fill: parent; onClicked: page.state = 'Position2' } + MouseArea { anchors.fill: parent; onClicked: page.state = 'Position2' } } // The image which will be moved when my state changes @@ -48,23 +48,23 @@ Rectangle { } ] - // transitions define how the matchProperties change. + // transitions define how the properties change. transitions: [ // When transitioning to 'Position1' move x,y over a duration of 1 second, // with easeOutBounce easing function. Transition { from: "*"; to: "Position1" - NumberAnimation { matchProperties: "x,y"; easing: "easeOutBounce"; duration: 1000 } + NumberAnimation { properties: "x,y"; easing: "easeOutBounce"; duration: 1000 } }, // When transitioning to 'Position2' move x,y over a duration of 2 seconds, // with easeInOutQuad easing function. Transition { from: "*"; to: "Position2" - NumberAnimation { matchProperties: "x,y"; easing: "easeInOutQuad"; duration: 2000 } + NumberAnimation { properties: "x,y"; easing: "easeInOutQuad"; duration: 2000 } }, // For any other state changes move x,y linearly over duration of 200ms. Transition { - NumberAnimation { matchProperties: "x,y"; duration: 200 } + NumberAnimation { properties: "x,y"; duration: 200 } } ] } diff --git a/examples/declarative/tabwidget/TabWidget.qml b/examples/declarative/tabwidget/TabWidget.qml index c56f41e..f0dfee8 100644 --- a/examples/declarative/tabwidget/TabWidget.qml +++ b/examples/declarative/tabwidget/TabWidget.qml @@ -25,7 +25,7 @@ Item { text: stack.children[index].title elide: Text.ElideRight } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: page.current = index } diff --git a/examples/declarative/tic-tac-toe/content/TicTac.qml b/examples/declarative/tic-tac-toe/content/TicTac.qml index eb80743..ccb7b78 100644 --- a/examples/declarative/tic-tac-toe/content/TicTac.qml +++ b/examples/declarative/tic-tac-toe/content/TicTac.qml @@ -13,7 +13,7 @@ Item { anchors.centerIn: parent } - MouseRegion { + MouseArea { anchors.fill: parent onClicked: parent.clicked() } diff --git a/examples/declarative/tutorials/helloworld/Cell.qml b/examples/declarative/tutorials/helloworld/Cell.qml index c38b40e..de4f3bb 100644 --- a/examples/declarative/tutorials/helloworld/Cell.qml +++ b/examples/declarative/tutorials/helloworld/Cell.qml @@ -23,7 +23,7 @@ Item { //![2] //![3] - MouseRegion { + MouseArea { anchors.fill: parent onClicked: container.clicked(container.color) } diff --git a/examples/declarative/tutorials/helloworld/tutorial3.qml b/examples/declarative/tutorials/helloworld/tutorial3.qml index 0f27f86..9eaa009 100644 --- a/examples/declarative/tutorials/helloworld/tutorial3.qml +++ b/examples/declarative/tutorials/helloworld/tutorial3.qml @@ -14,7 +14,7 @@ Rectangle { transformOrigin: Item.Center //![1] - MouseRegion { id: mouseRegion; anchors.fill: parent } + MouseArea { id: mouseRegion; anchors.fill: parent } //![1] //![2] @@ -28,7 +28,7 @@ Rectangle { transitions: Transition { from: ""; to: "down"; reversible: true ParallelAnimation { - NumberAnimation { matchProperties: "y,rotation"; duration: 500; easing: "easeInOutQuad" } + NumberAnimation { properties: "y,rotation"; duration: 500; easing: "easeInOutQuad" } ColorAnimation { duration: 500 } } } diff --git a/examples/declarative/tutorials/samegame/samegame1/Button.qml b/examples/declarative/tutorials/samegame/samegame1/Button.qml index 85e6777..2e31ff8 100644 --- a/examples/declarative/tutorials/samegame/samegame1/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame1/Button.qml @@ -18,7 +18,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame2/Button.qml b/examples/declarative/tutorials/samegame/samegame2/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame2/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame2/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame3/Button.qml b/examples/declarative/tutorials/samegame/samegame3/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml index 96dc246..9d35832 100644 --- a/examples/declarative/tutorials/samegame/samegame3/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame3/Dialog.qml @@ -18,6 +18,6 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } } //![0] diff --git a/examples/declarative/tutorials/samegame/samegame3/samegame.qml b/examples/declarative/tutorials/samegame/samegame3/samegame.qml index 8bdb428..c616397 100644 --- a/examples/declarative/tutorials/samegame/samegame3/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame3/samegame.qml @@ -27,7 +27,7 @@ Rectangle { width: parent.width - (parent.width % tileSize); height: parent.height - (parent.height % tileSize); - MouseRegion { + MouseArea { id: gameMR anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); } diff --git a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml index 2eb2ceb..4c2ba43 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/BoomBlock.qml @@ -24,7 +24,7 @@ Item { id:block } } opacity: 0 - opacity: Behavior { NumberAnimation { matchProperties:"opacity"; duration: 200 } } + opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } anchors.fill: parent } //![2] diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml index 63cd555..6629302 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Button.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Button.qml @@ -17,7 +17,7 @@ Rectangle { GradientStop { position: 1.0; color: activePalette.button } } - MouseRegion { id: mr; anchors.fill: parent; onClicked: container.clicked() } + MouseArea { id: mr; anchors.fill: parent; onClicked: container.clicked() } Text { id: txtItem; text: container.text; anchors.centerIn: container; color: activePalette.buttonText diff --git a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml index 3371d53..ed9fd32 100644 --- a/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml +++ b/examples/declarative/tutorials/samegame/samegame4/content/Dialog.qml @@ -17,5 +17,5 @@ Rectangle { NumberAnimation { duration: 1000 } } Text { id: myText; anchors.centerIn: parent; text: "Hello World!" } - MouseRegion { id: mr; anchors.fill: parent; onClicked: forceClose(); } + MouseArea { id: mr; anchors.fill: parent; onClicked: forceClose(); } } diff --git a/examples/declarative/tutorials/samegame/samegame4/samegame.qml b/examples/declarative/tutorials/samegame/samegame4/samegame.qml index 19b929f..a228e60 100644 --- a/examples/declarative/tutorials/samegame/samegame4/samegame.qml +++ b/examples/declarative/tutorials/samegame/samegame4/samegame.qml @@ -27,7 +27,7 @@ Rectangle { width: parent.width - (parent.width % getTileSize()); height: parent.height - (parent.height % getTileSize()); - MouseRegion { + MouseArea { id: gameMR anchors.fill: parent; onClicked: handleClick(mouse.x,mouse.y); } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 3a7ffa9..c39f99b 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -48,7 +48,7 @@ Rectangle { x: stickyImage.x width: stickyImage.width * stickyImage.scale height: stickyImage.height * stickyImage.scale - MouseRegion { + MouseArea { id: mouse onClicked: { myText.focus = true } anchors.fill: parent @@ -71,7 +71,7 @@ Rectangle { } transitions: Transition { - NumberAnimation { matchProperties: "rotation,scale"; duration: 200 } + NumberAnimation { properties: "rotation,scale"; duration: 200 } } } } diff --git a/examples/declarative/webview/autosize.qml b/examples/declarative/webview/autosize.qml index 1614906..74c6844 100644 --- a/examples/declarative/webview/autosize.qml +++ b/examples/declarative/webview/autosize.qml @@ -1,7 +1,7 @@ import Qt 4.6 // The WebView size is determined by the width, height, -// preferredWidth, and preferredHeight matchProperties. +// preferredWidth, and preferredHeight properties. Rectangle { id: rect color: "white" diff --git a/examples/declarative/webview/content/FieldText.qml b/examples/declarative/webview/content/FieldText.qml index 6b1d271..19b6acc 100644 --- a/examples/declarative/webview/content/FieldText.qml +++ b/examples/declarative/webview/content/FieldText.qml @@ -93,17 +93,17 @@ Item { } } - MouseRegion { + MouseArea { anchors.fill: cancelIcon onClicked: { reset() } } - MouseRegion { + MouseArea { anchors.fill: confirmIcon onClicked: { confirm() } } - MouseRegion { + MouseArea { id: editRegion anchors.fill: textEdit onClicked: { edit() } @@ -149,7 +149,7 @@ Item { to: "*" reversible: true NumberAnimation { - matchProperties: "opacity,leftMargin,rightMargin" + properties: "opacity,leftMargin,rightMargin" duration: 200 } ColorAnimation { diff --git a/examples/declarative/webview/evalandattach.html b/examples/declarative/webview/evalandattach.html index c0992bb..48a1c33 100644 --- a/examples/declarative/webview/evalandattach.html +++ b/examples/declarative/webview/evalandattach.html @@ -1,7 +1,7 @@ <body bgcolor=gray onload="ftext.confirmed.connect (ftext_confirmed); "> <script> do_it = function () {var oPressed = document.getElementById('pressed'); - oPressed.innerHTML = 'MouseRegion in QML clicked!';}; + oPressed.innerHTML = 'MouseArea in QML clicked!';}; ftext_confirmed = function () { statusText1.text = ftext.text; var oT = document.getElementById('htmlTextInput'); oT.value = ftext.text } </script> <table border=1> diff --git a/examples/declarative/webview/evalandattach.qml b/examples/declarative/webview/evalandattach.qml index 1b211c9..94301cd 100644 --- a/examples/declarative/webview/evalandattach.qml +++ b/examples/declarative/webview/evalandattach.qml @@ -21,7 +21,7 @@ Item { anchors.right: parent.right } - MouseRegion { + MouseArea { anchors.fill: teksti onClicked: { webView.evaluateJavaScript ("do_it()") } } diff --git a/examples/declarative/workerscript/workerscript.qml b/examples/declarative/workerscript/workerscript.qml index e36d4d4..0566f1f 100644 --- a/examples/declarative/workerscript/workerscript.qml +++ b/examples/declarative/workerscript/workerscript.qml @@ -20,7 +20,7 @@ Rectangle { anchors.leftMargin: 20 color: "red" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myWorker.sendMessage( { rectangle: "red", x: mouse.x, y: mouse.y } ); } @@ -32,7 +32,7 @@ Rectangle { anchors.rightMargin: 20 color: "blue" - MouseRegion { + MouseArea { anchors.fill: parent onClicked: myWorker.sendMessage( { rectangle: "blue", x: mouse.x, y: mouse.y } ); } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index bd14516..b80e29c 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -22,7 +22,7 @@ Rectangle { id: delegate height: wrapper.height + 10 - MouseRegion { + MouseArea { anchors.fill: wrapper onPressed: delegate.ListView.view.currentIndex = index; onClicked: if (wrapper.state == 'Details') wrapper.state = ''; else wrapper.state = 'Details'; @@ -61,8 +61,8 @@ Rectangle { transitions: Transition { from: "*"; to: "Details"; reversible: true SequentialAnimation { - NumberAnimation { duration: 200; matchProperties: "height"; easing: "easeOutQuad" } - NumberAnimation { duration: 200; matchProperties: "opacity" } + NumberAnimation { duration: 200; properties: "height"; easing: "easeOutQuad" } + NumberAnimation { duration: 200; properties: "opacity" } } } } diff --git a/examples/declarative/xmlhttprequest/test.qml b/examples/declarative/xmlhttprequest/test.qml index 18e328b..15ac54b 100644 --- a/examples/declarative/xmlhttprequest/test.qml +++ b/examples/declarative/xmlhttprequest/test.qml @@ -3,7 +3,7 @@ import Qt 4.6 Rectangle { width: 800; height: 600 - MouseRegion { + MouseArea { anchors.fill: parent onClicked: { diff --git a/examples/multimedia/audioinput/audioinput.cpp b/examples/multimedia/audioinput/audioinput.cpp index fbf4dc4..b01a396 100644 --- a/examples/multimedia/audioinput/audioinput.cpp +++ b/examples/multimedia/audioinput/audioinput.cpp @@ -48,16 +48,47 @@ #include <QAudioDeviceInfo> #include <QAudioInput> + +#include <QtCore/qendian.h> + #include "audioinput.h" -#define BUFFER_SIZE 4096 +const QString InputTest::PushModeLabel(tr("Enable push mode")); +const QString InputTest::PullModeLabel(tr("Enable pull mode")); +const QString InputTest::SuspendLabel(tr("Suspend recording")); +const QString InputTest::ResumeLabel(tr("Resume recording")); -AudioInfo::AudioInfo(QObject *parent, QAudioInput *device) - :QIODevice(parent) -{ - input = device; +const int BufferSize = 4096; + +AudioInfo::AudioInfo(const QAudioFormat &format, QObject *parent) + : QIODevice(parent) + , m_format(format) + , m_maxAmplitude(0) + , m_level(0.0) - m_maxValue = 0; +{ + switch (m_format.sampleSize()) { + case 8: + switch (m_format.sampleType()) { + case QAudioFormat::UnSignedInt: + m_maxAmplitude = 255; + break; + case QAudioFormat::SignedInt: + m_maxAmplitude = 127; + break; + } + break; + case 16: + switch (m_format.sampleType()) { + case QAudioFormat::UnSignedInt: + m_maxAmplitude = 65535; + break; + case QAudioFormat::SignedInt: + m_maxAmplitude = 32767; + break; + } + break; + } } AudioInfo::~AudioInfo() @@ -84,48 +115,56 @@ qint64 AudioInfo::readData(char *data, qint64 maxlen) qint64 AudioInfo::writeData(const char *data, qint64 len) { - int samples = len/2; // 2 bytes per sample - int maxAmp = 32768; // max for S16 samples - bool clipping = false; - - m_maxValue = 0; - - qint16 *s = (qint16*)data; - - // sample format is S16LE, only! - - for (int i = 0; i < samples; ++i) { - qint16 sample = *s; - s++; - if (abs(sample) > m_maxValue) m_maxValue = abs(sample); + if (m_maxAmplitude) { + Q_ASSERT(m_format.sampleSize() % 8 == 0); + const int channelBytes = m_format.sampleSize() / 8; + const int sampleBytes = m_format.channels() * channelBytes; + Q_ASSERT(len % sampleBytes == 0); + const int numSamples = len / sampleBytes; + + quint16 maxValue = 0; + const unsigned char *ptr = reinterpret_cast<const unsigned char *>(data); + + for (int i = 0; i < numSamples; ++i) { + for(int j = 0; j < m_format.channels(); ++j) { + quint16 value = 0; + + if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::UnSignedInt) { + value = *reinterpret_cast<const quint8*>(ptr); + } else if (m_format.sampleSize() == 8 && m_format.sampleType() == QAudioFormat::SignedInt) { + value = qAbs(*reinterpret_cast<const qint8*>(ptr)); + } else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::UnSignedInt) { + if (m_format.byteOrder() == QAudioFormat::LittleEndian) + value = qFromLittleEndian<quint16>(ptr); + else + value = qFromBigEndian<quint16>(ptr); + } else if (m_format.sampleSize() == 16 && m_format.sampleType() == QAudioFormat::SignedInt) { + if (m_format.byteOrder() == QAudioFormat::LittleEndian) + value = qAbs(qFromLittleEndian<qint16>(ptr)); + else + value = qAbs(qFromBigEndian<qint16>(ptr)); + } + + maxValue = qMax(value, maxValue); + ptr += channelBytes; + } + } + + maxValue = qMin(maxValue, m_maxAmplitude); + m_level = qreal(maxValue) / m_maxAmplitude; } - // check for clipping - if (m_maxValue >= (maxAmp - 1)) - clipping = true; - - float value = ((float)m_maxValue/(float)maxAmp); - if (clipping) - m_maxValue = 100; - else - m_maxValue = (int)(value*100); emit update(); - return len; } -int AudioInfo::LinearMax() -{ - return m_maxValue; -} - RenderArea::RenderArea(QWidget *parent) : QWidget(parent) { setBackgroundRole(QPalette::Base); setAutoFillBackground(true); - level = 0; + m_level = 0; setMinimumHeight(30); setMinimumWidth(200); } @@ -139,12 +178,12 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) painter.viewport().top()+10, painter.viewport().right()-20, painter.viewport().bottom()-20)); - if (level == 0) + if (m_level == 0.0) return; painter.setPen(Qt::red); - int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*level/100; + int pos = ((painter.viewport().right()-20)-(painter.viewport().left()+11))*m_level; for (int i = 0; i < 10; ++i) { int x1 = painter.viewport().left()+11; int y1 = painter.viewport().top()+10+i; @@ -157,156 +196,174 @@ void RenderArea::paintEvent(QPaintEvent * /* event */) } } -void RenderArea::setLevel(int value) +void RenderArea::setLevel(qreal value) { - level = value; + m_level = value; repaint(); } InputTest::InputTest() + : m_canvas(0) + , m_modeButton(0) + , m_suspendResumeButton(0) + , m_deviceBox(0) + , m_device(QAudioDeviceInfo::defaultInputDevice()) + , m_audioInfo(0) + , m_audioInput(0) + , m_input(0) + , m_pullMode(false) + , m_buffer(BufferSize, 0) { - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; + initializeWindow(); + initializeAudio(); +} + +InputTest::~InputTest() {} - canvas = new RenderArea; - layout->addWidget(canvas); +void InputTest::initializeWindow() +{ + QScopedPointer<QWidget> window(new QWidget); + QScopedPointer<QVBoxLayout> layout(new QVBoxLayout); - deviceBox = new QComboBox(this); + m_canvas = new RenderArea(this); + layout->addWidget(m_canvas); + + m_deviceBox = new QComboBox(this); QList<QAudioDeviceInfo> devices = QAudioDeviceInfo::availableDevices(QAudio::AudioInput); for(int i = 0; i < devices.size(); ++i) - deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); + m_deviceBox->addItem(devices.at(i).deviceName(), qVariantFromValue(devices.at(i))); - connect(deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); + connect(m_deviceBox, SIGNAL(activated(int)), SLOT(deviceChanged(int))); + layout->addWidget(m_deviceBox); - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button, SIGNAL(clicked()), SLOT(toggleMode())); - layout->addWidget(button); + m_modeButton = new QPushButton(this); + m_modeButton->setText(PushModeLabel); + connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode())); + layout->addWidget(m_modeButton); - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2, SIGNAL(clicked()), SLOT(toggleSuspend())); - layout->addWidget(button2); + m_suspendResumeButton = new QPushButton(this); + m_suspendResumeButton->setText(SuspendLabel); + connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspend())); + layout->addWidget(m_suspendResumeButton); - window->setLayout(layout); - setCentralWidget(window); - window->show(); + window->setLayout(layout.data()); + layout.take(); // ownership transferred - buffer = new char[BUFFER_SIZE]; + setCentralWidget(window.data()); + QWidget *const windowPtr = window.take(); // ownership transferred + windowPtr->show(); +} - pullMode = true; +void InputTest::initializeAudio() +{ + m_pullMode = true; - format.setFrequency(8000); - format.setChannels(1); - format.setSampleSize(16); - format.setSampleType(QAudioFormat::SignedInt); - format.setByteOrder(QAudioFormat::LittleEndian); - format.setCodec("audio/pcm"); + m_format.setFrequency(8000); + m_format.setChannels(1); + m_format.setSampleSize(16); + m_format.setSampleType(QAudioFormat::SignedInt); + m_format.setByteOrder(QAudioFormat::LittleEndian); + m_format.setCodec("audio/pcm"); QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); - if (!info.isFormatSupported(format)) { - qWarning()<<"default format not supported try to use nearest"; - format = info.nearestFormat(format); + if (!info.isFormatSupported(m_format)) { + qWarning() << "Default format not supported - trying to use nearest"; + m_format = info.nearestFormat(m_format); } - if(format.sampleSize() != 16) { - qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; - audioInput = 0; - button->setDisabled(true); - button2->setDisabled(true); - return; - } + m_audioInfo = new AudioInfo(m_format, this); + connect(m_audioInfo, SIGNAL(update()), SLOT(refreshDisplay())); - audioInput = new QAudioInput(format,this); - connect(audioInput, SIGNAL(notify()), SLOT(status())); - connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo = new AudioInfo(this,audioInput); - connect(audioinfo, SIGNAL(update()), SLOT(refreshDisplay())); - audioinfo->start(); - audioInput->start(audioinfo); + createAudioInput(); } -InputTest::~InputTest() {} +void InputTest::createAudioInput() +{ + m_audioInput = new QAudioInput(m_device, m_format, this); + connect(m_audioInput, SIGNAL(notify()), SLOT(notified())); + connect(m_audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); + m_audioInfo->start(); + m_audioInput->start(m_audioInfo); +} -void InputTest::status() +void InputTest::notified() { - qWarning()<<"bytesReady = "<<audioInput->bytesReady()<<" bytes, elapsedUSecs = "<<audioInput->elapsedUSecs()<<", processedUSecs = "<<audioInput->processedUSecs(); + qWarning() << "bytesReady = " << m_audioInput->bytesReady() + << ", " << "elapsedUSecs = " <<m_audioInput->elapsedUSecs() + << ", " << "processedUSecs = "<<m_audioInput->processedUSecs(); } void InputTest::readMore() { - if(!audioInput) + if(!m_audioInput) return; - qint64 len = audioInput->bytesReady(); + qint64 len = m_audioInput->bytesReady(); if(len > 4096) len = 4096; - qint64 l = input->read(buffer,len); + qint64 l = m_input->read(m_buffer.data(), len); if(l > 0) { - audioinfo->write(buffer,l); + m_audioInfo->write(m_buffer.constData(), l); } } void InputTest::toggleMode() { // Change bewteen pull and push modes - audioInput->stop(); + m_audioInput->stop(); - if (pullMode) { - button->setText(tr("Click for Pull Mode")); - input = audioInput->start(); - connect(input, SIGNAL(readyRead()), SLOT(readMore())); - pullMode = false; + if (m_pullMode) { + m_modeButton->setText(PullModeLabel); + m_input = m_audioInput->start(); + connect(m_input, SIGNAL(readyRead()), SLOT(readMore())); + m_pullMode = false; } else { - button->setText(tr("Click for Push Mode")); - pullMode = true; - audioInput->start(audioinfo); + m_modeButton->setText(PushModeLabel); + m_pullMode = true; + m_audioInput->start(m_audioInfo); } + + m_suspendResumeButton->setText(SuspendLabel); } void InputTest::toggleSuspend() { // toggle suspend/resume - if(audioInput->state() == QAudio::SuspendedState) { + if(m_audioInput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::ActiveState) { + m_audioInput->resume(); + m_suspendResumeButton->setText(SuspendLabel); + } else if (m_audioInput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; - audioInput->suspend(); - button2->setText("Click To Resume"); - } else if (audioInput->state() == QAudio::StoppedState) { + m_audioInput->suspend(); + m_suspendResumeButton->setText(ResumeLabel); + } else if (m_audioInput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; - audioInput->resume(); - button2->setText("Click To Suspend"); - } else if (audioInput->state() == QAudio::IdleState) { + m_audioInput->resume(); + m_suspendResumeButton->setText(SuspendLabel); + } else if (m_audioInput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } } -void InputTest::state(QAudio::State state) +void InputTest::stateChanged(QAudio::State state) { - qWarning() << " state=" << state; + qWarning() << "state = " << state; } void InputTest::refreshDisplay() { - canvas->setLevel(audioinfo->LinearMax()); - canvas->repaint(); + m_canvas->setLevel(m_audioInfo->level()); + m_canvas->repaint(); } -void InputTest::deviceChanged(int idx) +void InputTest::deviceChanged(int index) { - audioinfo->stop(); - audioInput->stop(); - audioInput->disconnect(this); - delete audioInput; - - device = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); - audioInput = new QAudioInput(device, format, this); - connect(audioInput, SIGNAL(notify()), SLOT(status())); - connect(audioInput, SIGNAL(stateChanged(QAudio::State)), SLOT(state(QAudio::State))); - audioinfo->start(); - audioInput->start(audioinfo); + m_audioInfo->stop(); + m_audioInput->stop(); + m_audioInput->disconnect(this); + delete m_audioInput; + + m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>(); + createAudioInput(); } diff --git a/examples/multimedia/audioinput/audioinput.h b/examples/multimedia/audioinput/audioinput.h index abe2be1..f87c682 100644 --- a/examples/multimedia/audioinput/audioinput.h +++ b/examples/multimedia/audioinput/audioinput.h @@ -45,6 +45,7 @@ #include <QMainWindow> #include <QPushButton> #include <QComboBox> +#include <QByteArray> #include <qaudioinput.h> @@ -52,21 +53,21 @@ class AudioInfo : public QIODevice { Q_OBJECT public: - AudioInfo(QObject *parent, QAudioInput *device); + AudioInfo(const QAudioFormat &format, QObject *parent); ~AudioInfo(); void start(); void stop(); - int LinearMax(); + qreal level() const { return m_level; } qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); - QAudioInput *input; - private: - int m_maxValue; + const QAudioFormat m_format; + quint16 m_maxAmplitude; + qreal m_level; // 0.0 <= m_level <= 1.0 signals: void update(); @@ -80,14 +81,14 @@ class RenderArea : public QWidget public: RenderArea(QWidget *parent = 0); - void setLevel(int value); + void setLevel(qreal value); protected: void paintEvent(QPaintEvent *event); private: - int level; - QPixmap pixmap; + qreal m_level; + QPixmap m_pixmap; }; class InputTest : public QMainWindow @@ -97,29 +98,38 @@ public: InputTest(); ~InputTest(); +private: + void initializeWindow(); + void initializeAudio(); + void createAudioInput(); + private slots: void refreshDisplay(); - void status(); + void notified(); void readMore(); void toggleMode(); void toggleSuspend(); - void state(QAudio::State s); - void deviceChanged(int idx); + void stateChanged(QAudio::State state); + void deviceChanged(int index); private: - AudioInfo *audioinfo; - QAudioDeviceInfo device; - QAudioFormat format; - QAudioInput *audioInput; - QIODevice *input; - RenderArea *canvas; - - bool pullMode; - - QPushButton *button; - QPushButton *button2; - QComboBox *deviceBox; - - char *buffer; + // Owned by layout + RenderArea *m_canvas; + QPushButton *m_modeButton; + QPushButton *m_suspendResumeButton; + QComboBox *m_deviceBox; + + AudioInfo *m_audioInfo; + QAudioDeviceInfo m_device; + QAudioFormat m_format; + QAudioInput *m_audioInput; + QIODevice *m_input; + bool m_pullMode; + QByteArray m_buffer; + + static const QString PushModeLabel; + static const QString PullModeLabel; + static const QString SuspendLabel; + static const QString ResumeLabel; }; diff --git a/examples/multimedia/audiooutput/audiooutput.cpp b/examples/multimedia/audiooutput/audiooutput.cpp index b44accd..cbadf02 100644 --- a/examples/multimedia/audiooutput/audiooutput.cpp +++ b/examples/multimedia/audiooutput/audiooutput.cpp @@ -44,30 +44,34 @@ #include <QAudioOutput> #include <QAudioDeviceInfo> +#include <QtCore/qmath.h> +#include <QtCore/qendian.h> #include "audiooutput.h" -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +const QString AudioTest::PushModeLabel(tr("Enable push mode")); +const QString AudioTest::PullModeLabel(tr("Enable pull mode")); +const QString AudioTest::SuspendLabel(tr("Suspend playback")); +const QString AudioTest::ResumeLabel(tr("Resume playback")); -#define SECONDS 1 -#define FREQ 600 -#define SYSTEM_FREQ 44100 +const int DurationSeconds = 1; +const int ToneFrequencyHz = 600; +const int DataFrequencyHz = 44100; +const int BufferSize = 32768; -Generator::Generator(QObject *parent) - :QIODevice( parent ) + +Generator::Generator(const QAudioFormat &format, + qint64 durationUs, + int frequency, + QObject *parent) + : QIODevice(parent) + , m_pos(0) { - finished = false; - buffer = new char[SECONDS*SYSTEM_FREQ*4+1000]; - t=buffer; - len=fillData(t,FREQ,SECONDS); /* mono FREQHz sine */ - pos = 0; - total = len; + generateData(format, durationUs, frequency); } Generator::~Generator() { - delete [] buffer; + } void Generator::start() @@ -77,47 +81,65 @@ void Generator::start() void Generator::stop() { + m_pos = 0; close(); } -int Generator::putShort(char *t, unsigned int value) +void Generator::generateData(const QAudioFormat &format, qint64 durationUs, int frequency) { - *(unsigned char *)(t++)=value&255; - *(unsigned char *)(t)=(value/256)&255; - return 2; -} - -int Generator::fillData(char *start, int frequency, int seconds) -{ - int i, len=0; - int value; - for(i=0; i<seconds*SYSTEM_FREQ; i++) { - value=(int)(32767.0*sin(2.0*M_PI*((double)(i))*(double)(frequency)/SYSTEM_FREQ)); - putShort(start, value); - start += 4; - len+=2; + const int channelBytes = format.sampleSize() / 8; + const int sampleBytes = format.channels() * channelBytes; + + qint64 length = (format.frequency() * format.channels() * (format.sampleSize() / 8)) + * durationUs / 100000; + + Q_ASSERT(length % sampleBytes == 0); + Q_UNUSED(sampleBytes) // suppress warning in release builds + + m_buffer.resize(length); + unsigned char *ptr = reinterpret_cast<unsigned char *>(m_buffer.data()); + int sampleIndex = 0; + + while (length) { + const qreal x = qSin(2 * M_PI * frequency * qreal(sampleIndex % format.frequency()) / format.frequency()); + for (int i=0; i<format.channels(); ++i) { + if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::UnSignedInt) { + const quint8 value = static_cast<quint8>((1.0 + x) / 2 * 255); + *reinterpret_cast<quint8*>(ptr) = value; + } else if (format.sampleSize() == 8 && format.sampleType() == QAudioFormat::SignedInt) { + const qint8 value = static_cast<qint8>(x * 127); + *reinterpret_cast<quint8*>(ptr) = value; + } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::UnSignedInt) { + quint16 value = static_cast<quint16>((1.0 + x) / 2 * 65535); + if (format.byteOrder() == QAudioFormat::LittleEndian) + qToLittleEndian<quint16>(value, ptr); + else + qToBigEndian<quint16>(value, ptr); + } else if (format.sampleSize() == 16 && format.sampleType() == QAudioFormat::SignedInt) { + qint16 value = static_cast<qint16>(x * 32767); + if (format.byteOrder() == QAudioFormat::LittleEndian) + qToLittleEndian<qint16>(value, ptr); + else + qToBigEndian<qint16>(value, ptr); + } + + ptr += channelBytes; + length -= channelBytes; + } + ++sampleIndex; } - return len; } -qint64 Generator::readData(char *data, qint64 maxlen) +qint64 Generator::readData(char *data, qint64 len) { - int len = maxlen; - if (len > 16384) - len = 16384; - - if (len < (SECONDS*SYSTEM_FREQ*2)-pos) { - // Normal - memcpy(data,t+pos,len); - pos+=len; - return len; - } else { - // Whats left and reset to start - qint64 left = (SECONDS*SYSTEM_FREQ*2)-pos; - memcpy(data,t+pos,left); - pos=0; - return left; + qint64 total = 0; + while (len - total) { + const qint64 chunk = qMin((m_buffer.size() - m_pos), len - total); + memcpy(data, m_buffer.constData() + m_pos, chunk); + m_pos = (m_pos + chunk) % m_buffer.size(); + total += chunk; } + return total; } qint64 Generator::writeData(const char *data, qint64 len) @@ -128,158 +150,166 @@ qint64 Generator::writeData(const char *data, qint64 len) return 0; } -AudioTest::AudioTest() +qint64 Generator::bytesAvailable() const { - QWidget *window = new QWidget; - QVBoxLayout* layout = new QVBoxLayout; - - deviceBox = new QComboBox(this); - foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) - deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); - connect(deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); - layout->addWidget(deviceBox); - - button = new QPushButton(this); - button->setText(tr("Click for Push Mode")); - connect(button,SIGNAL(clicked()),SLOT(toggle())); - layout->addWidget(button); - - button2 = new QPushButton(this); - button2->setText(tr("Click To Suspend")); - connect(button2,SIGNAL(clicked()),SLOT(togglePlay())); - layout->addWidget(button2); - - window->setLayout(layout); - setCentralWidget(window); - window->show(); + return m_buffer.size() + QIODevice::bytesAvailable(); +} - buffer = new char[BUFFER_SIZE]; +AudioTest::AudioTest() + : m_pullTimer(new QTimer(this)) + , m_modeButton(0) + , m_suspendResumeButton(0) + , m_deviceBox(0) + , m_device(QAudioDeviceInfo::defaultOutputDevice()) + , m_generator(0) + , m_audioOutput(0) + , m_output(0) + , m_buffer(BufferSize, 0) +{ + initializeWindow(); + initializeAudio(); +} - gen = new Generator(this); +void AudioTest::initializeWindow() +{ + QScopedPointer<QWidget> window(new QWidget); + QScopedPointer<QVBoxLayout> layout(new QVBoxLayout); - pullMode = true; + m_deviceBox = new QComboBox(this); + foreach (const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) + m_deviceBox->addItem(deviceInfo.deviceName(), qVariantFromValue(deviceInfo)); + connect(m_deviceBox,SIGNAL(activated(int)),SLOT(deviceChanged(int))); + layout->addWidget(m_deviceBox); + + m_modeButton = new QPushButton(this); + m_modeButton->setText(PushModeLabel); + connect(m_modeButton, SIGNAL(clicked()), SLOT(toggleMode())); + layout->addWidget(m_modeButton); + + m_suspendResumeButton = new QPushButton(this); + m_suspendResumeButton->setText(SuspendLabel); + connect(m_suspendResumeButton, SIGNAL(clicked()), SLOT(toggleSuspendResume())); + layout->addWidget(m_suspendResumeButton); + + window->setLayout(layout.data()); + layout.take(); // ownership transferred + + setCentralWidget(window.data()); + QWidget *const windowPtr = window.take(); // ownership transferred + windowPtr->show(); +} - timer = new QTimer(this); - connect(timer,SIGNAL(timeout()),SLOT(writeMore())); +void AudioTest::initializeAudio() +{ + connect(m_pullTimer, SIGNAL(timeout()), SLOT(pullTimerExpired())); - gen->start(); + m_pullMode = true; - settings.setFrequency(SYSTEM_FREQ); - settings.setChannels(1); - settings.setSampleSize(16); - settings.setCodec("audio/pcm"); - settings.setByteOrder(QAudioFormat::LittleEndian); - settings.setSampleType(QAudioFormat::SignedInt); + m_format.setFrequency(DataFrequencyHz); + m_format.setChannels(1); + m_format.setSampleSize(16); + m_format.setCodec("audio/pcm"); + m_format.setByteOrder(QAudioFormat::LittleEndian); + m_format.setSampleType(QAudioFormat::SignedInt); QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); - if (!info.isFormatSupported(settings)) { - qWarning()<<"default format not supported try to use nearest"; - settings = info.nearestFormat(settings); + if (!info.isFormatSupported(m_format)) { + qWarning() << "Default format not supported - trying to use nearest"; + m_format = info.nearestFormat(m_format); } - if(settings.sampleSize() != 16) { - qWarning()<<"audio device doesn't support 16 bit samples, example cannot run"; - button->setDisabled(true); - button2->setDisabled(true); - audioOutput = 0; - return; - } + m_generator = new Generator(m_format, DurationSeconds*1000000, ToneFrequencyHz, this); - audioOutput = new QAudioOutput(settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); + createAudioOutput(); +} - audioOutput->start(gen); +void AudioTest::createAudioOutput() +{ + delete m_audioOutput; + m_audioOutput = 0; + m_audioOutput = new QAudioOutput(m_device, m_format, this); + connect(m_audioOutput, SIGNAL(notify()), SLOT(notified())); + connect(m_audioOutput, SIGNAL(stateChanged(QAudio::State)), SLOT(stateChanged(QAudio::State))); + m_generator->start(); + m_audioOutput->start(m_generator); } AudioTest::~AudioTest() { - delete [] buffer; + } -void AudioTest::deviceChanged(int idx) +void AudioTest::deviceChanged(int index) { - timer->stop(); - gen->stop(); - audioOutput->stop(); - audioOutput->disconnect(this); - delete audioOutput; - - device = deviceBox->itemData(idx).value<QAudioDeviceInfo>(); - audioOutput = new QAudioOutput(device,settings,this); - connect(audioOutput,SIGNAL(notify()),SLOT(status())); - connect(audioOutput,SIGNAL(stateChanged(QAudio::State)),SLOT(state(QAudio::State))); - gen->start(); - audioOutput->start(gen); + m_pullTimer->stop(); + m_generator->stop(); + m_audioOutput->stop(); + m_audioOutput->disconnect(this); + m_device = m_deviceBox->itemData(index).value<QAudioDeviceInfo>(); + createAudioOutput(); } -void AudioTest::status() +void AudioTest::notified() { - qWarning() << "byteFree = " << audioOutput->bytesFree() << " bytes, elapsedUSecs = " << audioOutput->elapsedUSecs() << ", processedUSecs = " << audioOutput->processedUSecs(); + qWarning() << "bytesFree = " << m_audioOutput->bytesFree() + << ", " << "elapsedUSecs = " << m_audioOutput->elapsedUSecs() + << ", " << "processedUSecs = " << m_audioOutput->processedUSecs(); } -void AudioTest::writeMore() +void AudioTest::pullTimerExpired() { - if (!audioOutput) - return; - - if (audioOutput->state() == QAudio::StoppedState) - return; - - int l; - int out; - - int chunks = audioOutput->bytesFree()/audioOutput->periodSize(); - while(chunks) { - l = gen->read(buffer,audioOutput->periodSize()); - if (l > 0) - out = output->write(buffer,l); - if (l != audioOutput->periodSize()) - break; - chunks--; + if (m_audioOutput && m_audioOutput->state() != QAudio::StoppedState) { + int chunks = m_audioOutput->bytesFree()/m_audioOutput->periodSize(); + while (chunks) { + const qint64 len = m_generator->read(m_buffer.data(), m_audioOutput->periodSize()); + if (len) + m_output->write(m_buffer.data(), len); + if (len != m_audioOutput->periodSize()) + break; + --chunks; + } } } -void AudioTest::toggle() +void AudioTest::toggleMode() { - // Change between pull and push modes - - timer->stop(); - audioOutput->stop(); - - if (pullMode) { - button->setText("Click for Pull Mode"); - output = audioOutput->start(); - pullMode = false; - timer->start(20); + m_pullTimer->stop(); + m_audioOutput->stop(); + + if (m_pullMode) { + m_modeButton->setText(PullModeLabel); + m_output = m_audioOutput->start(); + m_pullMode = false; + m_pullTimer->start(20); } else { - button->setText("Click for Push Mode"); - pullMode = true; - audioOutput->start(gen); + m_modeButton->setText(PushModeLabel); + m_pullMode = true; + m_audioOutput->start(m_generator); } + + m_suspendResumeButton->setText(SuspendLabel); } -void AudioTest::togglePlay() +void AudioTest::toggleSuspendResume() { - // toggle suspend/resume - if (audioOutput->state() == QAudio::SuspendedState) { + if (m_audioOutput->state() == QAudio::SuspendedState) { qWarning() << "status: Suspended, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::ActiveState) { + m_audioOutput->resume(); + m_suspendResumeButton->setText(SuspendLabel); + } else if (m_audioOutput->state() == QAudio::ActiveState) { qWarning() << "status: Active, suspend()"; - audioOutput->suspend(); - button2->setText("Click To Resume"); - } else if (audioOutput->state() == QAudio::StoppedState) { + m_audioOutput->suspend(); + m_suspendResumeButton->setText(ResumeLabel); + } else if (m_audioOutput->state() == QAudio::StoppedState) { qWarning() << "status: Stopped, resume()"; - audioOutput->resume(); - button2->setText("Click To Suspend"); - } else if (audioOutput->state() == QAudio::IdleState) { + m_audioOutput->resume(); + m_suspendResumeButton->setText(SuspendLabel); + } else if (m_audioOutput->state() == QAudio::IdleState) { qWarning() << "status: IdleState"; } } -void AudioTest::state(QAudio::State state) +void AudioTest::stateChanged(QAudio::State state) { - qWarning() << " state=" << state; + qWarning() << "state = " << state; } diff --git a/examples/multimedia/audiooutput/audiooutput.h b/examples/multimedia/audiooutput/audiooutput.h index 372cf78..889482b 100644 --- a/examples/multimedia/audiooutput/audiooutput.h +++ b/examples/multimedia/audiooutput/audiooutput.h @@ -41,14 +41,13 @@ #include <math.h> -#define BUFFER_SIZE 32768 - #include <QObject> #include <QMainWindow> #include <QIODevice> #include <QTimer> #include <QPushButton> #include <QComboBox> +#include <QByteArray> #include <QAudioOutput> @@ -56,26 +55,22 @@ class Generator : public QIODevice { Q_OBJECT public: - Generator(QObject *parent); + Generator(const QAudioFormat &format, qint64 durationUs, int frequency, QObject *parent); ~Generator(); void start(); void stop(); - char *t; - int len; - int pos; - int total; - char *buffer; - bool finished; - int chunk_size; - qint64 readData(char *data, qint64 maxlen); qint64 writeData(const char *data, qint64 len); + qint64 bytesAvailable() const; private: - int putShort(char *t, unsigned int value); - int fillData(char *start, int frequency, int seconds); + void generateData(const QAudioFormat &format, qint64 durationUs, int frequency); + +private: + qint64 m_pos; + QByteArray m_buffer; }; class AudioTest : public QMainWindow @@ -85,26 +80,39 @@ public: AudioTest(); ~AudioTest(); - QAudioDeviceInfo device; - Generator* gen; - QAudioOutput* audioOutput; - QIODevice* output; - QTimer* timer; - QAudioFormat settings; +private: + void initializeWindow(); + void initializeAudio(); + void createAudioOutput(); + +private: + QTimer* m_pullTimer; + + // Owned by layout + QPushButton* m_modeButton; + QPushButton* m_suspendResumeButton; + QComboBox* m_deviceBox; + + QAudioDeviceInfo m_device; + Generator* m_generator; + QAudioOutput* m_audioOutput; + QIODevice* m_output; // not owned + QAudioFormat m_format; - bool pullMode; - char* buffer; + bool m_pullMode; + QByteArray m_buffer; - QPushButton* button; - QPushButton* button2; - QComboBox* deviceBox; + static const QString PushModeLabel; + static const QString PullModeLabel; + static const QString SuspendLabel; + static const QString ResumeLabel; private slots: - void status(); - void writeMore(); - void toggle(); - void togglePlay(); - void state(QAudio::State s); - void deviceChanged(int idx); + void notified(); + void pullTimerExpired(); + void toggleMode(); + void toggleSuspendResume(); + void stateChanged(QAudio::State state); + void deviceChanged(int index); }; |