Merge lp:~knightrider0xd/openlp/better-slide-scaling into lp:openlp
- better-slide-scaling
- Merge into trunk
Status: | Superseded |
---|---|
Proposed branch: | lp:~knightrider0xd/openlp/better-slide-scaling |
Merge into: | lp:openlp |
Diff against target: |
395 lines (+283/-9) 4 files modified
openlp/core/common/settings.py (+1/-0) openlp/core/ui/advancedtab.py (+12/-0) openlp/core/ui/listpreviewwidget.py (+42/-4) tests/functional/openlp_core_ui/test_listpreviewwidget.py (+228/-5) |
To merge this branch: | bzr merge lp:~knightrider0xd/openlp/better-slide-scaling |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tim Bentley | Needs Fixing | ||
Review via email: mp+289580@code.launchpad.net |
This proposal has been superseded by a proposal from 2016-04-01.
Commit message
Description of the change
Adds the ability to choose a maximum height for non-text slides in the list-preview-widget in slide controllers. See branch description for further details. May require sanity check.
lp:~knightrider0xd/openlp/better-slide-scaling (revision 2630)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
Ian Knight (knightrider0xd) wrote : | # |
Thanks for the feedback. See replies to inline comments.
- 2631. By Ian Knight
-
Corrected comments
- 2632. By Ian Knight
-
Shifted common test code into setup.
Ian Knight (knightrider0xd) wrote : | # |
Shifted common test code into setup function as recommended.
lp:~knightrider0xd/openlp/better-slide-scaling (revision 2632)
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
[SUCCESS] https:/
Tomas Groth (tomasgroth) wrote : | # |
Hi,
Remember to resubmit your merge proposal when it is ready for another review.
And you should probably just leave the branchs status as "development", we use "mature" for the release branches :)
Ian Knight (knightrider0xd) wrote : | # |
Thanks Tomas, I wasn't sure what the procedure was :)
Unmerged revisions
Preview Diff
1 | === modified file 'openlp/core/common/settings.py' |
2 | --- openlp/core/common/settings.py 2016-03-15 21:34:58 +0000 |
3 | +++ openlp/core/common/settings.py 2016-03-23 14:15:11 +0000 |
4 | @@ -121,6 +121,7 @@ |
5 | 'advanced/double click live': False, |
6 | 'advanced/enable exit confirmation': True, |
7 | 'advanced/expand service item': False, |
8 | + 'advanced/slide max height': 0, |
9 | 'advanced/hide mouse': True, |
10 | 'advanced/is portable': False, |
11 | 'advanced/max recent files': 20, |
12 | |
13 | === modified file 'openlp/core/ui/advancedtab.py' |
14 | --- openlp/core/ui/advancedtab.py 2016-01-19 06:52:23 +0000 |
15 | +++ openlp/core/ui/advancedtab.py 2016-03-23 14:15:11 +0000 |
16 | @@ -83,6 +83,13 @@ |
17 | self.expand_service_item_check_box = QtWidgets.QCheckBox(self.ui_group_box) |
18 | self.expand_service_item_check_box.setObjectName('expand_service_item_check_box') |
19 | self.ui_layout.addRow(self.expand_service_item_check_box) |
20 | + self.slide_max_height_label = QtWidgets.QLabel(self.ui_group_box) |
21 | + self.slide_max_height_label.setObjectName('slide_max_height_label') |
22 | + self.slide_max_height_spin_box = QtWidgets.QSpinBox(self.ui_group_box) |
23 | + self.slide_max_height_spin_box.setObjectName('slide_max_height_spin_box') |
24 | + self.slide_max_height_spin_box.setRange(0, 1000) |
25 | + self.slide_max_height_spin_box.setSingleStep(20) |
26 | + self.ui_layout.addRow(self.slide_max_height_label, self.slide_max_height_spin_box) |
27 | self.search_as_type_check_box = QtWidgets.QCheckBox(self.ui_group_box) |
28 | self.search_as_type_check_box.setObjectName('SearchAsType_check_box') |
29 | self.ui_layout.addRow(self.search_as_type_check_box) |
30 | @@ -277,6 +284,9 @@ |
31 | 'Preview items when clicked in Service Manager')) |
32 | self.expand_service_item_check_box.setText(translate('OpenLP.AdvancedTab', |
33 | 'Expand new service items on creation')) |
34 | + self.slide_max_height_label.setText(translate('OpenLP.AdvancedTab', |
35 | + 'Max height for non-text slides\nin slide controller:')) |
36 | + self.slide_max_height_spin_box.setSpecialValueText(translate('OpenLP.AdvancedTab', 'Disabled')) |
37 | self.enable_auto_close_check_box.setText(translate('OpenLP.AdvancedTab', |
38 | 'Enable application exit confirmation')) |
39 | self.service_name_group_box.setTitle(translate('OpenLP.AdvancedTab', 'Default Service Name')) |
40 | @@ -346,6 +356,7 @@ |
41 | self.single_click_preview_check_box.setChecked(settings.value('single click preview')) |
42 | self.single_click_service_preview_check_box.setChecked(settings.value('single click service preview')) |
43 | self.expand_service_item_check_box.setChecked(settings.value('expand service item')) |
44 | + self.slide_max_height_spin_box.setValue(settings.value('slide max height')) |
45 | self.enable_auto_close_check_box.setChecked(settings.value('enable exit confirmation')) |
46 | self.hide_mouse_check_box.setChecked(settings.value('hide mouse')) |
47 | self.service_name_day.setCurrentIndex(settings.value('default service day')) |
48 | @@ -428,6 +439,7 @@ |
49 | settings.setValue('single click preview', self.single_click_preview_check_box.isChecked()) |
50 | settings.setValue('single click service preview', self.single_click_service_preview_check_box.isChecked()) |
51 | settings.setValue('expand service item', self.expand_service_item_check_box.isChecked()) |
52 | + settings.setValue('slide max height', self.slide_max_height_spin_box.value()) |
53 | settings.setValue('enable exit confirmation', self.enable_auto_close_check_box.isChecked()) |
54 | settings.setValue('hide mouse', self.hide_mouse_check_box.isChecked()) |
55 | settings.setValue('alternate rows', self.alternate_rows_check_box.isChecked()) |
56 | |
57 | === modified file 'openlp/core/ui/listpreviewwidget.py' |
58 | --- openlp/core/ui/listpreviewwidget.py 2015-12-31 22:46:06 +0000 |
59 | +++ openlp/core/ui/listpreviewwidget.py 2016-03-23 14:15:11 +0000 |
60 | @@ -26,7 +26,7 @@ |
61 | |
62 | from PyQt5 import QtCore, QtGui, QtWidgets |
63 | |
64 | -from openlp.core.common import RegistryProperties |
65 | +from openlp.core.common import RegistryProperties, Settings |
66 | from openlp.core.lib import ImageSource, ServiceItem |
67 | |
68 | |
69 | @@ -63,6 +63,8 @@ |
70 | # Initialize variables. |
71 | self.service_item = ServiceItem() |
72 | self.screen_ratio = screen_ratio |
73 | + # Connect signals |
74 | + self.verticalHeader().sectionResized.connect(self.row_resized) |
75 | |
76 | def resizeEvent(self, event): |
77 | """ |
78 | @@ -80,12 +82,30 @@ |
79 | # Sort out songs, bibles, etc. |
80 | if self.service_item.is_text(): |
81 | self.resizeRowsToContents() |
82 | + # Sort out image heights. |
83 | else: |
84 | - # Sort out image heights. |
85 | + height = self.viewport().width() // self.screen_ratio |
86 | + max_img_row_height = Settings().value('advanced/slide max height') |
87 | + # Adjust for row height cap if in use. |
88 | + if max_img_row_height > 0 and height > max_img_row_height: |
89 | + height = max_img_row_height |
90 | + # Apply new height to slides |
91 | for frame_number in range(len(self.service_item.get_frames())): |
92 | - height = self.viewport().width() // self.screen_ratio |
93 | self.setRowHeight(frame_number, height) |
94 | |
95 | + def row_resized(self, row, old_height, new_height): |
96 | + """ |
97 | + Will scale non-image slides. |
98 | + """ |
99 | + # Only for non-text slides when row height cap in use |
100 | + if self.service_item.is_text() or Settings().value('advanced/slide max height') <= 0: |
101 | + return |
102 | + # Get and validate label widget containing slide & adjust max width |
103 | + try: |
104 | + self.cellWidget(row, 0).children()[1].setMaximumWidth(new_height * self.screen_ratio) |
105 | + except: |
106 | + return |
107 | + |
108 | def screen_size_changed(self, screen_ratio): |
109 | """ |
110 | This method is called whenever the live screen size changes, which then makes a layout recalculation necessary |
111 | @@ -139,8 +159,26 @@ |
112 | pixmap = QtGui.QPixmap.fromImage(image) |
113 | pixmap.setDevicePixelRatio(label.devicePixelRatio()) |
114 | label.setPixmap(pixmap) |
115 | - self.setCellWidget(frame_number, 0, label) |
116 | slide_height = width // self.screen_ratio |
117 | + # Setup row height cap if in use. |
118 | + max_img_row_height = Settings().value('advanced/slide max height') |
119 | + if max_img_row_height > 0: |
120 | + if slide_height > max_img_row_height: |
121 | + slide_height = max_img_row_height |
122 | + label.setMaximumWidth(max_img_row_height * self.screen_ratio) |
123 | + label.resize(max_img_row_height * self.screen_ratio, max_img_row_height) |
124 | + # Build widget with stretch padding |
125 | + container = QtWidgets.QWidget() |
126 | + hbox = QtWidgets.QHBoxLayout() |
127 | + hbox.setContentsMargins(0, 0, 0, 0) |
128 | + hbox.addWidget(label, stretch=1) |
129 | + hbox.addStretch(0) |
130 | + container.setLayout(hbox) |
131 | + # Add to table |
132 | + self.setCellWidget(frame_number, 0, container) |
133 | + else: |
134 | + # Add to table |
135 | + self.setCellWidget(frame_number, 0, label) |
136 | row += 1 |
137 | text.append(str(row)) |
138 | self.setItem(frame_number, 0, item) |
139 | |
140 | === modified file 'tests/functional/openlp_core_ui/test_listpreviewwidget.py' |
141 | --- tests/functional/openlp_core_ui/test_listpreviewwidget.py 2015-12-31 22:46:06 +0000 |
142 | +++ tests/functional/openlp_core_ui/test_listpreviewwidget.py 2016-03-23 14:15:11 +0000 |
143 | @@ -23,9 +23,12 @@ |
144 | Package to test the openlp.core.ui.listpreviewwidget package. |
145 | """ |
146 | from unittest import TestCase |
147 | + |
148 | +from openlp.core.common import Settings |
149 | from openlp.core.ui.listpreviewwidget import ListPreviewWidget |
150 | +from openlp.core.lib import ServiceItem |
151 | |
152 | -from tests.functional import patch |
153 | +from tests.functional import MagicMock, patch, call |
154 | |
155 | |
156 | class TestListPreviewWidget(TestCase): |
157 | @@ -34,9 +37,27 @@ |
158 | """ |
159 | Mock out stuff for all the tests |
160 | """ |
161 | - self.setup_patcher = patch('openlp.core.ui.listpreviewwidget.ListPreviewWidget._setup') |
162 | - self.mocked_setup = self.setup_patcher.start() |
163 | - self.addCleanup(self.setup_patcher.stop) |
164 | + # Mock self.parent().width() |
165 | + self.parent_patcher = patch('openlp.core.ui.listpreviewwidget.ListPreviewWidget.parent') |
166 | + self.mocked_parent = self.parent_patcher.start() |
167 | + self.mocked_parent.width.return_value = 100 |
168 | + self.addCleanup(self.parent_patcher.stop) |
169 | + |
170 | + # Mock Settings().value() |
171 | + self.Settings_patcher = patch('openlp.core.ui.listpreviewwidget.Settings') |
172 | + self.mocked_Settings = self.Settings_patcher.start() |
173 | + self.mocked_Settings_obj = MagicMock() |
174 | + self.mocked_Settings_obj.value.return_value = None |
175 | + self.mocked_Settings.return_value = self.mocked_Settings_obj |
176 | + self.addCleanup(self.Settings_patcher.stop) |
177 | + |
178 | + # Mock self.viewport().width() |
179 | + self.viewport_patcher = patch('openlp.core.ui.listpreviewwidget.ListPreviewWidget.viewport') |
180 | + self.mocked_viewport = self.viewport_patcher.start() |
181 | + self.mocked_viewport_obj = MagicMock() |
182 | + self.mocked_viewport_obj.width.return_value = 200 |
183 | + self.mocked_viewport.return_value = self.mocked_viewport_obj |
184 | + self.addCleanup(self.viewport_patcher.stop) |
185 | |
186 | def new_list_preview_widget_test(self): |
187 | """ |
188 | @@ -49,4 +70,206 @@ |
189 | |
190 | # THEN: The object is not None, and the _setup() method was called. |
191 | self.assertIsNotNone(list_preview_widget, 'The ListPreviewWidget object should not be None') |
192 | - self.mocked_setup.assert_called_with(1) |
193 | + self.assertEquals(list_preview_widget.screen_ratio, 1, 'Should not be called') |
194 | + |
195 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
196 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
197 | + def replace_recalculate_layout_test_text(self, mocked_setRowHeight, mocked_resizeRowsToContents): |
198 | + """ |
199 | + Test if "Max height for non-text slides..." enabled, txt slides unchanged in replace_service_item & __recalc... |
200 | + """ |
201 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
202 | + # a text ServiceItem and a ListPreviewWidget. |
203 | + |
204 | + # Mock Settings().value('advanced/slide max height') |
205 | + self.mocked_Settings_obj.value.return_value = 100 |
206 | + # Mock self.viewport().width() |
207 | + self.mocked_viewport_obj.width.return_value = 200 |
208 | + # Mock text service item |
209 | + service_item = MagicMock() |
210 | + service_item.is_text.return_value = True |
211 | + service_item.get_frames.return_value = [{'title': None, 'text': None, 'verseTag': None}, |
212 | + {'title': None, 'text': None, 'verseTag': None}] |
213 | + # init ListPreviewWidget and load service item |
214 | + list_preview_widget = ListPreviewWidget(None, 1) |
215 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
216 | + # Change viewport width before forcing a resize |
217 | + self.mocked_viewport_obj.width.return_value = 400 |
218 | + |
219 | + # WHEN: __recalculate_layout() is called (via resizeEvent) |
220 | + list_preview_widget.resizeEvent(None) |
221 | + |
222 | + # THEN: setRowHeight() should not be called, while resizeRowsToContents() should be called twice |
223 | + # (once each in __recalculate_layout and replace_service_item) |
224 | + self.assertEquals(mocked_resizeRowsToContents.call_count, 2, 'Should be called') |
225 | + self.assertEquals(mocked_setRowHeight.call_count, 0, 'Should not be called') |
226 | + |
227 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
228 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
229 | + def replace_recalculate_layout_test_img(self, mocked_setRowHeight, mocked_resizeRowsToContents): |
230 | + """ |
231 | + Test if "Max height for non-text slides..." disabled, img slides unchanged in replace_service_item & __recalc... |
232 | + """ |
233 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
234 | + # an image ServiceItem and a ListPreviewWidget. |
235 | + |
236 | + # Mock Settings().value('advanced/slide max height') |
237 | + self.mocked_Settings_obj.value.return_value = 0 |
238 | + # Mock self.viewport().width() |
239 | + self.mocked_viewport_obj.width.return_value = 200 |
240 | + # Mock image service item |
241 | + service_item = MagicMock() |
242 | + service_item.is_text.return_value = False |
243 | + service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
244 | + {'title': None, 'path': None, 'image': None}] |
245 | + # init ListPreviewWidget and load service item |
246 | + list_preview_widget = ListPreviewWidget(None, 1) |
247 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
248 | + # Change viewport width before forcing a resize |
249 | + self.mocked_viewport_obj.width.return_value = 400 |
250 | + |
251 | + # WHEN: __recalculate_layout() is called (via resizeEvent) |
252 | + list_preview_widget.resizeEvent(None) |
253 | + |
254 | + # THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called |
255 | + # twice for each slide. |
256 | + self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called') |
257 | + self.assertEquals(mocked_setRowHeight.call_count, 4, 'Should be called twice for each slide') |
258 | + calls = [call(0, 200), call(1, 200), call(0, 400), call(1, 400)] |
259 | + mocked_setRowHeight.assert_has_calls(calls) |
260 | + |
261 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
262 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
263 | + def replace_recalculate_layout_test_img_max(self, mocked_setRowHeight, mocked_resizeRowsToContents): |
264 | + """ |
265 | + Test if "Max height for non-text slides..." enabled, img slides resized in replace_service_item & __recalc... |
266 | + """ |
267 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
268 | + # an image ServiceItem and a ListPreviewWidget. |
269 | + |
270 | + # Mock Settings().value('advanced/slide max height') |
271 | + self.mocked_Settings_obj.value.return_value = 100 |
272 | + # Mock self.viewport().width() |
273 | + self.mocked_viewport_obj.width.return_value = 200 |
274 | + # Mock image service item |
275 | + service_item = MagicMock() |
276 | + service_item.is_text.return_value = False |
277 | + service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
278 | + {'title': None, 'path': None, 'image': None}] |
279 | + # init ListPreviewWidget and load service item |
280 | + list_preview_widget = ListPreviewWidget(None, 1) |
281 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
282 | + # Change viewport width before forcing a resize |
283 | + self.mocked_viewport_obj.width.return_value = 400 |
284 | + |
285 | + # WHEN: __recalculate_layout() is called (via resizeEvent) |
286 | + list_preview_widget.resizeEvent(None) |
287 | + |
288 | + # THEN: resizeRowsToContents() should not be called, while setRowHeight() should be called |
289 | + # twice for each slide. |
290 | + self.assertEquals(mocked_resizeRowsToContents.call_count, 0, 'Should not be called') |
291 | + self.assertEquals(mocked_setRowHeight.call_count, 4, 'Should be called twice for each slide') |
292 | + calls = [call(0, 100), call(1, 100), call(0, 100), call(1, 100)] |
293 | + mocked_setRowHeight.assert_has_calls(calls) |
294 | + |
295 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
296 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
297 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') |
298 | + def row_resized_test_text(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents): |
299 | + """ |
300 | + Test if "Max height for non-text slides..." enabled, text-based slides not affected in row_resized. |
301 | + """ |
302 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
303 | + # a text ServiceItem and a ListPreviewWidget. |
304 | + |
305 | + # Mock Settings().value('advanced/slide max height') |
306 | + self.mocked_Settings_obj.value.return_value = 100 |
307 | + # Mock self.viewport().width() |
308 | + self.mocked_viewport_obj.width.return_value = 200 |
309 | + # Mock text service item |
310 | + service_item = MagicMock() |
311 | + service_item.is_text.return_value = True |
312 | + service_item.get_frames.return_value = [{'title': None, 'text': None, 'verseTag': None}, |
313 | + {'title': None, 'text': None, 'verseTag': None}] |
314 | + # Mock self.cellWidget().children().setMaximumWidth() |
315 | + mocked_cellWidget_child = MagicMock() |
316 | + mocked_cellWidget_obj = MagicMock() |
317 | + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] |
318 | + mocked_cellWidget.return_value = mocked_cellWidget_obj |
319 | + # init ListPreviewWidget and load service item |
320 | + list_preview_widget = ListPreviewWidget(None, 1) |
321 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
322 | + |
323 | + # WHEN: row_resized() is called |
324 | + list_preview_widget.row_resized(0, 100, 150) |
325 | + |
326 | + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called |
327 | + self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called') |
328 | + |
329 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
330 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
331 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') |
332 | + def row_resized_test_img(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents): |
333 | + """ |
334 | + Test if "Max height for non-text slides..." disabled, image-based slides not affected in row_resized. |
335 | + """ |
336 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
337 | + # an image ServiceItem and a ListPreviewWidget. |
338 | + |
339 | + # Mock Settings().value('advanced/slide max height') |
340 | + self.mocked_Settings_obj.value.return_value = 0 |
341 | + # Mock self.viewport().width() |
342 | + self.mocked_viewport_obj.width.return_value = 200 |
343 | + # Mock image service item |
344 | + service_item = MagicMock() |
345 | + service_item.is_text.return_value = False |
346 | + service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
347 | + {'title': None, 'path': None, 'image': None}] |
348 | + # Mock self.cellWidget().children().setMaximumWidth() |
349 | + mocked_cellWidget_child = MagicMock() |
350 | + mocked_cellWidget_obj = MagicMock() |
351 | + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] |
352 | + mocked_cellWidget.return_value = mocked_cellWidget_obj |
353 | + # init ListPreviewWidget and load service item |
354 | + list_preview_widget = ListPreviewWidget(None, 1) |
355 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
356 | + |
357 | + # WHEN: row_resized() is called |
358 | + list_preview_widget.row_resized(0, 100, 150) |
359 | + |
360 | + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should not be called |
361 | + self.assertEquals(mocked_cellWidget_child.setMaximumWidth.call_count, 0, 'Should not be called') |
362 | + |
363 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.resizeRowsToContents') |
364 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.setRowHeight') |
365 | + @patch(u'openlp.core.ui.listpreviewwidget.ListPreviewWidget.cellWidget') |
366 | + def row_resized_test_img_max(self, mocked_cellWidget, mocked_setRowHeight, mocked_resizeRowsToContents): |
367 | + """ |
368 | + Test if "Max height for non-text slides..." enabled, image-based slides are scaled in row_resized. |
369 | + """ |
370 | + # GIVEN: A setting to adjust "Max height for non-text slides in slide controller", |
371 | + # an image ServiceItem and a ListPreviewWidget. |
372 | + |
373 | + # Mock Settings().value('advanced/slide max height') |
374 | + self.mocked_Settings_obj.value.return_value = 100 |
375 | + # Mock self.viewport().width() |
376 | + self.mocked_viewport_obj.width.return_value = 200 |
377 | + # Mock image service item |
378 | + service_item = MagicMock() |
379 | + service_item.is_text.return_value = False |
380 | + service_item.get_frames.return_value = [{'title': None, 'path': None, 'image': None}, |
381 | + {'title': None, 'path': None, 'image': None}] |
382 | + # Mock self.cellWidget().children().setMaximumWidth() |
383 | + mocked_cellWidget_child = MagicMock() |
384 | + mocked_cellWidget_obj = MagicMock() |
385 | + mocked_cellWidget_obj.children.return_value = [None, mocked_cellWidget_child] |
386 | + mocked_cellWidget.return_value = mocked_cellWidget_obj |
387 | + # init ListPreviewWidget and load service item |
388 | + list_preview_widget = ListPreviewWidget(None, 1) |
389 | + list_preview_widget.replace_service_item(service_item, 200, 0) |
390 | + |
391 | + # WHEN: row_resized() is called |
392 | + list_preview_widget.row_resized(0, 100, 150) |
393 | + |
394 | + # THEN: self.cellWidget(row, 0).children()[1].setMaximumWidth() should be called |
395 | + mocked_cellWidget_child.setMaximumWidth.assert_called_once_with(150) |
see inline comments