on 1809d71 help sign in
unity8/plugins/Dash/ScopeStyle.qml
96 lines 4.0 kB history raw
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 */
17import QtQuick 2.2
19/*! \brief Helper for processing scope customization options.
21 It will take the customizations object passed by the scope and
22 process it to provide the scope UI with data such as colors or
23 image paths.
24 */
26QtObject {
27 /// Style object passed from the scope
28 property var style: Object()
30 /*! \brief Calculate luminance of the passed color
32 \note If not fully opaque, luminance is dependant on blending.
33 */
34 function luminance(color) {
35 return 0.2126 * color.r + 0.7152 * color.g + 0.0722 * color.b;
36 }
38 /// Color used for text and symbolic icons
39 readonly property color foreground: "foreground-color" in style ? style["foreground-color"] : d.defaultDark
41 /// Luminance of the foreground color
42 readonly property real foregroundLuminance: foreground ? luminance(foreground) : d.defaultForegroundLuminance
44 /// Color used for the overall background
45 readonly property color background: "background-color" in style ? style["background-color"] : "transparent"
47 /// Luminance of the foreground color
48 readonly property real backgroundLuminance: background ? luminance(background) : d.defaultBackgroundLuminance
50 /*! \brief Luminance threshold for switching between fore and background color
52 \note If background colour is not fully opaque, it's not taken into account.
53 */
54 readonly property real threshold: background.a !== 1.0 ? foregroundLuminance : (foregroundLuminance + backgroundLuminance) / 2
56 /*! \brief The lighter of foreground and background colors
58 \note If background color is not fully opaque, it's not taken into account
59 and defaults to the theme-provided light color.
60 */
61 readonly property color light: {
62 if (background.a !== 1.0) return foregroundLuminance > d.defaultLightLuminance ? foreground : d.defaultLight;
63 return foregroundLuminance > backgroundLuminance ? foreground : background;
64 }
66 /*! \brief The darker of foreground and background colors
68 \note If background color is not fully opaque, it's not taken into account
69 and defaults to the theme-provided dark color.
70 */
71 readonly property color dark: {
72 if (background.a !== 1.0) return foregroundLuminance < d.defaultDarkLuminance ? foreground : d.defaultDark;
73 return foregroundLuminance < backgroundLuminance ? foreground : background;
74 }
76 /// Source of the logo image for the header
77 readonly property url headerLogo: "logo" in d.headerStyle ? d.headerStyle["logo"] : ""
79 /// Background style for the header
80 readonly property url headerBackground: "background" in d.headerStyle ? d.headerStyle["background"] : ""
82 /// Foreground color for the header
83 readonly property color headerForeground: "foreground-color" in d.headerStyle ? d.headerStyle["foreground-color"] : foreground
85 //! @cond
86 property var d: QtObject {
87 // FIXME: should be taken from the theme
88 readonly property color defaultLight: "white"
89 readonly property color defaultDark: "grey"
90 readonly property real defaultLightLuminance: luminance(defaultLight)
91 readonly property real defaultDarkLuminance: luminance(defaultDark)
93 readonly property var headerStyle: "page-header" in style ? style["page-header"] : { }
94 }
95 //! @endcond