on xenial help sign in
override some Qt Components definitions so we can have sane default values for flick speeds

Approved by: Albert Astals Cid

commitd0f3cb61fb2a5a823c0ef17988529ee8e6a2c9c7 authorAndrea Cimitan <andrea.cimitan@gmail.com> dateThu 22 Sep 2016, 07:31 (10 years ago) parentb5a58797f985b8
33 files changed+190−13
qml/Components/Carousel.qml+1−2 qml/Components/Flickable.qml+24 qml/Components/FloatingFlickable.qml+1 qml/Components/GridView.qml+24 qml/Components/ListView.qml+24 qml/Components/ResponsiveGridView.qml+1 qml/Components/ZoomableImage.qml+1−1 qml/Components/flickableUtils.js+28 qml/Dash/DashContent.qml−2 qml/Dash/DashNavigation.qml+1 qml/Dash/FiltersPopover.qml+1 qml/Dash/PageHeaderExtraPanel.qml+1 qml/Dash/ScopeListView.qml+4−2 qml/Dash/ScopesList.qml+2 qml/Dash/ScopesListCategory.qml+1 qml/Greeter/LoginList.qml−1 qml/Launcher/LauncherPanel.qml+1−1 qml/Panel/IndicatorPage.qml+1 qml/Panel/Indicators/client/IndicatorsList.qml+1 qml/Panel/Indicators/client/IndicatorsTree.qml+1 qml/Wizard/Pages/10-welcome.qml+1 qml/Wizard/Pages/20-keyboard.qml+1 qml/Wizard/Pages/30-wifi.qml+1 qml/Wizard/Pages/50-timezone.qml+1 qml/Wizard/Pages/70-passwd-type.qml+1 qml/Wizard/Pages/passcode-confirm.qml+2−2 qml/Wizard/Pages/passcode-desktop.qml+1 qml/Wizard/Pages/passcode-set.qml+2−2 qml/Wizard/Pages/password-set.qml+1 qml/Wizard/WizardItemSelector.qml+1 tests/imports/check_imports.py+58 tests/qmltests/Dash/Previews/tst_PreviewRatingDisplayCreationRanges.qml+1 tests/qmltests/tst_OrientedShell.qml+1
qml/Components/Carousel.qml+1−2
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import "carousel.js" as CarouselJS
20+import "."
2021
2122/*! The Carousel component presents the items of a model in a carousel view. It's similar to a
2223 cover flow. But it stops at it's boundaries (therefore no PathView is used).
@@ -141,8 +142,6 @@ Item {
141142
142143 boundsBehavior: Flickable.DragOverBounds
143144 cacheBuffer: carousel.cacheBuffer
144− flickDeceleration: Math.max(1500 * Math.pow(realWidth / referenceWidth, 1.5), 1500) // 1500 is platform default
145− maximumFlickVelocity: Math.max(2500 * Math.pow(realWidth / referenceWidth, 1.5), 2500) // 2500 is platform default
146145 orientation: ListView.Horizontal
147146
148147 function getXFromContinuousIndex(index) {
qml/Components/Flickable.qmlnew file+24
@@ -0,0 +1,24 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4 as QtQuick
18+import Ubuntu.Components 1.3
19+import "flickableUtils.js" as FlickableUtilsJS
20+
21+QtQuick.Flickable {
22+ flickDeceleration: FlickableUtilsJS.getFlickDeceleration(units.gridUnit)
23+ maximumFlickVelocity: FlickableUtilsJS.getMaximumFlickVelocity(units.gridUnit)
24+}
qml/Components/FloatingFlickable.qml+1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Gestures 0.1
20+import "."
2021
2122/*
2223 A Flickable that can be put in front of the item to be flicked and
qml/Components/GridView.qmlnew file+24
@@ -0,0 +1,24 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4 as QtQuick
18+import Ubuntu.Components 1.3
19+import "flickableUtils.js" as FlickableUtilsJS
20+
21+QtQuick.GridView {
22+ flickDeceleration: FlickableUtilsJS.getFlickDeceleration(units.gridUnit)
23+ maximumFlickVelocity: FlickableUtilsJS.getMaximumFlickVelocity(units.gridUnit)
24+}
qml/Components/ListView.qmlnew file+24
@@ -0,0 +1,24 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+import QtQuick 2.4 as QtQuick
18+import Ubuntu.Components 1.3
19+import "flickableUtils.js" as FlickableUtilsJS
20+
21+QtQuick.ListView {
22+ flickDeceleration: FlickableUtilsJS.getFlickDeceleration(units.gridUnit)
23+ maximumFlickVelocity: FlickableUtilsJS.getMaximumFlickVelocity(units.gridUnit)
24+}
qml/Components/ResponsiveGridView.qml+1
@@ -16,6 +16,7 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19+import "."
1920
2021/*
2122 Essentially a GridView
qml/Components/ZoomableImage.qml+1−1
@@ -16,7 +16,7 @@
1616
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
19−import "../Components"
19+import "."
2020
2121/*! \brief Zoomable for image.
2222
qml/Components/flickableUtils.jsnew file+28
@@ -0,0 +1,28 @@
1+/*
2+ * Copyright (C) 2016 Canonical, Ltd.
3+ *
4+ * This program is free software; you can redistribute it and/or modify
5+ * it under the terms of the GNU General Public License as published by
6+ * the Free Software Foundation; version 3.
7+ *
8+ * This program is distributed in the hope that it will be useful,
9+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
10+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+ * GNU General Public License for more details.
12+ *
13+ * You should have received a copy of the GNU General Public License
14+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
15+ */
16+
17+.pragma library
18+
19+/* TODO the "8" is is DEFAULT_GRID_UNIT_PX, we use it to normalize the values with the current grid unit size.
20+ Add a way to fetch this default grid unit px value from UITK. */
21+
22+function getFlickDeceleration(gridUnit) {
23+ return 1500 * gridUnit / 8;
24+}
25+
26+function getMaximumFlickVelocity(gridUnit) {
27+ return 2500 * gridUnit / 8;
28+}
qml/Dash/DashContent.qml−2
@@ -112,8 +112,6 @@ Item {
112112 anchors.fill: parent
113113 orientation: ListView.Horizontal
114114 boundsBehavior: Flickable.DragAndOvershootBounds
115− flickDeceleration: units.gu(625)
116− maximumFlickVelocity: width * 5
117115 snapMode: ListView.SnapOneItem
118116 highlightMoveDuration: 250
119117 highlightRangeMode: ListView.StrictlyEnforceRange
qml/Dash/DashNavigation.qml+1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Dash 0.1
20+import "../Components"
2021
2122Item {
2223 id: root
qml/Dash/FiltersPopover.qml+1
@@ -19,6 +19,7 @@ import Ubuntu.Components 1.3
1919import Ubuntu.Components.Popups 1.3
2020import Ubuntu.Components.ListItems 1.3 as ListItems
2121import "Filters" as Filters
22+import "../Components"
2223
2324Popover {
2425 id: root
qml/Dash/PageHeaderExtraPanel.qml+1
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Components.ListItems 1.3 as ListItems
2020import "Filters" as Filters
21+import "../Components"
2122
2223Item {
2324 id: root
qml/Dash/ScopeListView.qml+4−2
@@ -15,11 +15,13 @@
1515 */
1616
1717import QtQuick 2.4
18+import Ubuntu.Components 1.3
1819import Dash 0.1
20+import "../Components/flickableUtils.js" as FlickableUtilsJS
1921
2022ListViewWithPageHeader {
21− maximumFlickVelocity: height * 10
22− flickDeceleration: height * 2
23+ flickDeceleration: FlickableUtilsJS.getFlickDeceleration(units.gridUnit)
24+ maximumFlickVelocity: FlickableUtilsJS.getMaximumFlickVelocity(units.gridUnit)
2325 // 1073741823 is s^30 -1. A quite big number so that you have "infinite" cache, but not so
2426 // big so that if you add if with itself you're outside the 2^31 int range
2527 cacheBuffer: 1073741823
qml/Dash/ScopesList.qml+2
@@ -15,7 +15,9 @@
1515 */
1616
1717import QtQuick 2.4
18+import Ubuntu.Components 1.3
1819import Dash 0.1
20+import "../Components"
1921
2022Item {
2123 id: root
qml/Dash/ScopesListCategory.qml+1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Dash 0.1
20+import "../Components"
2021import "../Components/ListItems" as ListItems
2122
2223Item {
qml/Greeter/LoginList.qml−1
@@ -152,7 +152,6 @@ StyledItem {
152152 preferredHighlightEnd: userList.height / 2 - root.highlightedHeight / 2
153153 highlightRangeMode: ListView.StrictlyEnforceRange
154154 highlightMoveDuration: root.moveDuration
155− flickDeceleration: 10000
156155 interactive: count > 1
157156
158157 readonly property bool movingInternally: moveTimer.running || userList.moving
qml/Launcher/LauncherPanel.qml+1−1
@@ -19,7 +19,7 @@ import Ubuntu.Components 1.3
1919import Unity.Launcher 0.1
2020import Ubuntu.Components.Popups 1.3
2121import "../Components/ListItems"
22−import "../Components/"
22+import "../Components"
2323
2424Rectangle {
2525 id: root
qml/Panel/IndicatorPage.qml+1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3 as Components
1919import Unity.Indicators 0.1 as Indicators
20+import "../Components"
2021import "Indicators"
2122
2223IndicatorBase {
qml/Panel/Indicators/client/IndicatorsList.qml+1
@@ -22,6 +22,7 @@ import Ubuntu.Components 1.3
2222import Ubuntu.Components.ListItems 1.3 as ListItem
2323import Unity.Indicators 0.1 as Indicators
2424import "../.."
25+import "../../../Components"
2526
2627Page {
2728 id: page
qml/Panel/Indicators/client/IndicatorsTree.qml+1
@@ -21,6 +21,7 @@ import QtQuick 2.4
2121import Ubuntu.Components 1.3
2222import Unity.Indicators 0.1 as Indicators
2323import ".."
24+import "../../../Components"
2425
2526IndicatorBase {
2627 id: root
qml/Wizard/Pages/10-welcome.qml+1
@@ -20,6 +20,7 @@ import Ubuntu.Components.ListItems 1.3
2020import Ubuntu.SystemSettings.LanguagePlugin 1.0
2121import Wizard 0.1
2222import ".." as LocalComponents
23+import "../../Components"
2324
2425LocalComponents.Page {
2526 objectName: "languagePage"
qml/Wizard/Pages/20-keyboard.qml+1
@@ -23,6 +23,7 @@ import AccountsService 0.1
2323import Unity.InputInfo 0.1
2424import Unity.Application 0.1
2525import ".." as LocalComponents
26+import "../../Components"
2627
2728LocalComponents.Page {
2829 objectName: "keyboardPage"
qml/Wizard/Pages/30-wifi.qml+1
@@ -22,6 +22,7 @@ import Wizard 0.1
2222import Ubuntu.Connectivity 1.0
2323import Ubuntu.SystemImage 0.1
2424import ".." as LocalComponents
25+import "../../Components"
2526
2627LocalComponents.Page {
2728 id: wifiPage
qml/Wizard/Pages/50-timezone.qml+1
@@ -21,6 +21,7 @@ import Wizard 0.1
2121import Ubuntu.SystemSettings.TimeDate 1.1
2222import Utils 0.1 as Utils
2323import ".." as LocalComponents
24+import "../../Components"
2425
2526LocalComponents.Page {
2627 id: tzPage
qml/Wizard/Pages/70-passwd-type.qml+1
@@ -19,6 +19,7 @@ import Ubuntu.Components 1.3
1919import Ubuntu.Components.ListItems 1.3
2020import Ubuntu.SystemSettings.SecurityPrivacy 1.0
2121import ".." as LocalComponents
22+import "../../Components"
2223
2324/**
2425 * One quirk with this page: we don't actually set the password. We avoid
qml/Wizard/Pages/passcode-confirm.qml+2−2
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.SystemSettings.SecurityPrivacy 1.0
2020import ".." as LocalComponents
21−import "../../Components" as UnityComponents
21+import "../../Components"
2222
2323/**
2424 * See the main passwd-type page for an explanation of why we don't actually
@@ -34,7 +34,7 @@ LocalComponents.Page {
3434 // If we are entering this page, clear any saved password and get focus
3535 onEnabledChanged: if (enabled) lockscreen.clear(false)
3636
37− UnityComponents.Lockscreen {
37+ Lockscreen {
3838 id: lockscreen
3939 anchors {
4040 fill: content
qml/Wizard/Pages/passcode-desktop.qml+1
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import ".." as LocalComponents
21+import "../../Components"
2122
2223/**
2324 * See the main passwd-type page for an explanation of why we don't actually
qml/Wizard/Pages/passcode-set.qml+2−2
@@ -18,7 +18,7 @@ import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.SystemSettings.SecurityPrivacy 1.0
2020import ".." as LocalComponents
21−import "../../Components" as UnityComponents
21+import "../../Components"
2222
2323/**
2424 * See the main passwd-type page for an explanation of why we don't actually
@@ -45,7 +45,7 @@ LocalComponents.Page {
4545 onTriggered: pageStack.load(Qt.resolvedUrl("passcode-confirm.qml"));
4646 }
4747
48− UnityComponents.Lockscreen {
48+ Lockscreen {
4949 id: lockscreen
5050 anchors {
5151 fill: content
qml/Wizard/Pages/password-set.qml+1
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtQuick.Layouts 1.1
1919import Ubuntu.Components 1.3
2020import ".." as LocalComponents
21+import "../../Components"
2122
2223/**
2324 * See the main passwd-type page for an explanation of why we don't actually
qml/Wizard/WizardItemSelector.qml+1
@@ -17,6 +17,7 @@
1717import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import Ubuntu.Components.ListItems 1.3 as ListItem
20+import "../Components"
2021
2122Rectangle {
2223 id: optionToggle
tests/imports/check_imports.py+58
@@ -81,6 +81,53 @@ def scan_for_bad_import(file_path, all_pat, good_pats):
8181 print("%s: bad import version in multiple lines" % file_path)
8282 return bool(errors)
8383
84+# Flickable matches
85+flickable_pat = re.compile(r'.*\s*Flickable\s*{')
86+listview_pat = re.compile(r'.*\s*ListView\s*{')
87+gridview_pat = re.compile(r'.*\s*GridView\s*{')
88+flickable_pats = [flickable_pat, listview_pat, gridview_pat]
89+unity_components_pat = re.compile(r'.*import ".*Components"')
90+components_import_pat = re.compile(r'.*import "."')
91+components_path = re.compile(r'.*qml/Components.*')
92+skip_components_flickable_path = re.compile(r'.*qml/Components/Flickable.qml')
93+skip_components_listview_path = re.compile(r'.*qml/Components/ListView.qml')
94+skip_components_gridview_path = re.compile(r'.*qml/Components/GridView.qml')
95+skip_mocks_path = re.compile(r'.*tests/mocks.*')
96+
97+def scan_for_flickable_imports(file_path, component_pats, qtquick_pat, unitycomponents_pat):
98+ errors = []
99+ with open(file_path, 'rt', encoding='utf-8') as ifile, open(file_path, 'rt', encoding='utf-8') as i2file:
100+ flickable_found = False
101+ for lino, line in enumerate(ifile, start=1):
102+ for component_pat in component_pats:
103+ if component_pat.match(line):
104+ flickable_found = True
105+ if flickable_found:
106+ qtquick_found = False
107+ unitycomponents_found = False
108+ for lino, line in enumerate(i2file, start=1):
109+ if not qtquick_found and qtquick_pat.match(line):
110+ qtquick_found = True
111+ if unitycomponents_pat.match(line):
112+ unitycomponents_found = True
113+ if not qtquick_found:
114+ errors.append(lino)
115+ else:
116+ return
117+ if not unitycomponents_found:
118+ errors.append(lino)
119+ if 0 < len(errors) <= 10:
120+ if len(errors) > 1:
121+ plural = 's'
122+ else:
123+ plural = ''
124+ print(
125+ "%s: missing/wrong order of Components import in line%s %s" % (
126+ file_path, plural, ", ".join((str(i) for i in errors))))
127+ elif errors:
128+ print("%s: missing/wrong order of Components imports in multiple lines" % file_path)
129+ return bool(errors)
130+
84131# Parse args
85132
86133parser = argparse.ArgumentParser(
@@ -116,6 +163,17 @@ try:
116163 found_bad_import = True
117164 if scan_for_bad_import(path, ubuntu_components_pat, [ubuntu_good_components_pat]):
118165 found_bad_import = True
166+ if skip_mocks_path.match(path) or \
167+ skip_components_flickable_path.match(path) or \
168+ skip_components_listview_path.match(path) or \
169+ skip_components_gridview_path.match(path):
170+ break
171+ if not components_path.match(path):
172+ if scan_for_flickable_imports(path, flickable_pats, quick_good_pat, unity_components_pat):
173+ found_bad_import = True
174+ else:
175+ if scan_for_flickable_imports(path, flickable_pats, quick_good_pat, components_import_pat):
176+ found_bad_import = True
119177
120178except OSError as e:
121179 error("cannot create file list for \"" + dir + "\": " + e.strerror)
tests/qmltests/Dash/Previews/tst_PreviewRatingDisplayCreationRanges.qml+1
@@ -18,6 +18,7 @@ import QtQuick 2.4
1818import QtTest 1.0
1919import Ubuntu.Components 1.3
2020import "../../../../qml/Dash/Previews"
21+import "../../../../qml/Components"
2122import Unity.Test 0.1 as UT
2223
2324Flickable {
tests/qmltests/tst_OrientedShell.qml+1
@@ -28,6 +28,7 @@ import Unity.InputInfo 0.1
2828import Utils 0.1
2929
3030import "../../qml"
31+import "../../qml/Components"
3132import "Stages"
3233
3334Rectangle {