Unity 8
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.4
18 import Utils 0.1
19 import Ubuntu.Components 1.3
20 
21 /*! \brief Helper for processing scope customization options.
22 
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
25  image paths.
26  */
27 
28 QtObject {
29  /// Style object passed from the scope
30  property var style: Object()
31 
32  /// Color used for text and symbolic icons
33  readonly property color foreground: "foreground-color" in style ? style["foreground-color"] : d.defaultDark
34 
35  /// Luminance of the foreground color
36  readonly property real foregroundLuminance: foreground ? Style.luminance(foreground) : Style.luminance(d.defaultDark)
37 
38  /// Color used for the overall background
39  readonly property color background: "background-color" in style ? style["background-color"] : "#00f5f5f5"
40 
41  /// Luminance of the background color
42  readonly property real backgroundLuminance: background ? Style.luminance(background) : Style.luminance(d.defaultLight)
43 
44  /*! \brief Get the most contrasting available color based on luminance
45  *
46  * If background color is transparent, theme provided colors are taken into account
47  */
48  function getTextColor(luminance) {
49  if (Math.abs(foregroundLuminance - luminance) >
50  Math.abs(d.opaqueBackgroundLuminance - luminance)) {
51  return foreground;
52  } else {
53  return d.opaqueBackground;
54  }
55  }
56 
57  /// Source of the logo image for the header
58  readonly property url headerLogo: "logo" in d.headerStyle ? d.headerStyle["logo"] : ""
59 
60  /// Background style for the header
61  readonly property url headerBackground: "background" in d.headerStyle ? d.headerStyle["background"] : "color:///#f5f5f5"
62 
63  /// Foreground color for the header
64  readonly property color headerForeground: "foreground-color" in d.headerStyle ? d.headerStyle["foreground-color"] : foreground
65 
66  /// Color of the header divider
67  readonly property color headerDividerColor: "divider-color" in d.headerStyle ? d.headerStyle["divider-color"] : "#e0e0e0"
68 
69  /// Background style for the navigation
70  readonly property url navigationBackground: "navigation-background" in d.headerStyle ? d.headerStyle["navigation-background"] : "color:///#f5f5f5"
71 
72  /// Color of the primary preview button
73  readonly property color previewButtonColor: "preview-button-color" in style ? style["preview-button-color"] : UbuntuColors.orange
74 
75  //! @cond
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)
82 
83  readonly property color opaqueBackground: {
84  background.a > 0 ?
85  background :
86  (Math.abs(foregroundLuminance - defaultLightLuminance) >
87  Math.abs(foregroundLuminance - defaultDarkLuminance)) ?
88  defaultLight : defaultDark
89  }
90  readonly property real opaqueBackgroundLuminance: Style.luminance(opaqueBackground)
91 
92  readonly property var headerStyle: "page-header" in style ? style["page-header"] : { }
93  }
94  //! @endcond
95 }