Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/plugin-datetime/qml/TimeAndDate.qml
Original file line number Diff line number Diff line change
Expand Up @@ -225,20 +225,21 @@ DccObject {
pageType: DccObject.Editor
page: Item {
id: item
implicitHeight: 40
implicitHeight: addrErrorTip.visible ? 40 + addrErrorTip.height + 4 : 40
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: Avoid repeating the 40 constant in layout calculations to reduce maintenance issues.

This height is now hardcoded in multiple places (e.g. implicitHeight and topMargin: (40 - addr.height) / 2), so changing the base row height requires updating each occurrence. Define a local property (e.g. property int rowHeight: 40) on the Item and use it in all related calculations instead.

Suggested implementation:

            pageType: DccObject.Editor
            page: Item {
                id: item
                property int rowHeight: 40
                implicitHeight: addrErrorTip.visible ? rowHeight + addrErrorTip.height + 4 : rowHeight
                implicitWidth: 300


Search within the same Item (and related layout code for this row) for other hardcoded 40 usages, such as topMargin: (40 - addr.height) / 2, and replace them with expressions that use rowHeight instead, e.g. topMargin: (rowHeight - addr.height) / 2. This ensures all layout calculations stay consistent when rowHeight is changed.

implicitWidth: 300

D.LineEdit {
id: addr
implicitWidth: 200
text: dateAndTimeSettings.customAddr
placeholderText: qsTr("Required")
alertText: qsTr("The ntp server address cannot be empty")
alertDuration: 3000
showAlert: false
horizontalAlignment: background.visible ? TextInput.AlignLeft : TextInput.AlignRight
anchors{
rightMargin: 5
right: editBtn.left
verticalCenter: parent.verticalCenter
top: parent.top
topMargin: (40 - addr.height) / 2
}
rightPadding: (!addr.readOnly && addr.text.length > 0 ? addr.clearButton.width : 5)
onReadOnlyChanged: {
Expand All @@ -247,19 +248,28 @@ DccObject {
addr.focus = !addr.readOnly
}
onTextChanged: {
if (addr.showAlert && addr.text.length > 0) {
if (addr.text.length > 0) {
addr.showAlert = false
addrErrorTip.visible = false
}
}
Component.onCompleted: {
Qt.callLater( function(){ addr.forceActiveFocus() } )
addr.readOnly = text.length > 0
}

D.AlertToolTip {
id: addrErrorTip
target: addr
text: qsTr("The ntp server address cannot be empty")
visible: false
timeout: 3000
}
}
D.IconButton {
id: editBtn
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
anchors.verticalCenter: addr.verticalCenter
hoverEnabled: true
background: Rectangle {
anchors.fill: parent
Expand All @@ -286,10 +296,12 @@ DccObject {
onClicked: {
if (addr.text.length === 0) {
addr.showAlert = true
addrErrorTip.visible = true
return
}

addr.showAlert = false
addrErrorTip.visible = false

if (!addr.readOnly) {
dccData.ntpServerAddress = addr.text
Expand Down
Loading