on 2a10ef2 help sign in
unity8/plugins/Dash/ScopeStyle.qml
102 lines 4.4 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.4
18import Utils 0.1
19import GSettings 1.0
20import Ubuntu.Components 1.3
21import Ubuntu.Components.Themes 1.3
23/*! \brief Helper for processing scope customization options.
25 It will take the customizations object passed by the scope and
26 process it to provide the scope UI with data such as colors or
27 image paths.
28 */
30QtObject {
32 property var gsettings: GSettings {
33 schema.id: "com.ubuntu.touch.system-settings"
34 }
36 /// Style object passed from the scope
37 property var style: Object()
39 /// Color used for text and symbolic icons
40 property color foreground: gsettings.dashBackground ? "white" : ("foreground-color" in style ? style["foreground-color"] : d.defaultDark)
42 /// Luminance of the foreground color
43 readonly property real foregroundLuminance: foreground ? Style.luminance(foreground) : Style.luminance(d.defaultDark)
45 /// Color used for the overall background
46 property color background: "background-color" in style ? style["background-color"] : gsettings.dashBackground ? "transparent" : "#00f5f5f5"
48 /// Luminance of the background color
49 readonly property real backgroundLuminance: background ? Style.luminance(background) : Style.luminance(d.defaultLight)
51 /*! \brief Get the most contrasting available color based on luminance
52 *
53 * If background color is transparent, theme provided colors are taken into account
54 */
55 function getTextColor(luminance) {
56 if (Math.abs(foregroundLuminance - luminance) >
57 Math.abs(d.opaqueBackgroundLuminance - luminance)) {
58 return foreground;
59 } else {
60 return d.opaqueBackground;
61 }
62 }
64 /// Source of the logo image for the header
65 readonly property url headerLogo: "logo" in d.headerStyle ? d.headerStyle["logo"] : ""
67 /// Background style for the header
68 property url headerBackground: "background" in d.headerStyle ? d.headerStyle["background"] : gsettings.dashBackground ? "color:///transparent" : "color:///#ffffff"
70 /// Foreground color for the header
71 property color headerForeground: "foreground-color" in d.headerStyle ? d.headerStyle["foreground-color"] : gsettings.dashBackground ? "white" : foreground
73 /// Color of the header divider
74 property color headerDividerColor: "divider-color" in d.headerStyle ? d.headerStyle["divider-color"] : gsettings.dashBackground ? "transparent" : "#e0e0e0"
76 /// Background style for the navigation
77 property url navigationBackground: "navigation-background" in d.headerStyle ? d.headerStyle["navigation-background"] : gsettings.dashBackground ? "color:///white" : "color:///#f5f5f5"
79 /// Color of the primary preview button
80 readonly property color previewButtonColor: "preview-button-color" in style ? style["preview-button-color"] : theme.palette.normal.positive
82 //! @cond
83 property var d: QtObject {
84 // FIXME: should be taken from the theme
85 readonly property color defaultLight: "white"
86 readonly property color defaultDark: UbuntuColors.darkGrey
87 readonly property real defaultLightLuminance: Style.luminance(defaultLight)
88 readonly property real defaultDarkLuminance: Style.luminance(defaultDark)
90 readonly property color opaqueBackground: {
91 background.a > 0 ?
92 background :
93 (Math.abs(foregroundLuminance - defaultLightLuminance) >
94 Math.abs(foregroundLuminance - defaultDarkLuminance)) ?
95 defaultLight : defaultDark
96 }
97 readonly property real opaqueBackgroundLuminance: Style.luminance(opaqueBackground)
99 readonly property var headerStyle: "page-header" in style ? style["page-header"] : { }
100 }
101 //! @endcond