Commit 2dd1a681 authored by Ronan Abhamon's avatar Ronan Abhamon

feat(Popup/DropDownMenu): better attributes to deal with relative items

parent 27c93278
...@@ -27,9 +27,9 @@ Item { ...@@ -27,9 +27,9 @@ Item {
property alias childA: contentA.data property alias childA: contentA.data
property alias childB: contentB.data property alias childB: contentB.data
property bool defaultClosed: false property bool defaultClosed: false
property bool resizeAInPriority: false
property int closingEdge: Qt.LeftEdge // `LeftEdge` or `RightEdge`. property int closingEdge: Qt.LeftEdge // `LeftEdge` or `RightEdge`.
property int defaultChildAWidth property int defaultChildAWidth
property bool resizeAInPriority: false
// User limits: string or int values. // User limits: string or int values.
// By default: no limits. // By default: no limits.
...@@ -251,7 +251,6 @@ Item { ...@@ -251,7 +251,6 @@ Item {
onDoubleClicked: _inverseClosingState() onDoubleClicked: _inverseClosingState()
onMouseXChanged: pressed && onMouseXChanged: pressed &&
_applyLimitsOnUserMove(mouseX - _mouseStart) _applyLimitsOnUserMove(mouseX - _mouseStart)
onPressed: _mouseStart = mouseX onPressed: _mouseStart = mouseX
Rectangle { Rectangle {
......
...@@ -9,11 +9,19 @@ import Utils 1.0 ...@@ -9,11 +9,19 @@ import Utils 1.0
// =================================================================== // ===================================================================
Rectangle { Rectangle {
property bool drawOnRoot: false // Attributes used only with a ListView child.
property int entryHeight // Only with a ListView child. property int entryHeight
property int maxMenuHeight // Only with a ListView child. property int maxMenuHeight
// Optionnal parameter, if defined and if a click is detected
// on it, menu is not closed.
property var launcher property var launcher
// Optionnal parameters, set the position of Menu relative
// to this item.
property var relativeTo property var relativeTo
property int relativeX: 0
property int relativeY: 0
default property alias _content: content.data default property alias _content: content.data
...@@ -25,9 +33,9 @@ Rectangle { ...@@ -25,9 +33,9 @@ Rectangle {
return return
} }
if (drawOnRoot) { if (relativeTo != null) {
this.x = relativeTo.mapToItem(null, relativeTo.width, 0).x this.x = relativeTo.mapToItem(null, relativeX, relativeY).x
this.y = relativeTo.mapToItem(null, relativeTo.width, 0).y this.y = relativeTo.mapToItem(null, relativeX, relativeY).y
} }
visible = true visible = true
...@@ -49,6 +57,11 @@ Rectangle { ...@@ -49,6 +57,11 @@ Rectangle {
return content.height return content.height
} }
console.assert(
entryHeight != null,
'`entryHeight` must be defined when used with `ListView`.'
)
var height = model.count * entryHeight var height = model.count * entryHeight
return (maxMenuHeight !== undefined && height > maxMenuHeight) return (maxMenuHeight !== undefined && height > maxMenuHeight)
? maxMenuHeight ? maxMenuHeight
...@@ -61,12 +74,14 @@ Rectangle { ...@@ -61,12 +74,14 @@ Rectangle {
Keys.onEscapePressed: hideMenu() Keys.onEscapePressed: hideMenu()
// Set parent menu to root.
Component.onCompleted: { Component.onCompleted: {
if (drawOnRoot) { if (relativeTo != null) {
parent = Utils.getTopParent(this) parent = Utils.getTopParent(this)
} }
} }
// Menu content.
Rectangle { Rectangle {
id: content id: content
...@@ -79,6 +94,7 @@ Rectangle { ...@@ -79,6 +94,7 @@ Rectangle {
} }
} }
// Inverted mouse area to detect click outside menu.
InvertedMouseArea { InvertedMouseArea {
anchors.fill: parent anchors.fill: parent
enabled: parent.visible enabled: parent.visible
......
...@@ -21,8 +21,8 @@ Item { ...@@ -21,8 +21,8 @@ Item {
property alias placeholderText: searchField.placeholderText property alias placeholderText: searchField.placeholderText
signal menuClosed () signal menuClosed
signal menuOpened () signal menuOpened
function _hideMenu () { function _hideMenu () {
menu.hideMenu() menu.hideMenu()
......
...@@ -50,13 +50,14 @@ RowLayout { ...@@ -50,13 +50,14 @@ RowLayout {
} }
DropDownMenu { DropDownMenu {
drawOnRoot: true
id: menu id: menu
entryHeight: 22 entryHeight: 22
height: 100 height: 100
width: 120
launcher: button launcher: button
relativeTo: button relativeTo: button
relativeX: button.width
width: 120
Rectangle { Rectangle {
color: 'red' color: 'red'
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment