1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the Qt Components project.
9 ** $QT_BEGIN_LICENSE:BSD$
10 ** You may use this file under the terms of the BSD license as follows:
12 ** "Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
15 ** * Redistributions of source code must retain the above copyright
16 ** notice, this list of conditions and the following disclaimer.
17 ** * Redistributions in binary form must reproduce the above copyright
18 ** notice, this list of conditions and the following disclaimer in
19 ** the documentation and/or other materials provided with the
21 ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
22 ** the names of its contributors may be used to endorse or promote
23 ** products derived from this software without specific prior written
26 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
42 var __autoColumnWidth = 0;
43 var __suppressLayoutUpdates = false;
45 function initialize() {
46 // check the width requested by fixed width columns
47 var requestedWidth = 0;
48 var requestedCount = 0;
49 var invisibleCount = 0;
50 for (var i = 0; i < columns.length; i++) {
51 if (columns[i].visible) {
52 if (columns[i].width > 0 && !columns[i].privateIsAutoWidth) {
53 requestedWidth += columns[i].width;
61 // allocate the rest to auto width columns
62 if ((columns.length - requestedCount - invisibleCount) > 0) {
63 __autoColumnWidth = Math.floor((parent.width - requestedWidth) / (columns.length - requestedCount - invisibleCount));
66 for (var i = 0; i < columns.length; i++) {
67 var comp = Qt.createComponent("TumblerTemplate.qml");
68 var newObj = comp.createObject(tumblerRow);
69 if (!columns[i].width || columns[i].privateIsAutoWidth) {
70 columns[i].width = __autoColumnWidth;
71 columns[i].privateIsAutoWidth = true;
73 if (columns[i].label) {
74 // enable label for the tumbler
75 internal.hasLabel = true;
77 newObj.height = root.height;
79 newObj.tumblerColumn = columns[i];
80 newObj.widthChanged.connect(layout);
81 newObj.visibleChanged.connect(layout);
82 __columns.push(newObj);
84 privateTemplates = __columns;
88 var count = __columns.length;
89 for (var i = 0; i < count; i++) {
90 var tmp = __columns.pop();
95 function forceUpdate() {
96 for (var i = 0; i < columns.length; i++) {
97 columns[i].selectedIndex = __columns[i].view.currentIndex;
102 if (__suppressLayoutUpdates) {
103 // guard against onWidthChanged triggering again during this process
106 var requestedWidth = 0;
107 var requestedCount = 0;
108 var invisibleCount = 0;
109 for (var i = 0; i < columns.length; i++) {
110 if (columns[i].visible) {
111 var w = columns[i].width;
112 var a = columns[i].privateIsAutoWidth;
113 if (!a || (a && w != __autoColumnWidth)) {
114 requestedWidth += columns[i].width;
116 columns[i].privateIsAutoWidth = false;
118 columns[i].privateIsAutoWidth = true;
125 if ((columns.length - requestedCount - invisibleCount) > 0) {
126 __autoColumnWidth = Math.floor((parent.width - requestedWidth) / (columns.length - requestedCount - invisibleCount));
129 // guard against onWidthChanged triggering again during this process
130 __suppressLayoutUpdates = true;
131 for (var i = 0; i < columns.length; i++) {
132 if (columns[i].privateIsAutoWidth) {
133 columns[i].width = __autoColumnWidth;
136 __suppressLayoutUpdates = false;