From bd79b1d059c64451732d9ef7cafeacfc7c97416d Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Mon, 24 Nov 2014 21:43:34 +0200 Subject: [PATCH] [bug 1314469] Fix the border seen in the main display on KDE by not overwriting that bit of the stylesheet Fixes: https://launchpad.net/bugs/1314469 --- openlp/core/ui/maindisplay.py | 31 +++++++-- .../openlp_core_ui/test_maindisplay.py | 67 ++++++++++++++----- .../openlp_core_ui/test_mainwindow.py | 5 +- 3 files changed, 78 insertions(+), 25 deletions(-) diff --git a/openlp/core/ui/maindisplay.py b/openlp/core/ui/maindisplay.py index f9f00a235..fc1a620fe 100644 --- a/openlp/core/ui/maindisplay.py +++ b/openlp/core/ui/maindisplay.py @@ -38,20 +38,37 @@ Some of the code for this form is based on the examples at: import cgi import logging -import sys from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4.phonon import Phonon from openlp.core.common import Registry, RegistryProperties, OpenLPMixin, Settings, translate, is_macosx -from openlp.core.lib import ServiceItem, ImageSource, build_html, expand_tags, image_to_byte +from openlp.core.lib import ServiceItem, ImageSource, ScreenList, build_html, expand_tags, image_to_byte from openlp.core.lib.theme import BackgroundType - -from openlp.core.lib import ScreenList from openlp.core.ui import HideMode, AlertLocation log = logging.getLogger(__name__) +OPAQUE_STYLESHEET = """ +QWidget { + border: 0px; + margin: 0px; + padding: 0px; +} +QGraphicsView {} +""" +TRANSPARENT_STYLESHEET = """ +QWidget { + border: 0px; + margin: 0px; + padding: 0px; +} +QGraphicsView { + background: transparent; + border: 0px; +} +""" + class Display(QtGui.QGraphicsView): """ @@ -135,7 +152,7 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): self.audio_player = None self.first_time = True self.web_loaded = True - self.setStyleSheet('border: 0px; margin: 0px; padding: 0px;') + self.setStyleSheet(OPAQUE_STYLESHEET) window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint if Settings().value('advanced/x11 bypass wm'): window_flags |= QtCore.Qt.X11BypassWindowManagerHint @@ -165,10 +182,10 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties): """ if enabled: self.setAutoFillBackground(False) - self.setStyleSheet("QGraphicsView {background: transparent; border: 0px;}") + self.setStyleSheet(TRANSPARENT_STYLESHEET) else: self.setAttribute(QtCore.Qt.WA_NoSystemBackground, False) - self.setStyleSheet("QGraphicsView {}") + self.setStyleSheet(OPAQUE_STYLESHEET) self.setAttribute(QtCore.Qt.WA_TranslucentBackground, enabled) self.repaint() diff --git a/tests/functional/openlp_core_ui/test_maindisplay.py b/tests/functional/openlp_core_ui/test_maindisplay.py index 6d67a3b67..dbd6324c1 100644 --- a/tests/functional/openlp_core_ui/test_maindisplay.py +++ b/tests/functional/openlp_core_ui/test_maindisplay.py @@ -36,8 +36,10 @@ from PyQt4 import QtCore from openlp.core.common import Registry from openlp.core.lib import ScreenList from openlp.core.ui import MainDisplay +from openlp.core.ui.maindisplay import TRANSPARENT_STYLESHEET, OPAQUE_STYLESHEET -from tests.interfaces import MagicMock, patch +from tests.helpers.testmixin import TestMixin +from tests.interfaces import MagicMock SCREEN = { 'primary': False, @@ -46,7 +48,7 @@ SCREEN = { } -class TestMainDisplay(TestCase): +class TestMainDisplay(TestCase, TestMixin): def setUp(self): """ @@ -59,6 +61,9 @@ class TestMainDisplay(TestCase): self.desktop.screenGeometry.return_value = SCREEN['size'] self.screens = ScreenList.create(self.desktop) Registry.create() + self.registry = Registry() + self.setup_application() + Registry().register('application', self.app) def tearDown(self): """ @@ -80,30 +85,60 @@ class TestMainDisplay(TestCase): # THEN: The controller should not be a live controller. self.assertEqual(main_display.is_live, True, 'The main display should be a live controller') - def set_transparency_test(self): + def set_transparency_enabled_test(self): """ - Test creating an instance of the MainDisplay class + Test setting the display to be transparent """ - # GIVEN: get an instance of MainDisplay + # GIVEN: An instance of MainDisplay display = MagicMock() main_display = MainDisplay(display) - # WHEN: We enable transparency + # WHEN: Transparency is enabled main_display.set_transparency(True) - # THEN: There should be a Stylesheet - self.assertEqual('QGraphicsView {background: transparent; border: 0px;}', main_display.styleSheet(), - 'MainDisplay instance should be transparent') + # THEN: The transparent stylesheet should be used + self.assertEqual(TRANSPARENT_STYLESHEET, main_display.styleSheet(), + 'The MainDisplay should use the transparent stylesheet') self.assertFalse(main_display.autoFillBackground(), - 'MainDisplay instance should be without background auto fill') + 'The MainDisplay should not have autoFillBackground set') self.assertTrue(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground), - 'MainDisplay hasnt translucent background') + 'The MainDisplay should have a translucent background') - # WHEN: We disable transparency + def set_transparency_disabled_test(self): + """ + Test setting the display to be opaque + """ + # GIVEN: An instance of MainDisplay + display = MagicMock() + main_display = MainDisplay(display) + + # WHEN: Transparency is disabled main_display.set_transparency(False) - # THEN: The Stylesheet should be empty - self.assertEqual('QGraphicsView {}', main_display.styleSheet(), - 'MainDisplay instance should not be transparent') + # THEN: The opaque stylesheet should be used + self.assertEqual(OPAQUE_STYLESHEET, main_display.styleSheet(), + 'The MainDisplay should use the opaque stylesheet') self.assertFalse(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground), - 'MainDisplay hasnt translucent background') + 'The MainDisplay should not have a translucent background') + + def css_changed_test(self): + """ + Test that when the CSS changes, the plugins are looped over and given an opportunity to update the CSS + """ + # GIVEN: A mocked list of plugins, a mocked display and a MainDisplay + mocked_songs_plugin = MagicMock() + mocked_bibles_plugin = MagicMock() + mocked_plugin_manager = MagicMock() + mocked_plugin_manager.plugins = [mocked_songs_plugin, mocked_bibles_plugin] + Registry().register('plugin_manager', mocked_plugin_manager) + display = MagicMock() + main_display = MainDisplay(display) + # This is set up dynamically, so we need to mock it out for now + main_display.frame = MagicMock() + + # WHEN: The css_changed() method is triggered + main_display.css_changed() + + # THEN: The plugins should have each been given an opportunity to add their bit to the CSS + mocked_songs_plugin.refresh_css.assert_called_with(main_display.frame) + mocked_bibles_plugin.refresh_css.assert_called_with(main_display.frame) diff --git a/tests/functional/openlp_core_ui/test_mainwindow.py b/tests/functional/openlp_core_ui/test_mainwindow.py index e3d1fc445..1cffbfdc7 100644 --- a/tests/functional/openlp_core_ui/test_mainwindow.py +++ b/tests/functional/openlp_core_ui/test_mainwindow.py @@ -36,9 +36,10 @@ from unittest import TestCase from openlp.core.ui.mainwindow import MainWindow from openlp.core.lib.ui import UiStrings from openlp.core.common.registry import Registry -from tests.utils.constants import TEST_RESOURCES_PATH -from tests.helpers.testmixin import TestMixin + from tests.functional import MagicMock, patch +from tests.helpers.testmixin import TestMixin +from tests.utils.constants import TEST_RESOURCES_PATH class TestMainWindow(TestCase, TestMixin):