112 lines
4.1 KiB
QML
112 lines
4.1 KiB
QML
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
*
|
|
* Copyright (C) 2013 - 2024, nymea GmbH
|
|
* Copyright (C) 2024 - 2025, chargebyte austria GmbH
|
|
*
|
|
* This file is part of nymea-app-energy-overlay.
|
|
*
|
|
* nymea-app-energy-overlay is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* nymea-app-energy-overlay is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
* for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with nymea-app-energy-overlay. If not, see <https://www.gnu.org/licenses/>.
|
|
*
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
import QtQuick
|
|
import QtQuick.Templates as T
|
|
import QtQuick.Controls
|
|
import QtQuick.Controls.impl
|
|
import QtQuick.Controls.Material
|
|
import QtQuick.Controls.Material.impl
|
|
|
|
import Nymea
|
|
|
|
T.Button {
|
|
id: control
|
|
|
|
implicitWidth: Math.max(background ? background.implicitWidth : 0,
|
|
contentItem.implicitWidth + leftPadding + rightPadding)
|
|
implicitHeight: Math.max(background ? background.implicitHeight : 0,
|
|
contentItem.implicitHeight + topPadding + bottomPadding)
|
|
baselineOffset: contentItem.y + contentItem.baselineOffset
|
|
|
|
// external vertical padding is 6 (to increase touch area)
|
|
padding: 12
|
|
leftPadding: padding - 4
|
|
rightPadding: padding - 4
|
|
|
|
Material.elevation: flat ? control.down || control.hovered ? 2 : 0
|
|
: control.down ? 8 : 2
|
|
Material.background: flat ? "transparent" : undefined
|
|
|
|
contentItem: Text {
|
|
text: control.text
|
|
font.bold: control.font.bold
|
|
font.capitalization: Font.AllUppercase
|
|
font.family: control.font.family
|
|
font.hintingPreference: control.font.hintingPreference
|
|
font.italic: control.font.italic
|
|
font.letterSpacing: 2
|
|
font.overline: control.font.overline
|
|
font.pixelSize: Style.smallFont.pixelSize
|
|
font.weight: Font.Bold
|
|
color: Style.foregroundColor
|
|
horizontalAlignment: Text.AlignHCenter
|
|
verticalAlignment: Text.AlignVCenter
|
|
elide: Text.ElideRight
|
|
}
|
|
|
|
// TODO: Add a proper ripple/ink effect for mouse/touch input and focus state
|
|
background: Rectangle {
|
|
implicitWidth: 64
|
|
implicitHeight: Style.smallDelegateHeight
|
|
|
|
// external vertical padding is 6 (to increase touch area)
|
|
y: 6
|
|
width: parent.width
|
|
height: parent.height - 12
|
|
radius: Style.cornerRadius
|
|
color: !control.enabled ? control.Material.buttonDisabledColor :
|
|
control.highlighted ? control.Material.highlightedButtonColor : "white"
|
|
|
|
PaddedRectangle {
|
|
y: parent.height - 4
|
|
width: parent.width
|
|
height: 4
|
|
radius: 2
|
|
topPadding: -2
|
|
clip: true
|
|
visible: control.checkable && (!control.highlighted || control.flat)
|
|
color: control.checked && control.enabled ? control.Material.accentColor : control.Material.secondaryTextColor
|
|
}
|
|
|
|
// The layer is disabled when the button color is transparent so you can do
|
|
// Material.background: "transparent" and get a proper flat button without needing
|
|
// to set Material.elevation as well
|
|
layer.enabled: control.enabled && control.Material.buttonColor.a > 0
|
|
layer.effect: ElevationEffect {
|
|
elevation: control.Material.elevation
|
|
}
|
|
|
|
Ripple {
|
|
clipRadius: 2
|
|
width: parent.width
|
|
height: parent.height
|
|
pressed: control.pressed
|
|
anchor: control
|
|
active: control.down || control.visualFocus || control.hovered
|
|
color: control.Material.rippleColor
|
|
}
|
|
}
|
|
}
|