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* +*~ 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 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 diff --git a/modules/Material/Extras/CircleImage.qml b/modules/Material/Extras/CircleImage.qml index 8353049..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,9 +39,9 @@ Item { mipmap: true } - Image { + Extras.Image { id: mask - source: Qt.resolvedUrl("circle.png") + source: Qt.resolvedUrl("images/circle.png") anchors.fill: image smooth: true visible: false diff --git a/modules/Material/Extras/Image.qml b/modules/Material/Extras/Image.qml new file mode 100644 index 0000000..f4519ab --- /dev/null +++ b/modules/Material/Extras/Image.qml @@ -0,0 +1,37 @@ +import QtQuick 2.3 + +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); + } + } +} 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) 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"; + } +} diff --git a/modules/Material/Extras/qmldir b/modules/Material/Extras/qmldir index 2644ffe..0bb8241 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