2011-04-27 10:05:43 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2017-09-28 13:54:49 +00:00
|
|
|
** Copyright (C) 2017 The Qt Company Ltd.
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** This file is part of the examples of the Qt Toolkit.
|
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:BSD$
|
2017-09-28 13:54:49 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
**
|
|
|
|
** BSD License Usage
|
|
|
|
** Alternatively, you may use this file under the terms of the BSD license
|
|
|
|
** as follows:
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** "Redistribution and use in source and binary forms, with or without
|
|
|
|
** modification, are permitted provided that the following conditions are
|
|
|
|
** met:
|
|
|
|
** * Redistributions of source code must retain the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer.
|
|
|
|
** * Redistributions in binary form must reproduce the above copyright
|
|
|
|
** notice, this list of conditions and the following disclaimer in
|
|
|
|
** the documentation and/or other materials provided with the
|
|
|
|
** distribution.
|
2015-02-13 11:35:35 +00:00
|
|
|
** * Neither the name of The Qt Company Ltd nor the names of its
|
|
|
|
** contributors may be used to endorse or promote products derived
|
|
|
|
** from this software without specific prior written permission.
|
2012-09-20 05:21:40 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
**
|
|
|
|
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
|
2012-01-24 03:37:23 +00:00
|
|
|
**
|
2011-04-27 10:05:43 +00:00
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2011-08-25 23:23:28 +00:00
|
|
|
import QtQuick 2.0
|
2011-04-27 10:05:43 +00:00
|
|
|
import "content"
|
|
|
|
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [0]
|
2011-04-27 10:05:43 +00:00
|
|
|
Rectangle {
|
|
|
|
id: root
|
|
|
|
property int current: 0
|
2012-11-22 16:54:33 +00:00
|
|
|
property bool increasing: true
|
2012-03-08 00:50:11 +00:00
|
|
|
// Example index automation for convenience, disabled on click or tap
|
2012-11-22 16:54:33 +00:00
|
|
|
SequentialAnimation {
|
2012-03-08 00:50:11 +00:00
|
|
|
id: anim
|
|
|
|
loops: -1
|
2012-11-22 16:54:33 +00:00
|
|
|
running: true
|
|
|
|
ScriptAction {
|
2019-09-17 16:10:59 +00:00
|
|
|
script: if (root.increasing) {
|
|
|
|
root.current++;
|
|
|
|
if (root.current >= aModel.count -1) {
|
|
|
|
root.current = aModel.count - 1;
|
|
|
|
root.increasing = !root.increasing;
|
2012-11-22 16:54:33 +00:00
|
|
|
}
|
|
|
|
} else {
|
2019-09-17 16:10:59 +00:00
|
|
|
root.current--;
|
|
|
|
if (root.current <= 0) {
|
|
|
|
root.current = 0;
|
|
|
|
root.increasing = !root.increasing;
|
2012-11-22 16:54:33 +00:00
|
|
|
}
|
|
|
|
}
|
2012-03-08 00:50:11 +00:00
|
|
|
}
|
2012-11-22 16:54:33 +00:00
|
|
|
|
|
|
|
PauseAnimation { duration: 500 }
|
2012-03-08 00:50:11 +00:00
|
|
|
}
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [0]
|
2012-03-08 00:50:11 +00:00
|
|
|
MouseArea{
|
|
|
|
id: ma
|
|
|
|
z: 1
|
|
|
|
anchors.fill: parent
|
2012-11-22 16:54:33 +00:00
|
|
|
onClicked: { z = 1 - z; if (anim.running) anim.stop(); else anim.restart();}
|
2012-03-08 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
width: 320; height: 480
|
2011-04-27 10:05:43 +00:00
|
|
|
|
2014-01-15 21:01:15 +00:00
|
|
|
// This example shows the same model in three different ListView items,
|
|
|
|
// with different highlight ranges. The highlight ranges are set by the
|
2011-04-27 10:05:43 +00:00
|
|
|
// preferredHighlightBegin and preferredHighlightEnd properties in ListView.
|
|
|
|
//
|
|
|
|
// The first ListView does not set a highlight range, so its currentItem
|
|
|
|
// can move freely within the visible area. If it moves outside the
|
|
|
|
// visible area, the view is automatically scrolled to keep the current
|
|
|
|
// item visible.
|
|
|
|
//
|
|
|
|
// The second ListView sets a highlight range which attempts to keep the
|
2014-01-07 15:35:37 +00:00
|
|
|
// current item within the bounds of the range. However,
|
2011-04-27 10:05:43 +00:00
|
|
|
// 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 ListView sets the highlightRangeMode to StrictlyEnforceRange
|
|
|
|
// 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.
|
|
|
|
//
|
|
|
|
// All ListViews bind their currentIndex to the root.current property.
|
|
|
|
// The first ListView sets root.current whenever its currentIndex changes
|
|
|
|
// due to keyboard interaction.
|
|
|
|
// Flicking the third ListView with the mouse also changes root.current.
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [1]
|
2011-04-27 10:05:43 +00:00
|
|
|
ListView {
|
|
|
|
id: list1
|
2012-11-22 16:54:33 +00:00
|
|
|
height: 50; width: parent.width
|
2012-03-08 00:50:11 +00:00
|
|
|
model: PetsModel {id: aModel}
|
2011-04-27 10:05:43 +00:00
|
|
|
delegate: petDelegate
|
2012-03-08 00:50:11 +00:00
|
|
|
orientation: ListView.Horizontal
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
highlight: Rectangle { color: "lightsteelblue" }
|
|
|
|
currentIndex: root.current
|
|
|
|
onCurrentIndexChanged: root.current = currentIndex
|
|
|
|
focus: true
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: list2
|
2012-11-22 16:54:33 +00:00
|
|
|
y: 160
|
|
|
|
height: 50; width: parent.width
|
2011-04-27 10:05:43 +00:00
|
|
|
model: PetsModel {}
|
|
|
|
delegate: petDelegate
|
2012-03-08 00:50:11 +00:00
|
|
|
orientation: ListView.Horizontal
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
highlight: Rectangle { color: "yellow" }
|
|
|
|
currentIndex: root.current
|
|
|
|
preferredHighlightBegin: 80; preferredHighlightEnd: 220
|
|
|
|
highlightRangeMode: ListView.ApplyRange
|
|
|
|
}
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: list3
|
2012-11-22 16:54:33 +00:00
|
|
|
y: 320
|
|
|
|
height: 50; width: parent.width
|
2011-04-27 10:05:43 +00:00
|
|
|
model: PetsModel {}
|
|
|
|
delegate: petDelegate
|
2012-03-08 00:50:11 +00:00
|
|
|
orientation: ListView.Horizontal
|
2011-04-27 10:05:43 +00:00
|
|
|
|
|
|
|
highlight: Rectangle { color: "yellow" }
|
|
|
|
currentIndex: root.current
|
|
|
|
onCurrentIndexChanged: root.current = currentIndex
|
|
|
|
preferredHighlightBegin: 125; preferredHighlightEnd: 125
|
|
|
|
highlightRangeMode: ListView.StrictlyEnforceRange
|
|
|
|
}
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [1]
|
2011-04-27 10:05:43 +00:00
|
|
|
// The delegate for each list
|
|
|
|
Component {
|
|
|
|
id: petDelegate
|
2012-03-08 00:50:11 +00:00
|
|
|
Item {
|
2021-04-30 08:38:37 +00:00
|
|
|
id: petDelegateItem
|
2012-03-08 00:50:11 +00:00
|
|
|
width: 160
|
|
|
|
height: column.height
|
2019-09-17 16:10:59 +00:00
|
|
|
|
|
|
|
required property int index
|
|
|
|
required property string name
|
|
|
|
required property string type
|
|
|
|
required property int age
|
|
|
|
|
2012-03-08 00:50:11 +00:00
|
|
|
Column {
|
|
|
|
id: column
|
2021-04-30 08:38:37 +00:00
|
|
|
Text { text: 'Name: ' + petDelegateItem.name }
|
|
|
|
Text { text: 'Type: ' + petDelegateItem.type }
|
|
|
|
Text { text: 'Age: ' + petDelegateItem.age }
|
2012-03-08 00:50:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
2019-09-17 16:10:59 +00:00
|
|
|
onClicked: root.current = parent.index
|
2012-03-08 00:50:11 +00:00
|
|
|
}
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
|
|
|
}
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [2]
|
2011-04-27 10:05:43 +00:00
|
|
|
}
|
2012-04-27 06:35:12 +00:00
|
|
|
//! [2]
|