~ci-train-bot/ubuntu-settings-components/ubuntu-settings-components-ubuntu-yakkety-1895

« back to all changes in this revision

Viewing changes to plugins/Ubuntu/Settings/Fingerprint/FingerprintVisual.qml

  • Committer: Bileto Bot
  • Date: 2016-06-20 14:01:03 UTC
  • mfrom: (103.6.69 fingerprint)
  • Revision ID: ci-train-bot@canonical.com-20160620140103-q57lulbze89e6yyd
jonas-drange
* Add components for Fingerprint management.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 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 Lesser 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 Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 *
 
16
 * Authored by Jonas G. Drange <jonas.drange@canonical.com>
 
17
 *             Florian Boucault <florian.boucault@canonical.com>
 
18
 */
 
19
 
 
20
import QtQuick 2.4
 
21
import Ubuntu.Settings.Fingerprint 0.1
 
22
 
 
23
SegmentedImage {
 
24
    id: segmentedImage
 
25
 
 
26
    property var masks: []
 
27
 
 
28
    // http://stackoverflow.com/a/1830844/538866
 
29
    function isNumeric (n) {
 
30
        return !isNaN(parseFloat(n)) && isFinite(n);
 
31
    }
 
32
 
 
33
    function getMasksToEnroll () {
 
34
        var outMasks = [];
 
35
        if (masks && masks.length) {
 
36
            masks.forEach(function (mask, i) {
 
37
                // Format is "<source>/[x1,y1,w1,h1],…,[xn,yn,wn,hn]"
 
38
                // If any value is non-numeric, we drop the mask.
 
39
                if (!isNumeric(mask.x) || !isNumeric(mask.y) || !isNumeric(mask.width)
 
40
                    || !isNumeric(mask.height))
 
41
                    return;
 
42
 
 
43
                // Translate the box so as to mirror the mask
 
44
                mask.x = (1 - (mask.x + mask.width));
 
45
 
 
46
                outMasks.push(mask);
 
47
            });
 
48
        }
 
49
        return outMasks;
 
50
    }
 
51
 
 
52
    onMasksChanged: segmentedImage.enrollMasks(getMasksToEnroll())
 
53
 
 
54
    textureSource: "qrc:/assets/fingerprint_segmented.png"
 
55
    boxesSource: "qrc:/assets/fingerprint_boxes.json"
 
56
 
 
57
    Repeater {
 
58
        model: segmentedImage.masks
 
59
 
 
60
        Rectangle {
 
61
            visible: UbuntuSettingsFingerprint.debug
 
62
            color: "red"
 
63
            opacity: 0.25
 
64
            x: modelData.x * segmentedImage.implicitWidth
 
65
            y: modelData.y * segmentedImage.implicitHeight
 
66
            width: modelData.width * segmentedImage.implicitWidth
 
67
            height: modelData.height * segmentedImage.implicitHeight
 
68
 
 
69
            Component.onCompleted: console.log('Scanner mask (x, y, w, h):', x, y, width, height)
 
70
        }
 
71
    }
 
72
}