From 2423321be7a8ef012ff7ee9d07d789ddfb8c4d6b Mon Sep 17 00:00:00 2001 From: Bogdan Cuza Date: Tue, 16 Dec 2014 20:35:40 +0200 Subject: [PATCH 01/10] Create Image.qml It includes a color averaging function --- modules/Material/Extras/Image.qml | 37 +++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 modules/Material/Extras/Image.qml diff --git a/modules/Material/Extras/Image.qml b/modules/Material/Extras/Image.qml new file mode 100644 index 0000000..0de3c87 --- /dev/null +++ b/modules/Material/Extras/Image.qml @@ -0,0 +1,37 @@ +import QtQuick 2.0 + +Image { + id: image + + property color averageColor + + Canvas { + id: canvas + + opacity: 0 + + onAvailableChanged: { + var imgSource = image.source; + canvas.loadImage(String(imgSource)); + var context = canvas.getContext("2d"), + pixelInterval = 5, + count = 0, + i = -4, + rgba = {"r": 0, "g": 0, "b": 0, "a": 0}, + data = context.createImageData(String(imgSource)).data, + length = data.length; + while ((i += pixelInterval * 4) < length) { + count++; + rgba.r += data[i]; + rgba.g += data[i+1]; + rgba.b += data[i+2]; + rgba.a += data[i+3]; + }; + rgba.r = Math.floor(rgba.r/count); + rgba.g = Math.floor(rgba.g/count); + rgba.b = Math.floor(rgba.b/count); + rgba.a = Math.floor(rgba.a/count); + image.averageColor = Qt.rgba(rgba.r/255, rgba.g/255, rgba.b/255, rgba.a/255); + } + } +} From 8427c43a1ce49841155c939661fd6b5309ea1f38 Mon Sep 17 00:00:00 2001 From: Bogdan Cuza Date: Tue, 30 Dec 2014 15:59:10 +0200 Subject: [PATCH 02/10] Update CircleImage.qml --- modules/Material/Extras/CircleImage.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Material/Extras/CircleImage.qml b/modules/Material/Extras/CircleImage.qml index 8353049..55e2161 100644 --- a/modules/Material/Extras/CircleImage.qml +++ b/modules/Material/Extras/CircleImage.qml @@ -39,7 +39,7 @@ Item { Image { id: mask - source: Qt.resolvedUrl("circle.png") + source: Qt.resolvedUrl("images/circle.png") anchors.fill: image smooth: true visible: false From 77236320aab6c3347e68c35427ab09dd42398098 Mon Sep 17 00:00:00 2001 From: Bogdan Cuza Date: Tue, 30 Dec 2014 16:53:11 +0200 Subject: [PATCH 03/10] Update qmldir --- modules/Material/Extras/qmldir | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/Material/Extras/qmldir b/modules/Material/Extras/qmldir index 2b28eee..5169cbe 100644 --- a/modules/Material/Extras/qmldir +++ b/modules/Material/Extras/qmldir @@ -1,6 +1,7 @@ module Material.Extras CircleImage 0.1 CircleImage.qml +Image 0.1 Image.qml ColumnFlow 0.1 ColumnFlow.qml Document 0.1 Document.qml Object 0.1 Object.qml From efc50d781e60a69eed94196de7c80acf77745967 Mon Sep 17 00:00:00 2001 From: Bogdan Cuza Date: Tue, 30 Dec 2014 17:18:53 +0200 Subject: [PATCH 04/10] Average color for CircleImage --- modules/Material/Extras/CircleImage.qml | 6 ++++-- modules/Material/Extras/Image.qml | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/Material/Extras/CircleImage.qml b/modules/Material/Extras/CircleImage.qml index 55e2161..cf193fb 100644 --- a/modules/Material/Extras/CircleImage.qml +++ b/modules/Material/Extras/CircleImage.qml @@ -18,6 +18,7 @@ */ import QtQuick 2.3 +import Material.Extras 0.1 as Extras import QtGraphicalEffects 1.0 Item { @@ -25,11 +26,12 @@ Item { property alias source: image.source property alias status: image.status + property alias averageColor: image.averageColor width: image.implicitWidth height: image.implicitHeight - Image { + Extras.Image { id: image anchors.fill: parent smooth: true @@ -37,7 +39,7 @@ Item { mipmap: true } - Image { + Extras.Image { id: mask source: Qt.resolvedUrl("images/circle.png") anchors.fill: image diff --git a/modules/Material/Extras/Image.qml b/modules/Material/Extras/Image.qml index 0de3c87..f4519ab 100644 --- a/modules/Material/Extras/Image.qml +++ b/modules/Material/Extras/Image.qml @@ -1,4 +1,4 @@ -import QtQuick 2.0 +import QtQuick 2.3 Image { id: image From 184ce4cd3682ebae4b5964f9f924673d7df51462 Mon Sep 17 00:00:00 2001 From: Bogdan Cuza Date: Mon, 5 Jan 2015 20:50:59 +0200 Subject: [PATCH 05/10] Add slack support --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index bf63053..31659ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,3 +11,6 @@ install: script: - qmake - make check + +notifications: + slack: papyros:Dfl04xnx2RdvHLiue5Lm7v5R From 6d1f003aad107073dc87df5309d232d162e55710 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Wed, 7 Jan 2015 13:33:11 -0600 Subject: [PATCH 06/10] Rename to Papyros --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fa0f31..aa16e94 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ QML Extras ========== -[![Build Status](https://travis-ci.org/quantum-os/qml-extras.svg)](https://travis-ci.org/quantum-os/qml-extras) +[![Build Status](https://travis-ci.org/papyros/qml-extras.svg)](https://travis-ci.org/papyros/qml-extras) Extra types and utilities to make QML even more awesome From d1282ff4d76ab1d626d9457af130d11286530c55 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Fri, 9 Jan 2015 22:46:16 -0600 Subject: [PATCH 07/10] Fix a incorrect path in CircleImage --- modules/Material/Extras/CircleImage.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/Material/Extras/CircleImage.qml b/modules/Material/Extras/CircleImage.qml index 8353049..55e2161 100644 --- a/modules/Material/Extras/CircleImage.qml +++ b/modules/Material/Extras/CircleImage.qml @@ -39,7 +39,7 @@ Item { Image { id: mask - source: Qt.resolvedUrl("circle.png") + source: Qt.resolvedUrl("images/circle.png") anchors.fill: image smooth: true visible: false From 76278abeb6e026e92aeb670d242e8598d8c65852 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Fri, 9 Jan 2015 22:46:34 -0600 Subject: [PATCH 08/10] Add a shortDuration function to DateUtils --- modules/Material/Extras/js/dateutils.js | 32 +++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/modules/Material/Extras/js/dateutils.js b/modules/Material/Extras/js/dateutils.js index 36cf134..32f6115 100644 --- a/modules/Material/Extras/js/dateutils.js +++ b/modules/Material/Extras/js/dateutils.js @@ -131,6 +131,38 @@ function friendlyTime(time, standalone) { return standalone ? Qt.formatDate(time) : ("on %1").arg(Qt.formatDate(time)) } +function pad(n, width, z) { + z = z || '0'; + n = n + ''; + return n.length >= width ? n : new Array(width - n.length + 1).join(z) + n; +} + +function shortDuration(duration, type) { + var hours = Math.floor(duration/(1000 * 60 * 60)) + var minutes = Math.floor(duration/(1000 * 60) - 60 * hours) + var seconds = Math.floor(duration/1000 - 60 * minutes - 60 * 60 * hours) + + if (type === undefined) + type = '?' + + var str = '' + if (type === 's' || type === '?') + str = "%1".arg(pad(seconds, 2)) + if (type === 's' || type === 'm' || (type === '?' && (minutes >= 1 || hours >= 1))) { + if (str.length > 0) + str = "%1:%2".arg(pad(minutes, 2)).arg(str) + else + str = "%1".arg(pad(minutes, 2)) + } + if (type === 's' || type === 'm' || type === 'h' || (type === '?' && hours >= 1)) { + if (str.length > 0) + str = "%1:%2".arg(hours).arg(str) + else + str = "%1".arg(hours) + } + return str.trim() +} + function friendlyDuration(duration, type) { var hours = Math.floor(duration/(1000 * 60 * 60)) var minutes = Math.floor(duration/(1000 * 60) - 60 * hours) From 88abc56ea3b3a113552dceed1479ac0c4bfa305c Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Sat, 10 Jan 2015 22:16:51 -0600 Subject: [PATCH 09/10] Add a function for getting a number's ordinal --- modules/Material/Extras/js/utils.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/modules/Material/Extras/js/utils.js b/modules/Material/Extras/js/utils.js index 51857d6..7a701b0 100644 --- a/modules/Material/Extras/js/utils.js +++ b/modules/Material/Extras/js/utils.js @@ -110,7 +110,20 @@ function newObject(path, args, parent) { if (component.status === QtQuick.Component.Error) { // Error Handling print("Unable to load object: " + path + "\n" + component.errorString()) + return null } return component.createObject(parent, args); } + +function nth(d) { + if(d>3 && d<21) + return 'th'; // thanks kennebec + + switch (d % 10) { + case 1: return "st"; + case 2: return "nd"; + case 3: return "rd"; + default: return "th"; + } +} From fe8199abb560af45f9a02860bef2daadc99b7ab0 Mon Sep 17 00:00:00 2001 From: Michael Spencer Date: Sat, 10 Jan 2015 22:17:44 -0600 Subject: [PATCH 10/10] Updating the .gitignore file --- .gitignore | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d66a205..7821096 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,6 @@ tests/tst_extras .qmake.stash Makefile -*.o \ No newline at end of file +*.o +*.pro.user* +*~