~cherojeong/ubuntu-keyboard/korean-layout

« back to all changes in this revision

Viewing changes to qml/keys/KeyPad.qml

  • Committer: Michael Terry
  • Date: 2013-11-04 17:48:55 UTC
  • mfrom: (96 trunk)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: michael.terry@canonical.com-20131104174855-mtmwbdavrq77nl1r
Merge from trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2013 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
 
 
17
import QtQuick 2.0
 
18
 
 
19
Item {
 
20
    id: keyPadRoot
 
21
 
 
22
    state: "NORMAL"
 
23
 
 
24
    property var content: c1
 
25
    property string symbols: "languages/Keyboard_symbols.qml"
 
26
    property bool capsLock: false
 
27
 
 
28
    Column {
 
29
        id: c1
 
30
    }
 
31
 
 
32
    Component.onCompleted:
 
33
    {
 
34
        calculateKeyWidth();
 
35
        calculateKeyHeight();
 
36
    }
 
37
 
 
38
    onWidthChanged: calculateKeyWidth()
 
39
    onHeightChanged: calculateKeyHeight();
 
40
 
 
41
    function numberOfRows() {
 
42
        return content.children.length;
 
43
    }
 
44
 
 
45
    // we don´t use a QML layout, because we want all keys to be equally sized
 
46
    function calculateKeyWidth() {
 
47
        var width = panel.width;
 
48
 
 
49
        var maxNrOfKeys = 0;
 
50
        for (var i = 0; i < numberOfRows(); ++i) {
 
51
            if (content.children[i].children.length > maxNrOfKeys)
 
52
                maxNrOfKeys = content.children[i].children.length;
 
53
        }
 
54
 
 
55
        var maxSpaceForKeys = panel.width / maxNrOfKeys;
 
56
 
 
57
        panel.keyWidth = maxSpaceForKeys;
 
58
    }
 
59
 
 
60
    function calculateKeyHeight() {
 
61
        panel.keyHeight = panel.height / numberOfRows();
 
62
    }
 
63
}