~unity-team/unity8/launcher-tooltips

« back to all changes in this revision

Viewing changes to qml/Dash/CardTool.qml

  • Committer: Andrea Azzarone
  • Date: 2016-11-24 11:28:23 UTC
  • mfrom: (2600.3.96 unity8)
  • Revision ID: azzaronea@gmail.com-20161124112823-2uwlc5bc28zs0ysg
Merge with trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    property real viewWidth
43
43
 
44
44
    /*!
45
 
     \brief Scaling factor of selected Carousel item.
46
 
     */
47
 
    readonly property real carouselSelectedItemScaleFactor: 1.38  // XXX assuming 1.38 carousel scaling factor for cards
48
 
 
49
 
    /*!
50
45
     \brief Template supplied for the category.
51
46
     */
52
47
    property var template
57
52
    property var components
58
53
 
59
54
    /*!
 
55
     \brief The Scope this cardTool is representing
 
56
     */
 
57
    property string scopeId
 
58
 
 
59
    /*!
 
60
     \brief The Scope category this cardTool is representing
 
61
     */
 
62
    property string categoryId
 
63
 
 
64
    /*!
 
65
     \brief Scaling factor of selected Carousel item.
 
66
     */
 
67
    readonly property real carouselSelectedItemScaleFactor: 1.38  // XXX assuming 1.38 carousel scaling factor for cards
 
68
 
 
69
    /*!
60
70
     \brief The category layout for this card tool.
61
71
     */
62
 
    property string categoryLayout: {
 
72
    readonly property string categoryLayout: {
63
73
        var layout = template["category-layout"];
64
74
 
65
75
        // carousel fallback mode to grid
67
77
        return layout;
68
78
    }
69
79
 
 
80
    readonly property bool isAppLikeScope: scopeId === "clickscope" || scopeId === "libertine-scope.ubuntu_libertine-scope"
 
81
    readonly property bool isAppLikeScopeAppCategory: ((scopeId === "clickscope" && (categoryId === "predefined" || categoryId === "local"))
 
82
                                                      || (scopeId === "libertine-scope.ubuntu_libertine-scope" && categoryId !== "hint"))
70
83
 
71
 
    // Not readonly because gets overwritten from GenericScopeView in some cases
72
 
    property string artShapeStyle: categoryLayout === "carousel" ? "shadow" : "inset"
 
84
    readonly property string artShapeStyle: {
 
85
        if (isAppLikeScope) {
 
86
            return isAppLikeScopeAppCategory ? "icon" : "flat";
 
87
        } else {
 
88
            return categoryLayout === "carousel" ? "shadow" : "flat"
 
89
        }
 
90
    }
73
91
 
74
92
    // FIXME ? This seems like it should not be needed, but on Qt 5.4 + phone
75
93
    // we are doing unneeded calls to getCardComponent with artShapeStyle and categoryLayout being empty
90
108
    height: 0
91
109
    clip: true
92
110
 
 
111
    // We have 3 view "widths"
 
112
    //   narrow <= 45gu
 
113
    //   normal
 
114
    //   wide >= 70gu
 
115
    readonly property bool isWideView: viewWidth >= units.gu(70)
 
116
    readonly property bool isNarrowView: viewWidth <= units.gu(45)
 
117
 
93
118
    /*!
94
119
     type:real \brief Width to be enforced on the card in this configuration.
95
120
 
96
121
     If -1, should use implicit width of the actual card.
97
122
     */
98
 
    property real cardWidth: {
 
123
    readonly property real cardWidth: {
 
124
        if (isAppLikeScopeAppCategory) {
 
125
            if (!isNarrowView) {
 
126
                if (isWideView) {
 
127
                    return units.gu(11);
 
128
                } else {
 
129
                    return units.gu(10);
 
130
                }
 
131
            } else {
 
132
                return units.gu(12);
 
133
            }
 
134
        }
 
135
 
99
136
        switch (categoryLayout) {
100
137
            case "grid":
101
138
            case "vertical-journal":
103
140
                if (template["card-layout"] === "horizontal") size = "large";
104
141
                switch (size) {
105
142
                    case "small": {
106
 
                        if (viewWidth <= units.gu(45)) return units.gu(12);
 
143
                        if (isNarrowView) return units.gu(12);
107
144
                        else return units.gu(14);
108
145
                    }
109
146
                    case "large": {
110
 
                        if (viewWidth >= units.gu(70)) return units.gu(42);
 
147
                        if (isWideView) return units.gu(42);
111
148
                        else return viewWidth - units.gu(2);
112
149
                    }
113
150
                }
114
 
                if (viewWidth <= units.gu(45)) return units.gu(18);
115
 
                else if (viewWidth >= units.gu(70)) return units.gu(20);
 
151
                if (isNarrowView) return units.gu(18);
 
152
                else if (isWideView) return units.gu(20);
116
153
                else return units.gu(23);
117
154
            case "carousel":
118
155
            case "horizontal-list":
152
189
     type:real \brief Height of the card's header.
153
190
    */
154
191
    readonly property int headerHeight: cardLoader.item ? cardLoader.item.headerHeight : 0
155
 
    property size artShapeSize: cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
 
192
 
 
193
    readonly property size artShapeSize: {
 
194
        if (isAppLikeScopeAppCategory) {
 
195
            return Qt.size(units.gu(8), units.gu(7.5));
 
196
        } else {
 
197
            return cardLoader.item ? cardLoader.item.artShapeSize : Qt.size(0, 0)
 
198
        }
 
199
    }
156
200
 
157
201
    QtObject {
158
202
        id: carouselTool
159
203
 
160
 
        property real minimumTileWidth: {
 
204
        readonly property real minimumTileWidth: {
161
205
            if (cardTool.viewWidth === undefined) return undefined;
162
206
            if (cardTool.viewWidth <= units.gu(40)) return units.gu(18);
163
207
            if (cardTool.viewWidth >= units.gu(128)) return units.gu(26);
166
210
 
167
211
        readonly property real pathItemCount: 4.8457 /// (848 / 175) reference values
168
212
 
169
 
        property real realPathItemCount: {
 
213
        readonly property real realPathItemCount: {
170
214
            var scaledMinimumTileWidth = minimumTileWidth / cardTool.carouselSelectedItemScaleFactor;
171
215
            var tileWidth = Math.max(cardTool.viewWidth / pathItemCount, scaledMinimumTileWidth);
172
216
            return Math.min(cardTool.viewWidth / tileWidth, pathItemCount);