[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
This commit is contained in:
Raoul Snyman 2014-11-24 21:43:34 +02:00
parent 93706f8d99
commit bd79b1d059
3 changed files with 78 additions and 25 deletions

View File

@ -38,20 +38,37 @@ Some of the code for this form is based on the examples at:
import cgi import cgi
import logging import logging
import sys
from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL
from PyQt4.phonon import Phonon from PyQt4.phonon import Phonon
from openlp.core.common import Registry, RegistryProperties, OpenLPMixin, Settings, translate, is_macosx 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.theme import BackgroundType
from openlp.core.lib import ScreenList
from openlp.core.ui import HideMode, AlertLocation from openlp.core.ui import HideMode, AlertLocation
log = logging.getLogger(__name__) 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): class Display(QtGui.QGraphicsView):
""" """
@ -135,7 +152,7 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
self.audio_player = None self.audio_player = None
self.first_time = True self.first_time = True
self.web_loaded = 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 window_flags = QtCore.Qt.FramelessWindowHint | QtCore.Qt.Tool | QtCore.Qt.WindowStaysOnTopHint
if Settings().value('advanced/x11 bypass wm'): if Settings().value('advanced/x11 bypass wm'):
window_flags |= QtCore.Qt.X11BypassWindowManagerHint window_flags |= QtCore.Qt.X11BypassWindowManagerHint
@ -165,10 +182,10 @@ class MainDisplay(OpenLPMixin, Display, RegistryProperties):
""" """
if enabled: if enabled:
self.setAutoFillBackground(False) self.setAutoFillBackground(False)
self.setStyleSheet("QGraphicsView {background: transparent; border: 0px;}") self.setStyleSheet(TRANSPARENT_STYLESHEET)
else: else:
self.setAttribute(QtCore.Qt.WA_NoSystemBackground, False) self.setAttribute(QtCore.Qt.WA_NoSystemBackground, False)
self.setStyleSheet("QGraphicsView {}") self.setStyleSheet(OPAQUE_STYLESHEET)
self.setAttribute(QtCore.Qt.WA_TranslucentBackground, enabled) self.setAttribute(QtCore.Qt.WA_TranslucentBackground, enabled)
self.repaint() self.repaint()

View File

@ -36,8 +36,10 @@ from PyQt4 import QtCore
from openlp.core.common import Registry from openlp.core.common import Registry
from openlp.core.lib import ScreenList from openlp.core.lib import ScreenList
from openlp.core.ui import MainDisplay 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 = { SCREEN = {
'primary': False, 'primary': False,
@ -46,7 +48,7 @@ SCREEN = {
} }
class TestMainDisplay(TestCase): class TestMainDisplay(TestCase, TestMixin):
def setUp(self): def setUp(self):
""" """
@ -59,6 +61,9 @@ class TestMainDisplay(TestCase):
self.desktop.screenGeometry.return_value = SCREEN['size'] self.desktop.screenGeometry.return_value = SCREEN['size']
self.screens = ScreenList.create(self.desktop) self.screens = ScreenList.create(self.desktop)
Registry.create() Registry.create()
self.registry = Registry()
self.setup_application()
Registry().register('application', self.app)
def tearDown(self): def tearDown(self):
""" """
@ -80,30 +85,60 @@ class TestMainDisplay(TestCase):
# THEN: The controller should not be a live controller. # THEN: The controller should not be a live controller.
self.assertEqual(main_display.is_live, True, 'The main display should 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() display = MagicMock()
main_display = MainDisplay(display) main_display = MainDisplay(display)
# WHEN: We enable transparency # WHEN: Transparency is enabled
main_display.set_transparency(True) main_display.set_transparency(True)
# THEN: There should be a Stylesheet # THEN: The transparent stylesheet should be used
self.assertEqual('QGraphicsView {background: transparent; border: 0px;}', main_display.styleSheet(), self.assertEqual(TRANSPARENT_STYLESHEET, main_display.styleSheet(),
'MainDisplay instance should be transparent') 'The MainDisplay should use the transparent stylesheet')
self.assertFalse(main_display.autoFillBackground(), 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), 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) main_display.set_transparency(False)
# THEN: The Stylesheet should be empty # THEN: The opaque stylesheet should be used
self.assertEqual('QGraphicsView {}', main_display.styleSheet(), self.assertEqual(OPAQUE_STYLESHEET, main_display.styleSheet(),
'MainDisplay instance should not be transparent') 'The MainDisplay should use the opaque stylesheet')
self.assertFalse(main_display.testAttribute(QtCore.Qt.WA_TranslucentBackground), 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)

View File

@ -36,9 +36,10 @@ from unittest import TestCase
from openlp.core.ui.mainwindow import MainWindow from openlp.core.ui.mainwindow import MainWindow
from openlp.core.lib.ui import UiStrings from openlp.core.lib.ui import UiStrings
from openlp.core.common.registry import Registry 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.functional import MagicMock, patch
from tests.helpers.testmixin import TestMixin
from tests.utils.constants import TEST_RESOURCES_PATH
class TestMainWindow(TestCase, TestMixin): class TestMainWindow(TestCase, TestMixin):