summaryrefslogtreecommitdiffstats
path: root/resources/qml/components/FlatButton.qml
blob: 0636bc0401ccf0116e50b3ac3f29f9a93b1fad1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-FileCopyrightText: Nheko Contributors
//
// SPDX-License-Identifier: GPL-3.0-or-later

import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import QtQuick.Effects
import im.nheko

// FIXME(Nico): Don't use hardcoded colors.
Button {
    id: control

    implicitHeight: Math.ceil(control.contentItem.implicitHeight * 1.70)
    implicitWidth: Math.ceil(control.contentItem.implicitWidth + control.contentItem.implicitHeight)
    hoverEnabled: true

    property string iconImage: ""

    MultiEffect {
        anchors.fill: control.background
        shadowHorizontalOffset: 3
        shadowVerticalOffset: 3
        shadowBlur: 8
        shadowEnabled: true
        shadowColor: "#80000000"
        source: control.background
    }

    contentItem: RowLayout {
        spacing: 0
        anchors.centerIn: parent
        Image {
            Layout.leftMargin: Nheko.paddingMedium
            Layout.alignment: Qt.AlignVCenter | Qt.AlignHCenter
            Layout.preferredHeight: fontMetrics.font.pixelSize * 1.5
            Layout.preferredWidth:  fontMetrics.font.pixelSize * 1.5
            visible: !!iconImage
            source: iconImage
        }

        Text {
            Layout.alignment: Qt.AlignHCenter
            text: control.text
            //font: control.font
            font.capitalization: Font.AllUppercase
            font.pointSize: Math.ceil(fontMetrics.font.pointSize * 1.5)
            //font.capitalization: Font.AllUppercase
            color: palette.light
            horizontalAlignment: Text.AlignHCenter
            verticalAlignment: Text.AlignVCenter
            elide: Text.ElideRight
        }
    }

    background: Rectangle {
        //height: control.contentItem.implicitHeight * 2
        //width: control.contentItem.implicitWidth * 2
        radius: height / 8
        color: Qt.lighter(palette.dark, control.down ? 1.4 : (control.hovered ? 1.2 : 1))
    }

}