maxLibQt
MLHexSpinBox.qml
Go to the documentation of this file.
1 /*
2  MLHexSpinBox
3  https://github.com/mpaperno/maxLibQt
4 
5  COPYRIGHT: (c)2018 Maxim Paperno; All Right Reserved.
6  Contact: http://www.WorldDesign.com/contact
7 
8  LICENSE:
9 
10  Commercial License Usage
11  Licensees holding valid commercial licenses may use this file in
12  accordance with the terms contained in a written agreement between
13  you and the copyright holder.
14 
15  GNU General Public License Usage
16  Alternatively, this file may be used under the terms of the GNU
17  General Public License as published by the Free Software Foundation,
18  either version 3 of the License, or (at your option) any later version.
19 
20  This program is distributed in the hope that it will be useful,
21  but WITHOUT ANY WARRANTY; without even the implied warranty of
22  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23  GNU General Public License for more details.
24 
25  A copy of the GNU General Public License is available at <http://www.gnu.org/licenses/>.
26 */
27 
28 import QtQuick 2.10
29 import QtQuick.Controls 2.3
30 
42 MLDoubleSpinBox {
43  id: control
44  objectName: "MLHexSpinBox"
45 
46  property bool upperCase: true
47  property bool zeroPad: true
48  property bool showPrefix: true
49  property int digits: Math.abs(topValue).toString(16).length
50 
51  from: 0
52  to: 0xFFFFFFFF
53  decimals: 0
54  inputMethodHints: Qt.ImhNoPredictiveText | (upperCase ? Qt.ImhPreferUppercase : 0)
55  inputMask: (value < 0 ? "-" : "") + (showPrefix ? "\\0\\x" : "") + "H".repeat(digits)
56 
57  validator: RegExpValidator {
58  regExp: new RegExp("-?(0x)?[0-9A-Fa-f]{1," + control.digits + "}")
59  }
60 
61  function textFromValue(value, locale) {
62  var ret = Math.abs(Number(value)).toString(16);
63  if (zeroPad && digits > ret.length)
64  ret = "0".repeat(digits - ret.length) + ret;
65  if (upperCase)
66  ret = ret.toUpperCase();
67  if (showPrefix)
68  ret = "0x" + ret;
69 
70  return ret;
71  }
72 
73  function valueFromText(text, locale) {
74  return parseInt(text, 16);
75  }
76 
77 }
QString objectName() const const
int length() const const