Custom Button: better bar editor
This commit is contained in:
parent
4f3e0bdb1e
commit
f39dd2aa1c
2 changed files with 43 additions and 37 deletions
|
|
@ -131,7 +131,7 @@ NBox {
|
||||||
required property var modelData
|
required property var modelData
|
||||||
|
|
||||||
width: widgetContent.implicitWidth + Style.marginL * scaling
|
width: widgetContent.implicitWidth + Style.marginL * scaling
|
||||||
height: 40 * scaling
|
height: Style.baseWidgetSize * 1.15 * scaling
|
||||||
radius: Style.radiusL * scaling
|
radius: Style.radiusL * scaling
|
||||||
color: root.getWidgetColor(modelData)
|
color: root.getWidgetColor(modelData)
|
||||||
border.color: Color.mOutline
|
border.color: Color.mOutline
|
||||||
|
|
@ -145,6 +145,8 @@ NBox {
|
||||||
|
|
||||||
// Store the widget index for drag operations
|
// Store the widget index for drag operations
|
||||||
property int widgetIndex: index
|
property int widgetIndex: index
|
||||||
|
readonly property int buttonsWidth: Math.round(20 * scaling)
|
||||||
|
readonly property int buttonsCount: 1 + BarWidgetRegistry.widgetHasUserSettings(modelData.id)
|
||||||
|
|
||||||
// Visual feedback during drag
|
// Visual feedback during drag
|
||||||
states: State {
|
states: State {
|
||||||
|
|
@ -161,7 +163,7 @@ NBox {
|
||||||
id: widgetContent
|
id: widgetContent
|
||||||
|
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
spacing: Style.marginXS * scaling
|
spacing: Style.marginXXS * scaling
|
||||||
|
|
||||||
NText {
|
NText {
|
||||||
text: modelData.id
|
text: modelData.id
|
||||||
|
|
@ -172,6 +174,9 @@ NBox {
|
||||||
Layout.preferredWidth: 80 * scaling
|
Layout.preferredWidth: 80 * scaling
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RowLayout {
|
||||||
|
spacing: 0
|
||||||
|
Layout.preferredWidth: buttonsCount * buttonsWidth
|
||||||
Loader {
|
Loader {
|
||||||
active: BarWidgetRegistry.widgetHasUserSettings(modelData.id)
|
active: BarWidgetRegistry.widgetHasUserSettings(modelData.id)
|
||||||
sourceComponent: NIconButton {
|
sourceComponent: NIconButton {
|
||||||
|
|
@ -208,8 +213,11 @@ NBox {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Mouse area for drag and drop
|
// Mouse area for drag and drop
|
||||||
|
property int mouseXStartDrag: 0
|
||||||
|
|
||||||
MouseArea {
|
MouseArea {
|
||||||
id: mouseArea
|
id: mouseArea
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
|
@ -217,13 +225,8 @@ NBox {
|
||||||
|
|
||||||
onPressed: mouse => {
|
onPressed: mouse => {
|
||||||
// Check if the click is on the settings or close button area
|
// Check if the click is on the settings or close button area
|
||||||
const buttonsX = widgetContent.x + widgetContent.width - 45 * scaling
|
const buttonsX = widgetContent.x + widgetContent.width - (buttonsWidth * buttonsCount)
|
||||||
const buttonsY = widgetContent.y
|
if (mouseX >= buttonsX) {
|
||||||
const buttonsWidth = 45 * scaling
|
|
||||||
const buttonsHeight = 20 * scaling
|
|
||||||
|
|
||||||
if (mouseX >= buttonsX && mouseX <= buttonsX + buttonsWidth && mouseY >= buttonsY
|
|
||||||
&& mouseY <= buttonsY + buttonsHeight) {
|
|
||||||
// Click is on the buttons, don't start drag
|
// Click is on the buttons, don't start drag
|
||||||
mouse.accepted = false
|
mouse.accepted = false
|
||||||
return
|
return
|
||||||
|
|
@ -232,13 +235,18 @@ NBox {
|
||||||
//Logger.log("BarSectionEditor", `Started dragging widget: ${modelData.id} at index ${index}`)
|
//Logger.log("BarSectionEditor", `Started dragging widget: ${modelData.id} at index ${index}`)
|
||||||
// Bring to front when starting drag
|
// Bring to front when starting drag
|
||||||
widgetItem.z = 1000
|
widgetItem.z = 1000
|
||||||
|
mouseXStartDrag = mouseX
|
||||||
}
|
}
|
||||||
|
|
||||||
onReleased: {
|
onReleased: mouse => {
|
||||||
//Logger.log("BarSectionEditor", `Released widget: ${modelData.id} at index ${index}`)
|
//Logger.log("BarSectionEditor", `Released widget: ${modelData.id} at index ${index}`)
|
||||||
// Reset z-index when drag ends
|
// Reset z-index when drag ends
|
||||||
widgetItem.z = 0
|
widgetItem.z = 0
|
||||||
|
|
||||||
|
console.log(mouseXStartDrag - mouse.x)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Get the global mouse position
|
// Get the global mouse position
|
||||||
const globalDropX = mouseArea.mouseX + widgetItem.x + widgetFlow.x
|
const globalDropX = mouseArea.mouseX + widgetItem.x + widgetFlow.x
|
||||||
const globalDropY = mouseArea.mouseY + widgetItem.y + widgetFlow.y
|
const globalDropY = mouseArea.mouseY + widgetItem.y + widgetFlow.y
|
||||||
|
|
|
||||||
|
|
@ -129,8 +129,6 @@ Popup {
|
||||||
placeholderText: "Enter icon name (e.g., favorite, home, settings)"
|
placeholderText: "Enter icon name (e.g., favorite, home, settings)"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
NTextInput {
|
NTextInput {
|
||||||
id: leftClickExecInput
|
id: leftClickExecInput
|
||||||
Layout.fillWidth: true
|
Layout.fillWidth: true
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue