2 * Copyright 2014 Canonical Ltd.
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.
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.
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/>.
19 import Ubuntu.Components 1.3
21 /*! \brief Helper for processing scope customization options.
23 It will take the customizations object passed by the scope and
24 process it to provide the scope UI with data such as colors or
29 /// Style object passed from the scope
30 property var style: Object()
32 /// Color used for text and symbolic icons
33 readonly property color foreground: "foreground-color" in style ? style["foreground-color"] : d.defaultDark
35 /// Luminance of the foreground color
36 readonly property real foregroundLuminance: foreground ? Style.luminance(foreground) : Style.luminance(d.defaultDark)
38 /// Color used for the overall background
39 readonly property color background: "background-color" in style ? style["background-color"] : "#00f5f5f5"
41 /// Luminance of the background color
42 readonly property real backgroundLuminance: background ? Style.luminance(background) : Style.luminance(d.defaultLight)
44 /*! \brief Get the most contrasting available color based on luminance
46 * If background color is transparent, theme provided colors are taken into account
48 function getTextColor(luminance) {
49 if (Math.abs(foregroundLuminance - luminance) >
50 Math.abs(d.opaqueBackgroundLuminance - luminance)) {
53 return d.opaqueBackground;
57 /// Source of the logo image for the header
58 readonly property url headerLogo: "logo" in d.headerStyle ? d.headerStyle["logo"] : ""
60 /// Background style for the header
61 readonly property url headerBackground: "background" in d.headerStyle ? d.headerStyle["background"] : "color:///#f5f5f5"
63 /// Foreground color for the header
64 readonly property color headerForeground: "foreground-color" in d.headerStyle ? d.headerStyle["foreground-color"] : foreground
66 /// Color of the header divider
67 readonly property color headerDividerColor: "divider-color" in d.headerStyle ? d.headerStyle["divider-color"] : "#e0e0e0"
69 /// Background style for the navigation
70 readonly property url navigationBackground: "navigation-background" in d.headerStyle ? d.headerStyle["navigation-background"] : "color:///#f5f5f5"
72 /// Color of the primary preview button
73 readonly property color previewButtonColor: "preview-button-color" in style ? style["preview-button-color"] : UbuntuColors.orange
76 property var d: QtObject {
77 // FIXME: should be taken from the theme
78 readonly property color defaultLight: "white"
79 readonly property color defaultDark: UbuntuColors.darkGrey
80 readonly property real defaultLightLuminance: Style.luminance(defaultLight)
81 readonly property real defaultDarkLuminance: Style.luminance(defaultDark)
83 readonly property color opaqueBackground: {
86 (Math.abs(foregroundLuminance - defaultLightLuminance) >
87 Math.abs(foregroundLuminance - defaultDarkLuminance)) ?
88 defaultLight : defaultDark
90 readonly property real opaqueBackgroundLuminance: Style.luminance(opaqueBackground)
92 readonly property var headerStyle: "page-header" in style ? style["page-header"] : { }