Merge pull request #2543

bc40942 StandardDropdown: implement automatic closing (xiphon)
This commit is contained in:
luigi1111 2019-12-03 22:32:10 -06:00
commit c2dbda63c6
No known key found for this signature in database
GPG key ID: F4ACA0183641E010

View file

@ -27,6 +27,7 @@
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import QtQuick 2.9 import QtQuick 2.9
import QtQuick.Controls 2.2
import QtGraphicalEffects 1.0 import QtGraphicalEffects 1.0
import "../components" as MoneroComponents import "../components" as MoneroComponents
@ -42,7 +43,7 @@ Item {
property string releasedColor: MoneroComponents.Style.titleBarButtonHoverColor property string releasedColor: MoneroComponents.Style.titleBarButtonHoverColor
property string textColor: MoneroComponents.Style.defaultFontColor property string textColor: MoneroComponents.Style.defaultFontColor
property alias currentIndex: columnid.currentIndex property alias currentIndex: columnid.currentIndex
property bool expanded: false readonly property alias expanded: popup.visible
property int dropdownHeight: 42 property int dropdownHeight: 42
property int fontHeaderSize: 16 property int fontHeaderSize: 16
property int fontItemSize: 14 property int fontItemSize: 14
@ -56,18 +57,6 @@ Item {
signal changed(); signal changed();
onExpandedChanged: if(expanded) appWindow.currentItem = dropdown onExpandedChanged: if(expanded) appWindow.currentItem = dropdown
function hide() { dropdown.expanded = false }
function containsPoint(px, py) {
if(px < 0)
return false
if(px > width)
return false
if(py < 0)
return false
if(py > height + droplist.height)
return false
return true
}
// Workaroud for suspected memory leak in 5.8 causing malloc crash on app exit // Workaroud for suspected memory leak in 5.8 causing malloc crash on app exit
function update() { function update() {
@ -128,118 +117,118 @@ Item {
MouseArea { MouseArea {
id: dropArea id: dropArea
anchors.fill: parent anchors.fill: parent
onClicked: dropdown.expanded = !dropdown.expanded onClicked: dropdown.expanded ? popup.close() : popup.open()
hoverEnabled: true hoverEnabled: true
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
} }
} }
Rectangle { Popup {
id: droplist id: popup
anchors.left: parent.left padding: 0
anchors.right: parent.right
anchors.top: head.bottom
clip: true
height: dropdown.expanded ? columnid.height : 0
color: dropdown.pressedColor
Rectangle { Rectangle {
anchors.left: parent.left id: droplist
anchors.top: parent.top x: dropdown.x
width: 3; height: 3 width: dropdown.width
y: head.y + head.height
clip: true
height: dropdown.expanded ? columnid.height : 0
color: dropdown.pressedColor color: dropdown.pressedColor
}
Rectangle { Rectangle {
anchors.right: parent.right anchors.left: parent.left
anchors.top: parent.top anchors.top: parent.top
width: 3; height: 3 width: 3; height: 3
color: dropdown.pressedColor color: dropdown.pressedColor
} }
Behavior on height { Rectangle {
NumberAnimation { duration: 100; easing.type: Easing.InQuad } anchors.right: parent.right
} anchors.top: parent.top
width: 3; height: 3
color: dropdown.pressedColor
}
Column { Behavior on height {
id: columnid NumberAnimation { duration: 100; easing.type: Easing.InQuad }
anchors.left: parent.left }
anchors.right: parent.right
anchors.top: parent.top
property int currentIndex: 0
Repeater { Column {
id: repeater id: columnid
anchors.left: parent.left
anchors.right: parent.right
anchors.top: parent.top
property int currentIndex: 0
// Workaround for translations in listElements. All translated strings needs to be listed in this file. Repeater {
property string stringLow: qsTr("Low (x1 fee)") + translationManager.emptyString id: repeater
property string stringMedium: qsTr("Medium (x20 fee)") + translationManager.emptyString
property string stringHigh: qsTr("High (x166 fee)") + translationManager.emptyString
property string stringSlow: qsTr("Slow (x0.25 fee)") + translationManager.emptyString
property string stringDefault: qsTr("Default (x1 fee)") + translationManager.emptyString
property string stringFast: qsTr("Fast (x5 fee)") + translationManager.emptyString
property string stringFastest: qsTr("Fastest (x41.5 fee)") + translationManager.emptyString
property string stringAll: qsTr("All") + translationManager.emptyString
property string stringSent: qsTr("Sent") + translationManager.emptyString
property string stringReceived: qsTr("Received") + translationManager.emptyString
delegate: Rectangle { // Workaround for translations in listElements. All translated strings needs to be listed in this file.
anchors.left: parent.left property string stringAutomatic: qsTr("Automatic") + translationManager.emptyString
anchors.right: parent.right property string stringSlow: qsTr("Slow (x0.2 fee)") + translationManager.emptyString
height: (dropdown.dropdownHeight * 0.75) property string stringNormal: qsTr("Normal (x1 fee)") + translationManager.emptyString
//radius: index === repeater.count - 1 ? 4 : 0 property string stringFast: qsTr("Fast (x5 fee)") + translationManager.emptyString
color: itemArea.containsMouse || index === columnid.currentIndex || itemArea.containsMouse ? dropdown.releasedColor : dropdown.pressedColor property string stringFastest: qsTr("Fastest (x200 fee)") + translationManager.emptyString
MoneroComponents.TextPlain { delegate: Rectangle {
id: col1Text
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left anchors.left: parent.left
anchors.right: col2Text.left
anchors.leftMargin: 12
anchors.rightMargin: 0
font.family: MoneroComponents.Style.fontRegular.name
font.bold: true
font.pixelSize: fontItemSize
color: itemArea.containsMouse || index === columnid.currentIndex || itemArea.containsMouse ? "#FA6800" : "#FFFFFF"
text: qsTr(column1) + translationManager.emptyString
}
MoneroComponents.TextPlain {
id: col2Text
anchors.verticalCenter: parent.verticalCenter
anchors.right: parent.right anchors.right: parent.right
anchors.rightMargin: 45 height: (dropdown.dropdownHeight * 0.75)
font.family: MoneroComponents.Style.fontRegular.name //radius: index === repeater.count - 1 ? 4 : 0
font.pixelSize: 14 color: itemArea.containsMouse || index === columnid.currentIndex || itemArea.containsMouse ? dropdown.releasedColor : dropdown.pressedColor
color: "#FFFFFF"
text: ""
}
Rectangle { MoneroComponents.TextPlain {
anchors.left: parent.left id: col1Text
anchors.top: parent.top anchors.verticalCenter: parent.verticalCenter
width: 3; height: 3 anchors.left: parent.left
color: parent.color anchors.right: col2Text.left
} anchors.leftMargin: 12
anchors.rightMargin: 0
font.family: MoneroComponents.Style.fontRegular.name
font.bold: true
font.pixelSize: fontItemSize
color: itemArea.containsMouse || index === columnid.currentIndex || itemArea.containsMouse ? "#FA6800" : "#FFFFFF"
text: qsTr(column1) + translationManager.emptyString
}
Rectangle { MoneroComponents.TextPlain {
anchors.right: parent.right id: col2Text
anchors.top: parent.top anchors.verticalCenter: parent.verticalCenter
width: 3; height: 3 anchors.right: parent.right
color: parent.color anchors.rightMargin: 45
} font.family: MoneroComponents.Style.fontRegular.name
font.pixelSize: 14
color: "#FFFFFF"
text: ""
}
MouseArea { Rectangle {
id: itemArea anchors.left: parent.left
anchors.fill: parent anchors.top: parent.top
hoverEnabled: true width: 3; height: 3
cursorShape: Qt.PointingHandCursor color: parent.color
}
onClicked: { Rectangle {
dropdown.expanded = false anchors.right: parent.right
columnid.currentIndex = index anchors.top: parent.top
changed(); width: 3; height: 3
dropdown.update() color: parent.color
}
MouseArea {
id: itemArea
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
popup.close()
columnid.currentIndex = index
changed();
dropdown.update()
}
} }
} }
} }