forked from bitcoin-core/gui-qml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
qml, control: new IPAddressValueInput
Adding a new improved ValueInput control to handle both IP address and port values combined in the same field with the correct visual formatting (255.255.255.255:65535). In this iteration, validation for this control is implemented using both a function within the control itself focused solely on ensuring correct formatting and a simple regex validator for the valid input characters. Future versions will see integration with network model classes, enabling parsing of IP addresses and ports and additional checks, such as those outlined in doc/p2p-bad-ports.md.
- Loading branch information
1 parent
9db473a
commit a4f4263
Showing
3 changed files
with
98 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright (c) 2024 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
import QtQuick 2.15 | ||
import QtQuick.Controls 2.15 | ||
|
||
TextInput { | ||
id: root | ||
required property string parentState | ||
property string description: "" | ||
property bool filled: false | ||
property int descriptionSize: 18 | ||
property color textColor: root.filled ? Theme.color.neutral9 : Theme.color.neutral5 | ||
enabled: true | ||
state: root.parentState | ||
validator: RegExpValidator { regExp: /[0-9.:]*/ } // Allow only digits, dots, and colons | ||
selectByMouse: true // Enable text selection with the mouse | ||
|
||
maximumLength: 21 | ||
|
||
states: [ | ||
State { | ||
name: "ACTIVE" | ||
PropertyChanges { target: root; textColor: Theme.color.orange } | ||
}, | ||
State { | ||
name: "HOVER" | ||
PropertyChanges { | ||
target: root | ||
textColor: root.filled ? Theme.color.orangeLight1 : Theme.color.neutral5 | ||
} | ||
}, | ||
State { | ||
name: "DISABLED" | ||
PropertyChanges { | ||
target: root | ||
enabled: false | ||
textColor: Theme.color.neutral4 | ||
} | ||
} | ||
] | ||
|
||
font.family: "Inter" | ||
font.styleName: "Regular" | ||
font.pixelSize: root.descriptionSize | ||
color: root.textColor | ||
text: root.description | ||
horizontalAlignment: Text.AlignRight | ||
wrapMode: Text.WordWrap | ||
|
||
Behavior on color { | ||
ColorAnimation { duration: 150 } | ||
} | ||
|
||
function isValidIPPort(input) | ||
{ | ||
var parts = input.split(":"); | ||
if (parts.length !== 2) return false; | ||
if (parts[1].length === 0) return false; // port part is empty | ||
var ipAddress = parts[0]; | ||
var ipAddressParts = ipAddress.split("."); | ||
if (ipAddressParts.length !== 4) return false; | ||
for (var i = 0; (i < ipAddressParts.length); i++) { | ||
if (ipAddressParts[i].length === 0) return false; // ip group number part is empty | ||
if (parseInt(ipAddressParts[i]) > 255) return false; | ||
} | ||
var port = parseInt(parts[1]); | ||
if (port < 1 || port > 65535) return false; | ||
return true; | ||
} | ||
} |