diff --git a/soitool/inline_editable_soi_view.py b/soitool/inline_editable_soi_view.py index 5bde3a8ba14af685065fa8200d96e2148e36651a..564e7f11d1f96fd459b6b06684c0fe4b1a77c558 100644 --- a/soitool/inline_editable_soi_view.py +++ b/soitool/inline_editable_soi_view.py @@ -22,6 +22,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 +420,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 +428,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 +436,7 @@ 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 +471,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 +494,7 @@ 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 +520,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 +535,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 +553,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 +569,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 = ( diff --git a/soitool/modules/code_table_base.py b/soitool/modules/code_table_base.py index 9cdff1ed3d297456eb864864791c2310d442eb7d..478bc64449a55dc22a63336299d9ed83d5611253 100644 --- a/soitool/modules/code_table_base.py +++ b/soitool/modules/code_table_base.py @@ -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( diff --git a/soitool/modules/module_authentication_board.py b/soitool/modules/module_authentication_board.py index ca46c80dcfac75cb449104380700fe62e8d24916..e1f59126a50306e44e06bb14c6d2f8b8c7ed91ce 100644 --- a/soitool/modules/module_authentication_board.py +++ b/soitool/modules/module_authentication_board.py @@ -4,7 +4,7 @@ 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 +21,7 @@ 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 diff --git a/soitool/modules/module_base.py b/soitool/modules/module_base.py index 1d6f055d20dd0a418317e7a77d3e140540159b2d..4a6e1e17b1cb398de62da8b9afd5bbd7a9c3ae1e 100644 --- a/soitool/modules/module_base.py +++ b/soitool/modules/module_base.py @@ -2,12 +2,32 @@ 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): """Interface for SOI-modules.""" diff --git a/soitool/modules/module_freetext.py b/soitool/modules/module_freetext.py index 95066bceea66e73d73013f3b930fecd92ef1484d..1d1f47dc02d8491428a716977e6e60403198410d 100644 --- a/soitool/modules/module_freetext.py +++ b/soitool/modules/module_freetext.py @@ -13,7 +13,7 @@ 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 +113,7 @@ 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 diff --git a/soitool/modules/module_subtractorcodes.py b/soitool/modules/module_subtractorcodes.py index e56c0d4c38b1f0b72df23e65a11494ca7eb33d02..9ded65cd2c8aa4ec625285be3fab2a26f1ede908 100644 --- a/soitool/modules/module_subtractorcodes.py +++ b/soitool/modules/module_subtractorcodes.py @@ -3,7 +3,7 @@ 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 +21,7 @@ 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" diff --git a/soitool/modules/module_table.py b/soitool/modules/module_table.py index 43bef7fb8d9e3ca625877c9ae7dfae4705b3dd93..fff51d7e058351e3df4dde972e1db077481b8316 100644 --- a/soitool/modules/module_table.py +++ b/soitool/modules/module_table.py @@ -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: