Unity 8
 All Classes Functions Properties
ScopeStyle.qml
1 /*
2  * Copyright 2014 Canonical Ltd.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU 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 General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 import QtQuick 2.2
18 
26 QtObject {
28  property var style: Object()
29 
30 
34  function luminance(color) {
35  return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
36  }
37 
39  readonly property color foreground: "foreground-color" in style ? style["foreground-color"] : d.defaultDark
40 
42  readonly property color background: "background-color" in style ? style["background-color"] : "transparent"
43 
48  readonly property real threshold: background.a !== 1.0 ? d.foregroundLuminance : (d.foregroundLuminance + d.backgroundLuminance) / 2
49 
55  readonly property color light: {
56  if (background.a !== 1.0) return d.foregroundLuminance > d.defaultLightLuminance ? foreground : d.defaultLight;
57  return d.foregroundLuminance > d.backgroundLuminance ? foreground : background;
58  }
59 
65  readonly property color dark: {
66  if (background.a !== 1.0) return d.foregroundLuminance < d.defaultDarkLuminance ? foreground : d.defaultDark;
67  return d.foregroundLuminance < d.backgroundLuminance ? foreground : background;
68  }
69 
71  readonly property url headerLogo: "logo" in d.headerStyle ? d.headerStyle["logo"] : ""
72 
74  property var d: QtObject {
75  readonly property real foregroundLuminance: luminance(foreground)
76  readonly property real backgroundLuminance: luminance(background)
77 
78  // FIXME: should be taken from the theme
79  readonly property color defaultLight: "white"
80  readonly property color defaultDark: "grey"
81  readonly property real defaultLightLuminance: luminance(defaultLight)
82  readonly property real defaultDarkLuminance: luminance(defaultDark)
83 
84  readonly property var headerStyle: "page-header" in style ? style["page-header"] : { }
85  }
87 }