Debian Codegraph @

rc/qml/GalleryApplication.qml

raw
1 /*
2 * Copyright (C) 2011-2015 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 version 3 as
6 * published by the Free Software Foundation.
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 * Authors:
17 * Jim Nelson <[email protected]>
18 * Lucas Beeler <[email protected]>
19 * Charles Lindsay <[email protected]
20 */
21
22 import QtQuick 2.9
23 import QtQuick.Window 2.2
24 import "../js/Gallery.js" as Gallery
25 import Lomiri.Components 1.3 // Necessary to make [email protected] images load
26
27 Item {
28 id: application
29
30 // readonly
31 property bool isPortrait: (height > width)
32
33 property bool automaticOrientation: true
34
35 // Store current requested transfer
36 property var transfer: null
37
38 /// Indicates if the backend is loaded and the UI can be shown
39 property bool allLoaded: false
40
41 // Big list of form factor-specific values. 'default' is used if the key
42 // can't be found under any other form_factor (otherwise, form_factors should
43 // match the FORM_FACTOR values passed from main.cpp). Just add Portrait to
44 // the end of a key to make it portrait-mode specific.
45 property var deviceSpecifics: {
46 'default': {
47 // Size of thumbnails in album overview.
48 albumThumbnailWidth: units.gu(17),
49 albumThumbnailHeight: units.gu(20),
50
51 // Whitespace around photos in album overview.
52 albumGridTopMargin: units.gu(1), // Plus half of albumGridGutterHeight.
53 albumGridLeftMargin: units.gu(1), // Plus half of albumGridGutterWidth.
54 albumGridRightMargin: units.gu(1), // Plus half of albumGridGutterWidth.
55 albumGridGutterWidth: units.gu(2),
56 albumGridGutterHeight: units.gu(2),
57
58 // Whitespace around photos on album pages in the album viewer.
59 albumPageTopMargin: units.gu(2),
60 albumPageBottomMargin: units.gu(2),
61 albumPageGutterMargin: units.gu(1), // Between spine and photo.
62 albumPageGutterMarginPortrait: units.gu(2),
63 albumPageOuterMargin: units.gu(2), // Between opposite edge and photo.
64 albumPageInsideMargin: units.gu(2), // Between photos on one page.
65
66 // Whitespace around photos on album pages in preview thumbnails.
67 albumPreviewTopMargin: units.gu(1),
68 albumPreviewBottomMargin: units.gu(1),
69 albumPreviewGutterMargin: units.gu(1), // Between spine and photo.
70 albumPreviewOuterMargin: units.gu(1), // Between opposite edge and photo.
71 albumPreviewInsideMargin: units.gu(1), // Between photos on one page.
72 },
73
74 'phone': {
75 },
76
77 'tablet': {
78 // Size of thumbnails in album overview.
79 albumThumbnailWidth: units.gu(25),
80 albumThumbnailHeight: units.gu(30),
81
82 // Whitespace around photos in album overview.
83 albumGridTopMargin: units.gu(1), // Plus half of albumGridGutterHeight.
84 albumGridLeftMargin: units.gu(1), // Plus half of albumGridGutterWidth.
85 albumGridRightMargin: units.gu(1), // Plus half of albumGridGutterWidth.
86 albumGridGutterWidth: units.gu(3),
87 albumGridGutterHeight: units.gu(3),
88
89 // Whitespace around photos on album pages in the album viewer.
90 albumPageTopMargin: units.gu(2),
91 albumPageBottomMargin: units.gu(2),
92 albumPageGutterMargin: units.gu(1), // Between spine and photo.
93 albumPageGutterMarginPortrait: units.gu(2),
94 albumPageOuterMargin: units.gu(2), // Between opposite edge and photo.
95 albumPageInsideMargin: units.gu(2), // Between photos on one page.
96
97 // Whitespace around photos on album pages in preview thumbnails.
98 albumPreviewTopMargin: units.gu(1.5),
99 albumPreviewBottomMargin: units.gu(1.5),
100 albumPreviewGutterMargin: units.gu(2.5), // Between spine and photo.
101 albumPreviewOuterMargin: units.gu(2.5), // Between opposite edge and photo.
102 albumPreviewInsideMargin: units.gu(1.5), // Between photos on one page.
103 },
104 };
105
106 function getDeviceSpecific(key, form_factor, is_portrait) {
107 if (is_portrait === undefined)
108 is_portrait = isPortrait; // From GalleryApplication.
109
110 if (!form_factor)
111 form_factor = FORM_FACTOR; // From C++.
112 if (form_factor === 'sidebar')
113 form_factor = 'phone'; // Equivalent; saves typing above.
114 if (deviceSpecifics[form_factor] === undefined) {
115 if (Screen.primaryOrientation === Qt.LandscapeOrientation)
116 form_factor = 'tablet';
117 else
118 form_factor = 'default';
119 }
120
121 var portrait_key = key + 'Portrait';
122 if (is_portrait && deviceSpecifics[form_factor][portrait_key] !== undefined)
123 return deviceSpecifics[form_factor][portrait_key];
124 if (is_portrait && deviceSpecifics['default'][portrait_key] !== undefined)
125 return deviceSpecifics['default'][portrait_key];
126
127 if (deviceSpecifics[form_factor][key] !== undefined)
128 return deviceSpecifics[form_factor][key];
129 if (deviceSpecifics['default'][key] !== undefined)
130 return deviceSpecifics['default'][key];
131
132 console.debug("Invalid key '" + key + "' passed to getDeviceSpecific()");
133 return undefined;
134 }
135
136 // units.gu(), but for font point sizes.
137 function pointUnits(amt) {
138 // 1.6 is a hacky fudge-factor for now.
139 return Math.round(1.6 * amt);
140 }
141
142 function onLoaded() {
143 allLoaded = true;
144 }
145
146 function swapDimensions() {
147 var temp = width;
148 width = height;
149 height = temp;
150 }
151
152 function setFullScreenAppMode(fullScreen) {
153 APP.fullScreenAppMode = fullScreen;
154 }
155
156 function setFullScreenUserMode(fullScreen) {
157 APP.fullScreenUserMode = fullScreen;
158 }
159
160 width: units.gu(DEVICE_WIDTH)
161 height: units.gu(DEVICE_HEIGHT)
162
163 focus: true
164 Keys.onPressed: {
165 // Key presses only makes sense on Desktop
166 if (!Gallery.isDesktop()) {
167 return;
168 }
169
170 switch(event.key) {
171 case Qt.Key_F11:
172 setFullScreenUserMode(!APP.fullScreenUserMode);
173 break;
174
175 case Qt.Key_Escape:
176 setFullScreenUserMode(false);
177 break;
178
179 case Qt.Key_L:
180 if (isPortrait) {
181 swapDimensions();
182 }
183 break;
184
185 case Qt.Key_P:
186 if (!isPortrait) {
187 swapDimensions();
188 }
189 break;
190
191 default:
192 break;
193 }
194 }
195
196 Loader {
197 id: mainScreenLoader
198 anchors.fill: parent
199 visible: status === Loader.Ready
200 source: APP.pickModeEnabled ? Qt.resolvedUrl("PickerScreen.qml") : Qt.resolvedUrl("MainScreen.qml")
201 }
202 }