Skip to content

Commit

Permalink
Merge branch 'master' of github.com:quantum-os/qml-extras
Browse files Browse the repository at this point in the history
  • Loading branch information
iBelieve committed Jan 19, 2015
2 parents 0584797 + fe8199a commit ccafd38
Show file tree
Hide file tree
Showing 8 changed files with 95 additions and 5 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
tests/tst_extras
.qmake.stash
Makefile
*.o
*.o
*.pro.user*
*~
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,6 @@ install:
script:
- qmake
- make check

notifications:
slack: papyros:Dfl04xnx2RdvHLiue5Lm7v5R
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
8 changes: 5 additions & 3 deletions modules/Material/Extras/CircleImage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,30 @@
*/

import QtQuick 2.3
import Material.Extras 0.1 as Extras
import QtGraphicalEffects 1.0

Item {
id: 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
visible: false
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
Expand Down
37 changes: 37 additions & 0 deletions modules/Material/Extras/Image.qml
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
32 changes: 32 additions & 0 deletions modules/Material/Extras/js/dateutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions modules/Material/Extras/js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}
1 change: 1 addition & 0 deletions modules/Material/Extras/qmldir
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit ccafd38

Please sign in to comment.