Page & popups: standardized keyboard accept/cancel
This commit is contained in:
		
							
								
								
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								TODO.md
									
									
									
									
									
								
							| @@ -10,7 +10,7 @@ | |||||||
| - can leave room with a reason? | - can leave room with a reason? | ||||||
| - field/area focus line in popups weird | - field/area focus line in popups weird | ||||||
| - use new nio `restore_login()` | - use new nio `restore_login()` | ||||||
| - verify all popups and boxes work | - verify all popups and boxes work: enter/esc, tab focus, operations | ||||||
|  |  | ||||||
| ## Refactoring | ## Refactoring | ||||||
|  |  | ||||||
|   | |||||||
| @@ -7,10 +7,6 @@ HFlickableColumnPage { | |||||||
|     implicitWidth: Math.min(parent.width, theme.controls.box.defaultWidth) |     implicitWidth: Math.min(parent.width, theme.controls.box.defaultWidth) | ||||||
|     implicitHeight: Math.min(parent.height, flickable.contentHeight) |     implicitHeight: Math.min(parent.height, flickable.contentHeight) | ||||||
|  |  | ||||||
|     // XXX |  | ||||||
|     // Keys.onReturnPressed: if (clickButtonOnEnter) enterClickButton() |  | ||||||
|     // Keys.onEnterPressed: Keys.onReturnPressed(event) |  | ||||||
|  |  | ||||||
|     background: Rectangle { |     background: Rectangle { | ||||||
|         color: theme.controls.box.background |         color: theme.controls.box.background | ||||||
|         radius: theme.controls.box.radius |         radius: theme.controls.box.radius | ||||||
|   | |||||||
| @@ -7,6 +7,10 @@ Page { | |||||||
|     padding: currentSpacing < theme.spacing ? 0 : currentSpacing |     padding: currentSpacing < theme.spacing ? 0 : currentSpacing | ||||||
|     background: null |     background: null | ||||||
|  |  | ||||||
|  |     Keys.onReturnPressed: keyboardAccept() | ||||||
|  |     Keys.onEnterPressed: keyboardAccept() | ||||||
|  |     Keys.onEscapePressed: keyboardCancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     property bool useVariableSpacing: true |     property bool useVariableSpacing: true | ||||||
|  |  | ||||||
| @@ -19,6 +23,9 @@ Page { | |||||||
|         ) : |         ) : | ||||||
|         theme.spacing |         theme.spacing | ||||||
|  |  | ||||||
|  |     signal keyboardAccept() | ||||||
|  |     signal keyboardCancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     Behavior on padding { HNumberAnimation {} } |     Behavior on padding { HNumberAnimation {} } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -87,7 +87,8 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: cancel() |     onKeyboardCancel: cancel() | ||||||
|  |     onKeyboardAccept: applyChanges() | ||||||
|  |  | ||||||
|  |  | ||||||
|     HUserAvatar { |     HUserAvatar { | ||||||
| @@ -221,8 +222,6 @@ HFlickableColumnPage { | |||||||
|  |  | ||||||
|             // TODO: Qt 5.14+: use a Binding enabled when text not empty |             // TODO: Qt 5.14+: use a Binding enabled when text not empty | ||||||
|             color: utils.nameColor(text) |             color: utils.nameColor(text) | ||||||
|  |  | ||||||
|             onAccepted: applyChanges() |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
| @@ -262,7 +261,6 @@ HFlickableColumnPage { | |||||||
|         HTextField { |         HTextField { | ||||||
|             width: parent.width |             width: parent.width | ||||||
|             error: aliasField.alreadyTakenBy !== "" |             error: aliasField.alreadyTakenBy !== "" | ||||||
|             onAccepted: applyChanges() |  | ||||||
|             defaultText: aliasField.currentAlias |             defaultText: aliasField.currentAlias | ||||||
|             placeholderText: qsTr("e.g. %1").arg(( |             placeholderText: qsTr("e.g. %1").arg(( | ||||||
|                 nameField.item.text || |                 nameField.item.text || | ||||||
|   | |||||||
| @@ -92,7 +92,7 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: page.cancel() |     onKeyboardCancel: page.cancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     Timer { |     Timer { | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: cancel() |     onKeyboardCancel: cancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     HRoomAvatar { |     HRoomAvatar { | ||||||
|   | |||||||
| @@ -81,7 +81,7 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: cancel() |     onKeyboardCancel: cancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     CurrentUserAvatar { |     CurrentUserAvatar { | ||||||
|   | |||||||
| @@ -69,7 +69,7 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: cancel() |     onKeyboardCancel: cancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     CurrentUserAvatar { |     CurrentUserAvatar { | ||||||
|   | |||||||
| @@ -79,7 +79,8 @@ HFlickableColumnPage { | |||||||
|         } |         } | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     Keys.onEscapePressed: cancel() |     onKeyboardAccept: save() | ||||||
|  |     onKeyboardCancel: cancel() | ||||||
|  |  | ||||||
|  |  | ||||||
|     HRoomAvatar { |     HRoomAvatar { | ||||||
|   | |||||||
| @@ -10,6 +10,8 @@ HPopup { | |||||||
|     default property alias pageData: page.columnData |     default property alias pageData: page.columnData | ||||||
|     readonly property alias page: page |     readonly property alias page: page | ||||||
|  |  | ||||||
|  |     signal keyboardAccept() | ||||||
|  |  | ||||||
|  |  | ||||||
|     HColumnPage { |     HColumnPage { | ||||||
|         id: page |         id: page | ||||||
| @@ -23,5 +25,8 @@ HPopup { | |||||||
|             topPadding + bottomPadding + implicitContentHeight, |             topPadding + bottomPadding + implicitContentHeight, | ||||||
|         ) |         ) | ||||||
|         useVariableSpacing: false |         useVariableSpacing: false | ||||||
|  |  | ||||||
|  |         Keys.onReturnPressed: popup.keyboardAccept() | ||||||
|  |         Keys.onEnterPressed: popup.keyboardAccept() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -10,6 +10,8 @@ HPopup { | |||||||
|     default property alias pageData: page.columnData |     default property alias pageData: page.columnData | ||||||
|     readonly property alias page: page |     readonly property alias page: page | ||||||
|  |  | ||||||
|  |     signal keyboardAccept() | ||||||
|  |  | ||||||
|  |  | ||||||
|     HFlickableColumnPage { |     HFlickableColumnPage { | ||||||
|         id: page |         id: page | ||||||
| @@ -21,5 +23,8 @@ HPopup { | |||||||
|             popup.maximumPreferredHeight, |             popup.maximumPreferredHeight, | ||||||
|             implicitHeaderHeight + implicitFooterHeight + contentHeight, |             implicitHeaderHeight + implicitFooterHeight + contentHeight, | ||||||
|         ) |         ) | ||||||
|  |  | ||||||
|  |         Keys.onReturnPressed: popup.keyboardAccept() | ||||||
|  |         Keys.onEnterPressed: popup.keyboardAccept() | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -74,6 +74,7 @@ HFlickableColumnPopup { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     onOpened: passwordField.forceActiveFocus() |     onOpened: passwordField.forceActiveFocus() | ||||||
|  |     onKeyboardAccept: popup.validate() | ||||||
|  |  | ||||||
|  |  | ||||||
|     SummaryLabel { id: summary } |     SummaryLabel { id: summary } | ||||||
| @@ -90,8 +91,6 @@ HFlickableColumnPopup { | |||||||
|             onTextChanged: passwordValid = |             onTextChanged: passwordValid = | ||||||
|                 validateWhileTyping ? verifyPassword(text) : null |                 validateWhileTyping ? verifyPassword(text) : null | ||||||
|  |  | ||||||
|             onAccepted: popup.validate() |  | ||||||
|  |  | ||||||
|             Layout.fillWidth: true |             Layout.fillWidth: true | ||||||
|         } |         } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -51,6 +51,7 @@ HFlickableColumnPopup { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     onOpened: reasonField.item.forceActiveFocus() |     onOpened: reasonField.item.forceActiveFocus() | ||||||
|  |     onKeyboardAccept: popup.remove() | ||||||
|  |  | ||||||
|  |  | ||||||
|     SummaryLabel { |     SummaryLabel { | ||||||
| @@ -80,7 +81,6 @@ HFlickableColumnPopup { | |||||||
|  |  | ||||||
|         HTextField { |         HTextField { | ||||||
|             width: parent.width |             width: parent.width | ||||||
|             onAccepted: popup.remove() |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -48,6 +48,7 @@ HFlickableColumnPopup { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     onOpened: reasonField.item.forceActiveFocus() |     onOpened: reasonField.item.forceActiveFocus() | ||||||
|  |     onKeyboardAccept: popup.remove() | ||||||
|  |  | ||||||
|  |  | ||||||
|     SummaryLabel { |     SummaryLabel { | ||||||
| @@ -70,7 +71,6 @@ HFlickableColumnPopup { | |||||||
|  |  | ||||||
|         HTextField { |         HTextField { | ||||||
|             width: parent.width |             width: parent.width | ||||||
|             onAccepted: popup.remove() |  | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	