diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-09-15 06:23:57 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-09-15 06:23:57 (GMT) |
commit | b43b430b0668d145e31fd0445ed9d272270a576c (patch) | |
tree | 0cc28e21844da6d8717c9e47a51428a89e12d4b3 /examples | |
parent | 8cad28ef7abf92cab034ae3586e24cd0b8be38a2 (diff) | |
parent | 7c6bc5a25d11a9d455b5bf96cb5229f78790db3a (diff) | |
download | Qt-b43b430b0668d145e31fd0445ed9d272270a576c.zip Qt-b43b430b0668d145e31fd0445ed9d272270a576c.tar.gz Qt-b43b430b0668d145e31fd0445ed9d272270a576c.tar.bz2 |
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'examples')
35 files changed, 286 insertions, 102 deletions
diff --git a/examples/declarative/aspectratio/face_fit_animated.qml b/examples/declarative/aspectratio/face_fit_animated.qml index 2768150..7db1c80 100644 --- a/examples/declarative/aspectratio/face_fit_animated.qml +++ b/examples/declarative/aspectratio/face_fit_animated.qml @@ -16,7 +16,7 @@ Rectangle { source: "pics/face.png" x: (parent.width-width*scale)/2 y: (parent.height-height*scale)/2 - scale: Follow { + scale: SpringFollow { source: Math.max(Math.min(Image.parent.width/Image.width*1.333,Image.parent.height/Image.height), Math.min(Image.parent.width/Image.width,Image.parent.height/Image.height*1.333)) spring: 1 diff --git a/examples/declarative/clock/Clock.qml b/examples/declarative/clock/Clock.qml index e152be3..6064dd4 100644 --- a/examples/declarative/clock/Clock.qml +++ b/examples/declarative/clock/Clock.qml @@ -28,7 +28,7 @@ Item { id: HourRotation origin.x: 4; origin.y: 45 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.hours * 50 * 3 + Clock.minutes / 2 @@ -44,7 +44,7 @@ Item { id: MinuteRotation origin.x: 4; origin.y: 70 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 2 damping: .2 source: Clock.minutes * 6 @@ -60,7 +60,7 @@ Item { id: SecondRotation origin.x: 2; origin.y: 60 angle: 0 - angle: Follow { + angle: SpringFollow { spring: 5 damping: .25 modulus: 360 diff --git a/examples/declarative/dial/DialLibrary/Dial.qml b/examples/declarative/dial/DialLibrary/Dial.qml index f53b25e..1a163a8 100644 --- a/examples/declarative/dial/DialLibrary/Dial.qml +++ b/examples/declarative/dial/DialLibrary/Dial.qml @@ -26,8 +26,8 @@ Item { id: NeedleRotation origin.x: 7; origin.y: 65 angle: -130 - angle: Follow { -id: MyFollow + angle: SpringFollow { + id: MyFollow spring: 1.4 damping: .15 source: Math.min(Math.max(-130, Root.value*2.2 - 130), 133) diff --git a/examples/declarative/extending/adding/example.qml b/examples/declarative/extending/adding/example.qml index ba7af7a..c608f94 100644 --- a/examples/declarative/extending/adding/example.qml +++ b/examples/declarative/extending/adding/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] Person { diff --git a/examples/declarative/extending/attached/example.qml b/examples/declarative/extending/attached/example.qml index 20233f6..952eb93 100644 --- a/examples/declarative/extending/attached/example.qml +++ b/examples/declarative/extending/attached/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 BirthdayParty { celebrant: Boy { diff --git a/examples/declarative/extending/binding/example.qml b/examples/declarative/extending/binding/example.qml index cedb8bd..1651b7a 100644 --- a/examples/declarative/extending/binding/example.qml +++ b/examples/declarative/extending/binding/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/coercion/example.qml b/examples/declarative/extending/coercion/example.qml index 5090782..64d26b0 100644 --- a/examples/declarative/extending/coercion/example.qml +++ b/examples/declarative/extending/coercion/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/default/example.qml b/examples/declarative/extending/default/example.qml index 5fe693a..58035f9 100644 --- a/examples/declarative/extending/default/example.qml +++ b/examples/declarative/extending/default/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/extended/example.qml b/examples/declarative/extending/extended/example.qml index a276211..985ce20 100644 --- a/examples/declarative/extending/extended/example.qml +++ b/examples/declarative/extending/extended/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] QLineEdit { diff --git a/examples/declarative/extending/extended/lineedit.cpp b/examples/declarative/extending/extended/lineedit.cpp index fe4fdc3..f11d22e 100644 --- a/examples/declarative/extending/extended/lineedit.cpp +++ b/examples/declarative/extending/extended/lineedit.cpp @@ -63,4 +63,4 @@ int LineEditExtension::setBottomMargin(int m) } QML_DECLARE_TYPE(QLineEdit); -QML_DEFINE_EXTENDED_TYPE(QLineEdit, QLineEdit, LineEditExtension); +QML_DEFINE_EXTENDED_TYPE(People, 1, 0, 0, QLineEdit, QLineEdit, LineEditExtension); diff --git a/examples/declarative/extending/grouped/example.qml b/examples/declarative/extending/grouped/example.qml index 1be7abe..55912ed 100644 --- a/examples/declarative/extending/grouped/example.qml +++ b/examples/declarative/extending/grouped/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/properties/example.qml b/examples/declarative/extending/properties/example.qml index 326105a..9594a84 100644 --- a/examples/declarative/extending/properties/example.qml +++ b/examples/declarative/extending/properties/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/signal/example.qml b/examples/declarative/extending/signal/example.qml index 1cbaab4..e46bf32 100644 --- a/examples/declarative/extending/signal/example.qml +++ b/examples/declarative/extending/signal/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/extending/valuesource/example.qml b/examples/declarative/extending/valuesource/example.qml index aba2796..6d47350 100644 --- a/examples/declarative/extending/valuesource/example.qml +++ b/examples/declarative/extending/valuesource/example.qml @@ -1,4 +1,4 @@ -import Qt 4.6 +import People 1.0 // ![0] BirthdayParty { diff --git a/examples/declarative/focusscope/test3.qml b/examples/declarative/focusscope/test3.qml index 51fa35a..8a53c3a 100644 --- a/examples/declarative/focusscope/test3.qml +++ b/examples/declarative/focusscope/test3.qml @@ -39,7 +39,9 @@ Rectangle { focus: true model: Model delegate: VerticalDelegate - currentItemPositioning: "SnapAuto" + preferredHighlightBegin: 100 + preferredHighlightEnd: 101 + strictlyEnforceHighlightRange: true } diff --git a/examples/declarative/follow/follow.qml b/examples/declarative/follow/follow.qml index 37dc2e8..1f585e2 100644 --- a/examples/declarative/follow/follow.qml +++ b/examples/declarative/follow/follow.qml @@ -26,7 +26,7 @@ Rectangle { color: "#ff0000" x: Rect.width; width: Rect.width; height: 20 y: 200 - y: Follow { source: Rect.y; velocity: 200 } + y: SpringFollow { source: Rect.y; velocity: 200 } } Text { x: Rect.width; y: 220; text: "Velocity" } @@ -35,13 +35,13 @@ Rectangle { color: "#ff0000" x: Rect.width * 2; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2 } + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2 } } Rectangle { color: "#880000" x: Rect.width * 2.5; width: Rect.width/2; height: 20 y: 200 - y: Follow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object + y: SpringFollow { source: Rect.y; spring: 1.0; damping: 0.2; mass: 3.0 } // "heavier" object } Text { x: Rect.width * 2; y: 220; text: "Spring" } @@ -54,8 +54,8 @@ Rectangle { width: 20; height: 20 radius: 10 color: "#0000ff" - x: Follow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } - y: Follow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + x: SpringFollow { id: "F1"; source: Mouse.mouseX-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } + y: SpringFollow { id: "F2"; source: Mouse.mouseY-10; spring: 1.0; damping: 0.05; epsilon: 0.25 } states: [ State { name: "following" diff --git a/examples/declarative/follow/pong.qml b/examples/declarative/follow/pong.qml index 0314bb8..b51c0d0 100644 --- a/examples/declarative/follow/pong.qml +++ b/examples/declarative/follow/pong.qml @@ -25,7 +25,7 @@ Rectangle { } // Make y follow the target y coordinate, with a velocity of 200 - y: Follow { source: Ball.targetY; velocity: 200 } + y: SpringFollow { source: Ball.targetY; velocity: 200 } // Detect the ball hitting the top or bottom of the view and bounce it onYChanged: { @@ -42,7 +42,7 @@ Rectangle { id: LeftBat color: "#00ee00" x: 2; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'left' } @@ -51,7 +51,7 @@ Rectangle { id: RightBat color: "#00ee00" x: Page.width-22; width: 20; height: 90 - y: Follow { + y: SpringFollow { source: Ball.y-45; velocity: 300 enabled: Ball.direction == 'right' } diff --git a/examples/declarative/listview/content/ClickAutoRepeating.qml b/examples/declarative/listview/content/ClickAutoRepeating.qml new file mode 100644 index 0000000..19dd6f6 --- /dev/null +++ b/examples/declarative/listview/content/ClickAutoRepeating.qml @@ -0,0 +1,29 @@ +import Qt 4.6 + +Item { + id: Page + property int repeatdelay: 300 + property int repeatperiod: 75 + property bool pressed: false + signal pressed + signal released + signal clicked + pressed: SequentialAnimation { + id: AutoRepeat + PropertyAction { target: Page; property: "pressed"; value: true } + ScriptAction { script: Page.onPressed } + ScriptAction { script: Page.onClicked } + PauseAnimation { duration: repeatdelay } + SequentialAnimation { + repeat: true + ScriptAction { script: Page.onClicked } + PauseAnimation { duration: repeatperiod } + } + } + MouseRegion { + id: MR + anchors.fill: parent + onPressed: AutoRepeat.start() + onReleased: { AutoRepeat.stop(); parent.pressed = false; Page.released } + } +} diff --git a/examples/declarative/listview/content/pics/add.png b/examples/declarative/listview/content/pics/add.png Binary files differnew file mode 100644 index 0000000..f29d84b --- /dev/null +++ b/examples/declarative/listview/content/pics/add.png diff --git a/examples/declarative/listview/content/pics/del.png b/examples/declarative/listview/content/pics/del.png Binary files differnew file mode 100644 index 0000000..1d753a3 --- /dev/null +++ b/examples/declarative/listview/content/pics/del.png diff --git a/examples/declarative/listview/content/pics/trash.png b/examples/declarative/listview/content/pics/trash.png Binary files differnew file mode 100644 index 0000000..2042595 --- /dev/null +++ b/examples/declarative/listview/content/pics/trash.png diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml new file mode 100644 index 0000000..52c3c0b --- /dev/null +++ b/examples/declarative/listview/dynamic.qml @@ -0,0 +1,142 @@ +import Qt 4.6 +import "content" + +Item { + width: 320 + height: 500 + + ListModel { + id: FruitModel + ListElement { + name: "Apple" + cost: 2.45 + attributes: [ + ListElement { description: "Core" }, + ListElement { description: "Deciduous" } + ] + } + ListElement { + name: "Banana" + cost: 1.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Seedless" } + ] + } + ListElement { + name: "Cumquat" + cost: 3.25 + types: [ "Small", "Smaller" ] + attributes: [ + ListElement { description: "Citrus" } + ] + } + ListElement { + name: "Durian" + cost: 9.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Smelly" } + ] + } + ListElement { + name: "Elderberry" + cost: 0.05 + attributes: [ + ListElement { description: "Berry" } + ] + } + ListElement { + name: "Fig" + cost: 0.25 + attributes: [ + ListElement { description: "Flower" } + ] + } + } + + Component { + id: FruitDelegate + Item { + width: parent.width; height: 55 + Text { id: Label; font.pixelSize: 24; text: name; elide: "ElideRight"; anchors.right: Cost.left; anchors.left:parent.left } + Text { id: Cost; font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } + Row { + anchors.top: Label.bottom + spacing: 5 + Repeater { + model: attributes + Component { + Text { text: description } + } + } + } + Row { + id: ItemButtons + anchors.right: parent.right + width: childrenRect.width + Image { source: "content/pics/add.png" + ClickAutoRepeating { id: ClickUp; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Number(cost)+0.25) } + scale: ClickUp.pressed ? 0.9 : 1 + } + Image { source: "content/pics/del.png" + ClickAutoRepeating { id: ClickDown; anchors.fill: parent; onClicked: FruitModel.set(index,"cost",Math.max(0,Number(cost)-0.25)) } + scale: ClickDown.pressed ? 0.9 : 1 + } + Image { source: "content/pics/trash.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.remove(index) } + } + Column { + width: childrenRect.width + Image { source: "content/pics/moreUp.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.move(index,index-1,1) } + } + Image { source: "content/pics/moreDown.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.move(index,index+1,1) } + } + } + } + } + } + + ListView { + model: FruitModel + delegate: FruitDelegate + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right + anchors.bottom: Buttons.top + } + + Row { + width: childrenRect.width + height: childrenRect.height + anchors.bottom: parent.bottom + id: Buttons + Image { source: "content/pics/add.png" + MouseRegion { anchors.fill: parent; + onClicked: { + FruitModel.append({ + "name":"Pizza Margarita", + "cost":5.95, + "attributes":[{"description": "Cheese"},{"description": "Tomato"}] + }) + } + } + } + Image { source: "content/pics/add.png" + MouseRegion { anchors.fill: parent; + onClicked: { + FruitModel.insert(0,{ + "name":"Pizza Supreme", + "cost":9.95, + "attributes":[{"description": "Cheese"},{"description": "Tomato"},{"description": "The Works"}] + }) + } + } + } + Image { source: "content/pics/trash.png" + MouseRegion { anchors.fill: parent; onClicked: FruitModel.clear() } + } + } +} diff --git a/examples/declarative/listview/highlight.qml b/examples/declarative/listview/highlight.qml index 2bf3a9f..cb92ad9 100644 --- a/examples/declarative/listview/highlight.qml +++ b/examples/declarative/listview/highlight.qml @@ -44,7 +44,7 @@ Rectangle { id: PetHighlight Rectangle { width: 200; height: 50; color: "#FFFF88" - y: Follow { source: List1.current.y; spring: 3; damping: 0.1 } + y: SpringFollow { source: List1.currentItem.y; spring: 3; damping: 0.1 } } } ListView { diff --git a/examples/declarative/listview/itemlist.qml b/examples/declarative/listview/itemlist.qml index 061fab3..01781ec 100644 --- a/examples/declarative/listview/itemlist.qml +++ b/examples/declarative/listview/itemlist.qml @@ -29,7 +29,9 @@ Rectangle { anchors.fill: parent anchors.bottomMargin: 30 model: ItemModel - currentItemPositioning: "SnapAuto" + preferredHighlightBegin: 0 + preferredHighlightEnd: 1 + strictlyEnforceHighlightRange: true orientation: "Horizontal" } diff --git a/examples/declarative/listview/listview.qml b/examples/declarative/listview/listview.qml index 1cca5ad..ac1cef1 100644 --- a/examples/declarative/listview/listview.qml +++ b/examples/declarative/listview/listview.qml @@ -29,21 +29,24 @@ Rectangle { Rectangle { color: "#FFFF88" } } - // Show the model in three lists, with different currentItemPositioning. - // currentItemPositioning determines how the list behaves when the - // current item changes. Note that the second and third ListView + // Show the model in three lists, with different highlight ranges. + // preferredHighlightBegin and preferredHighlightEnd set the + // range in which to attempt to maintain the highlight. + // Note that the second and third ListView // set their currentIndex to be the same as the first, and that // the first ListView is given keyboard focus. - // The default mode, Free, allows the currentItem to move freely + // The default mode allows the currentItem to move freely // within the visible area. If it would move outside the visible // area, the view is scrolled to keep it visible. - // Snap currentItemPositioning attempts to keep the current item - // aligned with the snapPosition by scrolling the view, however the - // items will not scroll beyond the beginning or end of the view. - // SnapAuto currentItemPositioning always keeps the current item on - // the snapPosition by scrolling the view. It also automatically - // sets the current item as is scrolled with the mouse. Note - // that the first ListView sets its currentIndex to be equal to + // The second list sets a highlight range which attempts to keep the + // current item within the the bounds of the range, however + // items will not scroll beyond the beginning or end of the view, + // forcing the highlight to move outside the range at the ends. + // The third list sets strictlyEnforceHighlightRange to true + // and sets a range smaller than the height of an item. This + // forces the current item to change when the view is flicked, + // since the highlight is unable to move. + // Note that the first ListView sets its currentIndex to be equal to // the third ListView's currentIndex. By flicking List3 with // the mouse, the current index of List1 will be changed. ListView { @@ -57,23 +60,17 @@ Rectangle { id: List2 x: 200; width: 200; height: parent.height model: MyPetsModel; delegate: PetDelegate; highlight: PetHighlight - currentItemPositioning: "Snap"; snapPosition: 125 + preferredHighlightBegin: 80 + preferredHighlightEnd: 220 currentIndex: List1.currentIndex } ListView { id: List3 x: 400; width: 200; height: parent.height - model: MyPetsModel; delegate: PetDelegate - currentItemPositioning: "SnapAuto"; snapPosition: 125 + model: MyPetsModel; delegate: PetDelegate; highlight: PetHighlight currentIndex: List1.currentIndex - - // Position a static highlight rather than a normal highlight so that - // when the view is flicked, the highlight does not move. - // By positioning the highlight at the same position as the snapPosition - // the item under the highlight will always be the current item. - Rectangle { - y: 125; width: 200; height: 50 - color: "#FFFF88"; z: -1 - } + preferredHighlightBegin: 125 + preferredHighlightEnd: 126 + strictlyEnforceHighlightRange: true } } diff --git a/examples/declarative/loader/Browser.qml b/examples/declarative/loader/Browser.qml index 196cdc5..6711de4 100644 --- a/examples/declarative/loader/Browser.qml +++ b/examples/declarative/loader/Browser.qml @@ -82,7 +82,7 @@ Rectangle { focus: true Keys.onPressed: { if (event.key == Qt.Key_Return || event.key == Qt.Key_Select) { - View.current.launch(); + View.currentItem.launch(); event.accepted = true; } } diff --git a/examples/declarative/snow/snow.qml b/examples/declarative/snow/snow.qml index b6781c3..2241c3f 100644 --- a/examples/declarative/snow/snow.qml +++ b/examples/declarative/snow/snow.qml @@ -30,15 +30,15 @@ Rectangle { property bool slowDeform: true property real deform: 0 - deform: Follow { + deform: SpringFollow { id: "DeformFollow"; source: MyLayout.targetDeform; velocity: MyLayout.slowDeform?0.1:2 onSyncChanged: if(inSync) { MyLayout.slowDeform = true; MyLayout.targetDeform = 0; } } ImageBatch { offset: 0; ref: ImagePanel } - x: Follow { source: MyLayout.targetX; velocity: 1000 } - y: Follow { source: -(selectedY + imageHeight / 2); velocity: 500 } + x: SpringFollow { source: MyLayout.targetX; velocity: 1000 } + y: SpringFollow { source: -(selectedY + imageHeight / 2); velocity: 500 } } transform: Rotation { diff --git a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml index ec115fe..7bcdf50 100644 --- a/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml +++ b/examples/declarative/tutorials/contacts/2_Reuse/1b/BlueRect.qml @@ -16,18 +16,18 @@ Rectangle { } } ] - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.right: parent.right anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.top: parent.top } - ComponentInstance { - component: redRectangle + Loader { + sourceComponent: redRectangle anchors.left: parent.left anchors.bottom: parent.bottom } diff --git a/examples/declarative/velocity/Day.qml b/examples/declarative/velocity/Day.qml index 06d0bd4..4001a3e 100644 --- a/examples/declarative/velocity/Day.qml +++ b/examples/declarative/velocity/Day.qml @@ -31,7 +31,7 @@ Rectangle { x: Math.random() * 200 + 100 y: Math.random() * 300 + 50 id: StickyPage - rotation: Follow { + rotation: SpringFollow { source: -Flick.horizontalVelocity / 100 spring: 2.0 damping: 0.1 diff --git a/examples/declarative/webview/newwindows.qml b/examples/declarative/webview/newwindows.qml index 9ff902e2..57cbf4e 100644 --- a/examples/declarative/webview/newwindows.qml +++ b/examples/declarative/webview/newwindows.qml @@ -24,5 +24,5 @@ Row { } ] width: 500 - ComponentInstance { component: WebViewPage } + Loader { sourceComponent: WebViewPage } } diff --git a/examples/declarative/xmldata/yahoonews.qml b/examples/declarative/xmldata/yahoonews.qml index 6395284..7ebc2b2 100644 --- a/examples/declarative/xmldata/yahoonews.qml +++ b/examples/declarative/xmldata/yahoonews.qml @@ -101,6 +101,5 @@ Rectangle { clip: true model: feedModel delegate: feedDelegate - currentItemPositioning: "Snap" } } diff --git a/examples/opengl/opengl.pro b/examples/opengl/opengl.pro index 567eb7b..b86e0ba 100644 --- a/examples/opengl/opengl.pro +++ b/examples/opengl/opengl.pro @@ -5,6 +5,9 @@ contains(QT_CONFIG, opengles1)|contains(QT_CONFIG, opengles1cl)|contains(QT_CONF SUBDIRS = hellogl_es2 } else { SUBDIRS = hellogl_es + !contains(QT_CONFIG, opengles1cl) { + SUBDIRS += textures + } } } else { SUBDIRS = 2dpainting \ diff --git a/examples/opengl/textures/glwidget.cpp b/examples/opengl/textures/glwidget.cpp index cfb99b0..9c6d5ea 100644 --- a/examples/opengl/textures/glwidget.cpp +++ b/examples/opengl/textures/glwidget.cpp @@ -42,12 +42,17 @@ #include <QtGui> #include <QtOpenGL> -#include <math.h> - #include "glwidget.h" -GLuint GLWidget::sharedObject = 0; -int GLWidget::refCount = 0; +class CubeObject +{ +public: + GLuint textures[6]; + QVector<QVector3D> vertices; + QVector<QVector2D> texCoords; + + void draw(); +}; GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget) : QGLWidget(parent, shareWidget) @@ -56,14 +61,12 @@ GLWidget::GLWidget(QWidget *parent, QGLWidget *shareWidget) xRot = 0; yRot = 0; zRot = 0; + cube = 0; } GLWidget::~GLWidget() { - if (--refCount == 0) { - makeCurrent(); - glDeleteLists(sharedObject, 1); - } + delete cube; } QSize GLWidget::minimumSizeHint() const @@ -92,9 +95,7 @@ void GLWidget::setClearColor(const QColor &color) void GLWidget::initializeGL() { - if (!sharedObject) - sharedObject = makeObject(); - ++refCount; + makeObject(); glEnable(GL_DEPTH_TEST); glEnable(GL_CULL_FACE); @@ -106,11 +107,11 @@ void GLWidget::paintGL() qglClearColor(clearColor); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); - glTranslated(0.0, 0.0, -10.0); - glRotated(xRot / 16.0, 1.0, 0.0, 0.0); - glRotated(yRot / 16.0, 0.0, 1.0, 0.0); - glRotated(zRot / 16.0, 0.0, 0.0, 1.0); - glCallList(sharedObject); + glTranslatef(0.0f, 0.0f, -10.0f); + glRotatef(xRot / 16.0f, 1.0f, 0.0f, 0.0f); + glRotatef(yRot / 16.0f, 0.0f, 1.0f, 0.0f); + glRotatef(zRot / 16.0f, 0.0f, 0.0f, 1.0f); + cube->draw(); } void GLWidget::resizeGL(int width, int height) @@ -120,7 +121,11 @@ void GLWidget::resizeGL(int width, int height) glMatrixMode(GL_PROJECTION); glLoadIdentity(); +#ifndef QT_OPENGL_ES glOrtho(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); +#else + glOrthof(-0.5, +0.5, +0.5, -0.5, 4.0, 15.0); +#endif glMatrixMode(GL_MODELVIEW); } @@ -147,7 +152,7 @@ void GLWidget::mouseReleaseEvent(QMouseEvent * /* event */) emit clicked(); } -GLuint GLWidget::makeObject() +void GLWidget::makeObject() { static const int coords[6][4][3] = { { { +1, -1, -1 }, { -1, -1, -1 }, { -1, +1, -1 }, { +1, +1, -1 } }, @@ -158,25 +163,32 @@ GLuint GLWidget::makeObject() { { -1, -1, +1 }, { +1, -1, +1 }, { +1, +1, +1 }, { -1, +1, +1 } } }; + cube = new CubeObject(); - GLuint textures[6]; - for (int j=0; j < 6; ++j) - textures[j] = bindTexture(QPixmap(QString(":/images/side%1.png").arg(j + 1)), - GL_TEXTURE_2D); + for (int j=0; j < 6; ++j) { + cube->textures[j] = bindTexture + (QPixmap(QString(":/images/side%1.png").arg(j + 1)), GL_TEXTURE_2D); + } - GLuint list = glGenLists(1); - glNewList(list, GL_COMPILE); for (int i = 0; i < 6; ++i) { - glBindTexture(GL_TEXTURE_2D, textures[i]); - glBegin(GL_QUADS); for (int j = 0; j < 4; ++j) { - glTexCoord2d(j == 0 || j == 3, j == 0 || j == 1); - glVertex3d(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], - 0.2 * coords[i][j][2]); + cube->texCoords.append + (QVector2D(j == 0 || j == 3, j == 0 || j == 1)); + cube->vertices.append + (QVector3D(0.2 * coords[i][j][0], 0.2 * coords[i][j][1], + 0.2 * coords[i][j][2])); } - glEnd(); } +} - glEndList(); - return list; +void CubeObject::draw() +{ + glVertexPointer(3, GL_FLOAT, 0, vertices.constData()); + glTexCoordPointer(2, GL_FLOAT, 0, texCoords.constData()); + glEnableClientState(GL_VERTEX_ARRAY); + glEnableClientState(GL_TEXTURE_COORD_ARRAY); + for (int i = 0; i < 6; ++i) { + glBindTexture(GL_TEXTURE_2D, textures[i]); + glDrawArrays(GL_TRIANGLE_FAN, i * 4, 4); + } } diff --git a/examples/opengl/textures/glwidget.h b/examples/opengl/textures/glwidget.h index 68be8bc..f793d6d 100644 --- a/examples/opengl/textures/glwidget.h +++ b/examples/opengl/textures/glwidget.h @@ -44,6 +44,8 @@ #include <QGLWidget> +class CubeObject; + class GLWidget : public QGLWidget { Q_OBJECT @@ -69,16 +71,14 @@ protected: void mouseReleaseEvent(QMouseEvent *event); private: - GLuint makeObject(); + void makeObject(); QColor clearColor; QPoint lastPos; int xRot; int yRot; int zRot; - - static GLuint sharedObject; - static int refCount; + CubeObject *cube; }; #endif diff --git a/examples/opengl/textures/window.cpp b/examples/opengl/textures/window.cpp index ea64512..9bd7931 100644 --- a/examples/opengl/textures/window.cpp +++ b/examples/opengl/textures/window.cpp @@ -48,8 +48,6 @@ Window::Window() { QGridLayout *mainLayout = new QGridLayout; - glWidgets[0][0] = 0; - for (int i = 0; i < NumRows; ++i) { for (int j = 0; j < NumColumns; ++j) { QColor clearColor; @@ -57,7 +55,7 @@ Window::Window() / (NumRows * NumColumns - 1), 255, 63); - glWidgets[i][j] = new GLWidget(0, glWidgets[0][0]); + glWidgets[i][j] = new GLWidget(0, 0); glWidgets[i][j]->setClearColor(clearColor); glWidgets[i][j]->rotateBy(+42 * 16, +42 * 16, -21 * 16); mainLayout->addWidget(glWidgets[i][j], i, j); |