Changeset View
Changeset View
Standalone View
Standalone View
kcms/nightcolor/package/contents/ui/NumberField.qml
- This file was added.
1 | /******************************************************************** | ||||
---|---|---|---|---|---|
2 | Copyright 2017 Roman Gilg <subdiff@gmail.com> | ||||
3 | | ||||
4 | This program is free software; you can redistribute it and/or modify | ||||
5 | it under the terms of the GNU General Public License as published by | ||||
6 | the Free Software Foundation; either version 2 of the License, or | ||||
7 | (at your option) any later version. | ||||
8 | | ||||
9 | This program is distributed in the hope that it will be useful, | ||||
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
12 | GNU General Public License for more details. | ||||
13 | | ||||
14 | You should have received a copy of the GNU General Public License | ||||
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
16 | *********************************************************************/ | ||||
17 | import QtQuick 2.1 | ||||
18 | import QtQuick.Controls 1.4 as Controls | ||||
19 | | ||||
20 | Controls.TextField { | ||||
21 | property double backend | ||||
22 | | ||||
23 | maximumLength: 10 | ||||
24 | horizontalAlignment: TextInput.AlignHCenter | ||||
25 | | ||||
26 | inputMethodHints: Qt.ImhFormattedNumbersOnly | ||||
27 | | ||||
28 | text: backend | ||||
29 | | ||||
30 | onBackendChanged: { | ||||
31 | text = backend; | ||||
32 | } | ||||
33 | | ||||
34 | onTextChanged: { | ||||
35 | var textFloat = parseFloat(text); | ||||
36 | if (textFloat == undefined || isNaN(textFloat)) { | ||||
37 | return; | ||||
38 | } | ||||
39 | backend = textFloat; | ||||
40 | } | ||||
41 | | ||||
42 | onFocusChanged: { | ||||
43 | var textFloat = parseFloat(text); | ||||
44 | if (!focus && (textFloat == undefined || isNaN(textFloat))) { | ||||
45 | text = backend; | ||||
46 | } | ||||
47 | } | ||||
48 | } |