Skip to content
Snippets Groups Projects
Commit 3fa2c06e authored by Thomas Holene Løkkeborg's avatar Thomas Holene Løkkeborg
Browse files

Merge branch 'fiks-oppløsningsproblem' into 'master'

#125 løsning til oppløsningstrøbbel ved å bruke px ikke pt i font

See merge request !70
parents c3ab5479 a3f893bc
No related branches found
No related tags found
1 merge request!70#125 løsning til oppløsningstrøbbel ved å bruke px ikke pt i font
Pipeline #83475 passed
......@@ -12,7 +12,6 @@ from PySide2.QtWidgets import (
QGraphicsProxyWidget,
)
from PySide2.QtGui import (
QFont,
QPixmap,
QBrush,
QPalette,
......@@ -22,6 +21,7 @@ from PySide2.QtPrintSupport import QPrinter
from soitool.soi import ModuleLargerThanBinError
from soitool.dialog_wrappers import exec_warning_dialog
from soitool.serialize_export_import_soi import generate_soi_filename
from soitool.modules.module_base import qfont_with_pixel_size
# How attachment pages should be numbered. The first page should be numbered
# by the value of ATTACHMENT_NUMBERING_SCHEME[0], the second page
......@@ -419,7 +419,7 @@ class InlineEditableSOIView(QScrollArea):
label_title = QLabel(self.soi.title)
label_title.move(x, y + self.soi.HEADER_HEIGHT)
label_title.setStyleSheet("background-color: rgba(0,0,0,0%)")
label_title.setFont(QFont("Times New Roman", 35))
label_title.setFont(qfont_with_pixel_size("Times New Roman", 60))
proxy = self.scene.addWidget(label_title)
proxy.setRotation(-90)
......@@ -427,7 +427,7 @@ class InlineEditableSOIView(QScrollArea):
label_description = QLabel(self.soi.description)
label_description.move(x + 57, y + self.soi.HEADER_HEIGHT)
label_description.setStyleSheet("background-color: rgba(0,0,0,0%)")
label_description.setFont(QFont("Times New Roman", 15))
label_description.setFont(qfont_with_pixel_size("Times New Roman", 25))
proxy = self.scene.addWidget(label_description)
proxy.setRotation(-90)
......@@ -435,7 +435,9 @@ class InlineEditableSOIView(QScrollArea):
creation_date = soi_date_string_to_user_friendly_string(self.soi.date)
label_creation_date = QLabel("Opprettet: {}".format(creation_date))
label_creation_date.setStyleSheet("background-color: rgba(0,0,0,0%)")
label_creation_date.setFont(QFont("Times New Roman", 15))
label_creation_date.setFont(
qfont_with_pixel_size("Times New Roman", 25)
)
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......@@ -470,7 +472,7 @@ class InlineEditableSOIView(QScrollArea):
"1 av N", f"{self.copy_current} av {self.copy_total}"
)
proxy.label.setStyleSheet("background-color: rgba(0,0,0,0%)")
proxy.label.setFont(QFont("Times New Roman", 40))
proxy.label.setFont(qfont_with_pixel_size("Times New Roman", 70))
# Need to call this when label of proxy changes. See function docstring
proxy.update_bounding_rect()
......@@ -493,7 +495,9 @@ class InlineEditableSOIView(QScrollArea):
label_copy_number_header.setStyleSheet(
"background-color: rgba(0,0,0,0%)"
)
label_copy_number_header.setFont(QFont("Times New Roman", 15))
label_copy_number_header.setFont(
qfont_with_pixel_size("Times New Roman", 25)
)
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......@@ -519,7 +523,7 @@ class InlineEditableSOIView(QScrollArea):
)
)
page_number.setStyleSheet("background-color: rgba(0,0,0,0%)")
page_number.setFont(QFont("Times New Roman", 15))
page_number.setFont(qfont_with_pixel_size("Times New Roman", 25))
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......@@ -534,7 +538,7 @@ class InlineEditableSOIView(QScrollArea):
classification.setStyleSheet(
"background-color: rgba(0,0,0,0%); " "color: red"
)
classification.setFont(QFont("Times New Roman", 35))
classification.setFont(qfont_with_pixel_size("Times New Roman", 60))
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......@@ -552,7 +556,7 @@ class InlineEditableSOIView(QScrollArea):
)
label_valid_from = QLabel("Gyldig fra: {}".format(valid_from))
label_valid_from.setStyleSheet("background-color: rgba(0,0,0,0%)")
label_valid_from.setFont(QFont("Times New Roman", 15))
label_valid_from.setFont(qfont_with_pixel_size("Times New Roman", 25))
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......@@ -568,7 +572,7 @@ class InlineEditableSOIView(QScrollArea):
valid_to = soi_date_string_to_user_friendly_string(self.soi.valid_to)
label_valid_to = QLabel("Gyldig til: {}".format(valid_to))
label_valid_to.setStyleSheet("background-color: rgba(0,0,0,0%)")
label_valid_to.setFont(QFont("Times New Roman", 15))
label_valid_to.setFont(qfont_with_pixel_size("Times New Roman", 25))
# Source: https://stackoverflow.com/a/8638114/3545896
# CAUTION: does not work if font is set through stylesheet
label_width = (
......
......@@ -11,6 +11,7 @@ from soitool.modules.module_base import (
get_table_size,
resize_table,
HEADLINE_FONT,
TABLE_CELL_DEFAULT_FONT,
)
AUTHENTICATIONBOARD_MODULE = "AuthenticationBoardModule"
......@@ -37,6 +38,7 @@ class CodeTableBase(ModuleBase, QTableWidget, metaclass=Meta):
self.verticalHeader().hide()
self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.setFont(TABLE_CELL_DEFAULT_FONT)
# Resize table when headline changes
self.cellChanged.connect(
......
......@@ -4,7 +4,11 @@ from secrets import choice
from PySide2.QtWidgets import QTableWidgetItem
from PySide2 import QtGui
from PySide2.QtCore import Qt
from soitool.modules.module_base import resize_table
from soitool.modules.module_base import (
resize_table,
qfont_with_pixel_size,
TABLE_CELL_DEFAULT_FONT,
)
from soitool.modules.code_table_base import CodeTableBase
# Characters for first column,
......@@ -21,7 +25,9 @@ CODE_LENGTH = 25
CODE_CHARACTER_TYPE = "ascii"
# Font for authentication codes, should be a monospaced font
CODE_FONT = QtGui.QFont("Consolas", 10, QtGui.QFont.SansSerif)
CODE_FONT = qfont_with_pixel_size(
"Consolas", TABLE_CELL_DEFAULT_FONT.pixelSize(), QtGui.QFont.SansSerif
)
# Adds space between sets of characters, 0 => no spaces
# If code is 123456 and interval is 2, code will be 12 34 56
......
......@@ -2,11 +2,34 @@
from abc import ABC
from PySide2 import QtGui
def qfont_with_pixel_size(font_family, pixel_size, weight=None):
"""Provide a QFont with given family and pixel size.
Created because QFont does not have a constructor with pixel size as a
parameter.
Parameters
----------
font_family : str
Name of font family. Sent to https://doc.qt.io/qt-5/qfont.html#QFont-1
pixel_size : int
Pixel size. Sent to https://doc.qt.io/qt-5/qfont.html#setPixelSize
weight : QFont.Weight
Weight of font. Sent to https://doc.qt.io/qt-5/qfont.html#QFont-1
"""
if weight is not None:
font = QtGui.QFont(font_family, weight=weight)
else:
font = QtGui.QFont(font_family)
font.setPixelSize(pixel_size)
return font
# Font for module headline
HEADLINE_FONT = QtGui.QFont()
HEADLINE_FONT.setFamily("Arial")
HEADLINE_FONT.setPointSize(12)
HEADLINE_FONT.setWeight(100)
HEADLINE_FONT = qfont_with_pixel_size("Arial", 24, 100)
TABLE_CELL_DEFAULT_FONT = qfont_with_pixel_size("Arial", 16)
class ModuleBase(ABC):
......
......@@ -13,7 +13,11 @@ from PySide2.QtWidgets import (
)
from PySide2.QtCore import QSize, Qt
from PySide2.QtGui import QIcon, QFontMetricsF
from soitool.modules.module_base import ModuleBase, HEADLINE_FONT
from soitool.modules.module_base import (
ModuleBase,
HEADLINE_FONT,
qfont_with_pixel_size,
)
class TextEditWithSizeOfContent(QTextEdit):
......@@ -113,6 +117,9 @@ class FreeTextModule(ModuleBase, QWidget, metaclass=Meta):
self.line_edit_header = LineEditWithSizeOfContent()
self.line_edit_header.setFont(HEADLINE_FONT)
self.text_edit_body = TextEditWithSizeOfContent()
self.text_edit_body.setFont(
qfont_with_pixel_size("Arial", HEADLINE_FONT.pixelSize())
)
# When the contents of these widgets change we need to manually trigger
# adjust of size, even on self. Without adjust of size on self the
......
......@@ -3,7 +3,11 @@ import string
from PySide2.QtWidgets import QTableWidgetItem
from PySide2 import QtGui
from PySide2.QtCore import Qt
from soitool.modules.module_base import resize_table
from soitool.modules.module_base import (
resize_table,
qfont_with_pixel_size,
TABLE_CELL_DEFAULT_FONT,
)
from soitool.modules.code_table_base import CodeTableBase
# Characters for first and second column
......@@ -21,7 +25,9 @@ SPACE_INTERVAL = 4
SPACE_AMOUNT = 3
# Font for subtractorcodes
CODE_FONT = QtGui.QFont("Arial", 10, QtGui.QFont.SansSerif)
CODE_FONT = qfont_with_pixel_size(
"Arial", TABLE_CELL_DEFAULT_FONT.pixelSize(), QtGui.QFont.SansSerif
)
HEADLINE_TEXT = "Subtraktorkoder"
......
......@@ -6,6 +6,7 @@ from soitool.modules.module_base import (
resize_table,
get_table_size,
HEADLINE_FONT,
TABLE_CELL_DEFAULT_FONT,
)
START_ROWS = 2
......@@ -42,6 +43,7 @@ class TableModule(ModuleBase, QTableWidget, metaclass=Meta):
self.verticalHeader().hide()
self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.setFont(TABLE_CELL_DEFAULT_FONT)
# If parameters are None, start as empty table.
if size is None and data is None:
......
"""Test module that looks for differences in SOI modules across resolutions.
This was written as a regression test for #125. Ideally it should also test the
header of the SOI, but this is much more complicated to test for..
## Important
This test can not test across different resolutions by itself, this is up to
the user. Our pipeline will test across a couple of different resolutions.
"""
import unittest
from PySide2.QtWidgets import QApplication
from PySide2 import QtGui
from PySide2.QtCore import QTimer, Qt, QSysInfo
from PySide2.QtTest import QTest
from PySide2.QtGui import QGuiApplication
from soitool.soi import SOI
from soitool.modules.module_authentication_board import (
AuthenticationBoardModule,
)
from soitool.modules.module_subtractorcodes import SubtractorcodesModule
from soitool.new_module_dialog import MODULE_CHOICES
if isinstance(QtGui.qApp, type(None)):
app = QApplication([])
else:
app = QtGui.qApp
def screen_information():
"""Get string with information about the screen.
Returns
-------
str
String with screen information.
"""
screen_string = ""
screen = QGuiApplication.primaryScreen()
screen_string += "screen.size() -> " + str(screen.size()) + "\n"
screen_string += (
"screen.physicalDotsPerInchX() -> "
+ str(screen.physicalDotsPerInchX())
+ "\n"
)
screen_string += (
"screen.physicalDotsPerInchY() -> "
+ str(screen.physicalDotsPerInchY())
+ "\n"
)
screen_string += (
"screen.logicalDotsPerInchX() -> "
+ str(screen.logicalDotsPerInchX())
+ "\n"
)
screen_string += (
"screen.logicalDotsPerInchY() -> "
+ str(screen.logicalDotsPerInchY())
+ "\n"
)
screen_string += (
"screen.devicePixelRatio() -> " + str(screen.devicePixelRatio()) + "\n"
)
return screen_string
class TestModulesAcrossResolutions(unittest.TestCase):
"""TestCase for modules across resolutions."""
@unittest.skipUnless(
QSysInfo.productType() == "windows",
"Test currently only able to target Windows",
)
def test_add_all_modules(self):
"""Add all modules, reorganize, and assert result.
Expected result was gotten by simply running reorganize and noting down
the results. We should get the same result across different
resolutions.
Modules added to SOI must be the same every time the program is ran.
Test only works on Windows, as the expected result is based on the
Windows look-and-feel.
NOTE: This test needs to be updated when a new module is added,
deleted, or changed. It will fail until it is updated.
"""
expected_result = [
{"x": 0, "y": 0, "page": 1, "name": "AuthenticationBoardModule"},
{"x": 407.5, "y": 0, "page": 1, "name": "SubtractorcodesModule"},
{"x": 602.0, "y": 0, "page": 1, "name": "FreeTextModule"},
{"x": 702.0, "y": 0, "page": 1, "name": "TableModule"},
]
def press_enter():
active_widget = app.activeModalWidget()
# triple click to select existing text for overwrite
QTest.mouseDClick(active_widget.edit_headline, Qt.LeftButton)
QTest.mouseClick(active_widget.edit_headline, Qt.LeftButton)
# need to overwrite text because title otherwise contains
# unpredictable text
QTest.keyClicks(active_widget.edit_headline, "TestTitle")
QTest.keyClick(active_widget, Qt.Key_Enter)
soi = SOI()
for module in MODULE_CHOICES:
# If we're adding one of the modules with a popup as part of it's
# constructor we need to singleShot pressing enter to close it
if module in (AuthenticationBoardModule, SubtractorcodesModule):
QTimer.singleShot(0, press_enter)
soi.add_module(module.__name__, module())
soi.reorganize()
self.assertEqual(
expected_result,
[module["meta"] for module in soi.modules],
"All modules added to SOI and calling reorganize should result in "
"expected 'meta' information. Screen is: \n"
+ screen_information(),
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment