Lomiri
Loading...
Searching...
No Matches
MainViewStyle.qml
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16import QtQuick 2.15
17import QtQml 2.15
18import Lomiri.Components 1.3
19
20// FIXME: copied with slight modifications from Lomiri UI Toolkit's Ambiance's theme
21Item {
22 anchors.fill: parent
23 z: -1
24 id: mainViewStyle
25
26 property var theme
27
28 /*!
29 Color of the header's background.
30
31 \sa backgroundColor, footerColor
32 */
33 property color headerColor: styledItem.headerColor
34
35 /*!
36 Color of the background.
37
38 The background is usually a single color. However if \l headerColor
39 or \l footerColor are set then a gradient of colors will be drawn.
40
41 \sa footerColor, headerColor
42 */
43 property color backgroundColor: styledItem.backgroundColor
44
45 /*!
46 Color of the footer's background.
47
48 \sa backgroundColor, headerColor
49 */
50 property color footerColor: styledItem.footerColor
51
52 Gradient {
53 id: backgroundGradient
54 GradientStop { position: 0.0; color: mainViewStyle.headerColor }
55 GradientStop { position: 0.83; color: mainViewStyle.backgroundColor }
56 GradientStop { position: 1.0; color: mainViewStyle.footerColor }
57 }
58
59 Rectangle {
60 id: backgroundColor
61 anchors.fill: parent
62 color: mainViewStyle.backgroundColor
63 gradient: internals.isGradient ? backgroundGradient : null
64 }
65
66 QtObject {
67 id: internals
68 property bool isGradient: mainViewStyle.backgroundColor != mainViewStyle.headerColor ||
69 mainViewStyle.backgroundColor != mainViewStyle.footerColor
70
71 /*
72 As we don't know the order the property bindings and onXXXChanged signals are evaluated
73 we should rely only on one property when changing the theme to avoid intermediate
74 theme changes due to properties being evaluated separately.
75
76 Qt bug: https://bugreports.qt-project.org/browse/QTBUG-11712
77 */
78 property string theme: (ColorUtils.luminance(styledItem.backgroundColor) >= 0.85) ? "Ambiance" : "SuruDark"
79 }
80
81 // automatically select the appropriate theme depending on the background colors
82 Binding {
83 target: theme
84 restoreMode: Binding.RestoreBinding
85 property: "name"
86 value: internals.theme
87 when: internals.theme !== ""
88 }
89}