qtdoc/examples/demos/coffee/CustomButton.qml

55 lines
2.0 KiB
QML
Raw Normal View History

// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Effects
AbstractButton {
// Height, width and any other size related properties containing odd looking float or other dividers
// that do not seem to have any logical origin are just arbitrary and based on original design
// and/or personal preference on what looks nice.
id: button
property string buttonText: ""
property bool showIcon: true
property string buttonColor: "grey"
states: State {
name: "pressed"; when: button.pressed
PropertyChanges { target: rectangle; scale: 0.9 }
}
transitions: Transition {
NumberAnimation { properties: "scale"; duration: 10; easing.type: Easing.InOutQuad }
}
contentItem: Rectangle {
id: rectangle
border.width: 1
Fix Coffee Machine clipping UI elements on lower resolution displays Reason for these changes is that it was discovered that some of the UI elements of the re-designed Coffee Machine example did overflow the target device display with lower than ~1080x1920 display resolution. Added states to coffee cards that will scale the cards and their content down if target device screen resolution is lower than set limit. Added state to home component where text components will be scaled down in target device screen resolution is lower than set limit. Added some colors to Colors.qml to remove hardcoded color values. Added states to sliders in Settings.qml and in CustomSlider.qml that will scale them down if target device screen resolution is lower than set limit. Scaled the custom buttons heights down a bit throughout the app to make them fit on screen. Added state to progress page that will scale the caption text down if target device screen resotion is lower than set limit and set minimum width and height to dialog component so that the text will not overflow its container. Added states to ready page that will reduce the row spacing of the grid component and scale the caption font size down if target device screen resolution is lower than the set limit. Tested successfully with Android emulators with screen resolution ranging from 320x480 to 1440x3120. Removed multiple property changes regarding text sizes in Settings.qml and replaced them by binding the text objects font size to a new property int that will be modified through state. Added the missing when condition in state change to change the font size in Setting.qml. Renamed ambiguous id's * Removed unused property aliases * Re-applied missing qdoc snippet tags to Settings.qml which were removed by mistake. This should fix one of the qdoc warnings in CI. Fixes: QTBUG-116402 Pick-to: 6.7 6.6 Change-Id: I2524be43f943494f5ab7b2689b222a977996dac6 Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
2023-12-11 07:05:43 +00:00
border.color: Colors.border
radius: 10
anchors.fill: parent
gradient: if (buttonColor == "grey" && Colors.currentTheme == Colors.dark) {
Colors.darkButtonGradient
} else if (buttonColor == "grey" && Colors.currentTheme == Colors.light) {
Colors.lightButtonGradient
} else {
Colors.greenButtonGradient
}
Row {
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Text {
text: buttonText
color: (buttonColor == "green") ? Colors.dark.textColor : Colors.currentTheme.textColor
font.pixelSize: 18
font.weight: 700
rightPadding: 8
}
Image {
id: icon
visible: showIcon
source: (Colors.currentTheme == Colors.dark) ? "./images/icons/keyboard_backspace_white_right.svg" : "./images/icons/keyboard_backspace_black_right.svg"
}
}
}
}