Skip to content

Commit 8ed9a88

Browse files
nmaarnioLKajan
authored andcommitted
add font selection to print settings page
1 parent fbb6caa commit 8ed9a88

4 files changed

Lines changed: 165 additions & 63 deletions

File tree

arho_feature_template/core/prints/layout_items.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
QgsUnitTypes,
2121
)
2222
from qgis.PyQt.QtCore import QPointF, QSizeF, Qt
23-
from qgis.PyQt.QtGui import QFont, QPolygonF
23+
from qgis.PyQt.QtGui import QPolygonF
2424

2525
from arho_feature_template.core.prints.layout_utils import (
2626
move_label_above_symbol,
@@ -49,9 +49,6 @@
4949
class LayoutItemFactory:
5050
SETTINGS: RegulationPrintSettings
5151

52-
BOLD_FONT = QFont()
53-
BOLD_FONT.setBold(True)
54-
5552
@classmethod
5653
def new_regulation_print_item(
5754
cls,
@@ -215,7 +212,7 @@ def new_regulation_heading_label(
215212
label.setMode(QgsLayoutItemLabel.Mode.ModeFont)
216213
text = get_localized_text(heading, cls.SETTINGS.languages[language_index])
217214
label.setText(text if text else "")
218-
label.setFont(cls.BOLD_FONT)
215+
label.setFont(cls.SETTINGS.heading_font)
219216
label.setMarginX(2)
220217
# label.setMarginY(2)
221218
label.attemptResize(
@@ -235,6 +232,7 @@ def new_regulation_text_label(
235232
label = QgsLayoutItemLabel(layout)
236233
label.setMode(QgsLayoutItemLabel.Mode.ModeFont)
237234
label.setText(get_localized_text(text, cls.SETTINGS.languages[language_index]) or "")
235+
label.setFont(cls.SETTINGS.text_font)
238236
label.setMarginX(2)
239237
label.attemptResize(
240238
QgsLayoutSize(
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
from __future__ import annotations
22

3-
from typing import NamedTuple
3+
from typing import TYPE_CHECKING, NamedTuple
4+
5+
if TYPE_CHECKING:
6+
from qgis.PyQt.QtGui import QFont
47

58

69
class RegulationPrintSettings(NamedTuple):
710
include_regulation_headings: bool
811
include_regulation_texts: bool
912
symbol_width: float
1013
symbol_height: float
14+
heading_font: QFont
15+
text_font: QFont
1116
x_margins: float
1217
y_margins: float
1318
languages: list[str] # list of language codes, e.g. "fin" or "swe". Should be 1 or 2

arho_feature_template/gui/dialogs/regulations_print_settings_dialog.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from arho_feature_template.project.layers.code_layers import LanguageLayer
1212

1313
if TYPE_CHECKING:
14-
from qgis.gui import QgsSpinBox
14+
from qgis.gui import QgsFontButton, QgsSpinBox
1515

1616
from arho_feature_template.gui.components.code_combobox import CodeComboBox
1717

@@ -27,10 +27,14 @@ def __init__(self):
2727
# TYPES
2828
self.include_regulation_headings_checkbox: QCheckBox
2929
self.include_regulation_texts_checkbox: QCheckBox
30-
self.language_1_selection: CodeComboBox
31-
self.language_2_selection: CodeComboBox
30+
self.heading_font_selection: QgsFontButton
31+
self.text_font_selection: QgsFontButton
3232
self.symbol_width_spinbox: QgsSpinBox
3333
self.symbol_height_spinbox: QgsSpinBox
34+
35+
self.language_1_selection: CodeComboBox
36+
self.language_2_selection: CodeComboBox
37+
3438
self.x_margins_spinbox: QgsSpinBox
3539
self.y_margins_spinbox: QgsSpinBox
3640

@@ -48,6 +52,8 @@ def get_settings(self) -> RegulationPrintSettings:
4852
self.include_regulation_texts_checkbox.isChecked(),
4953
self.symbol_width_spinbox.value(),
5054
self.symbol_height_spinbox.value(),
55+
self.heading_font_selection.currentFont(),
56+
self.text_font_selection.currentFont(),
5157
self.x_margins_spinbox.value(),
5258
self.y_margins_spinbox.value(),
5359
self.get_language_codes(),

arho_feature_template/gui/dialogs/regulations_print_settings_dialog.ui

Lines changed: 147 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>359</width>
10-
<height>417</height>
9+
<width>427</width>
10+
<height>505</height>
1111
</rect>
1212
</property>
1313
<property name="windowTitle">
@@ -17,18 +17,30 @@
1717
<item>
1818
<widget class="QGroupBox" name="groupBox">
1919
<property name="title">
20-
<string>Sisältö</string>
20+
<string>Elementit</string>
2121
</property>
2222
<layout class="QFormLayout" name="formLayout_2">
2323
<item row="0" column="0">
2424
<widget class="QLabel" name="label_4">
25+
<property name="minimumSize">
26+
<size>
27+
<width>0</width>
28+
<height>25</height>
29+
</size>
30+
</property>
2531
<property name="text">
2632
<string>Sisällytä määräyksien otsikot:</string>
2733
</property>
2834
</widget>
2935
</item>
3036
<item row="0" column="1">
3137
<widget class="QCheckBox" name="include_regulation_headings_checkbox">
38+
<property name="minimumSize">
39+
<size>
40+
<width>0</width>
41+
<height>25</height>
42+
</size>
43+
</property>
3244
<property name="text">
3345
<string/>
3446
</property>
@@ -37,15 +49,27 @@
3749
</property>
3850
</widget>
3951
</item>
40-
<item row="1" column="0">
52+
<item row="2" column="0">
4153
<widget class="QLabel" name="label">
54+
<property name="minimumSize">
55+
<size>
56+
<width>0</width>
57+
<height>25</height>
58+
</size>
59+
</property>
4260
<property name="text">
4361
<string>Sisällytä määräystekstit:</string>
4462
</property>
4563
</widget>
4664
</item>
47-
<item row="1" column="1">
65+
<item row="2" column="1">
4866
<widget class="QCheckBox" name="include_regulation_texts_checkbox">
67+
<property name="minimumSize">
68+
<size>
69+
<width>0</width>
70+
<height>25</height>
71+
</size>
72+
</property>
4973
<property name="text">
5074
<string/>
5175
</property>
@@ -54,52 +78,20 @@
5478
</property>
5579
</widget>
5680
</item>
57-
</layout>
58-
</widget>
59-
</item>
60-
<item>
61-
<widget class="QGroupBox" name="groupBox_3">
62-
<property name="title">
63-
<string>Kielet</string>
64-
</property>
65-
<layout class="QFormLayout" name="formLayout_3">
66-
<item row="0" column="0">
67-
<widget class="QLabel" name="label_5">
68-
<property name="text">
69-
<string>Kieli 1:</string>
70-
</property>
71-
</widget>
72-
</item>
73-
<item row="0" column="1">
74-
<widget class="CodeComboBox" name="language_1_selection"/>
75-
</item>
76-
<item row="1" column="0">
77-
<widget class="QLabel" name="label_6">
78-
<property name="text">
79-
<string>Kieli 2:</string>
80-
</property>
81-
</widget>
82-
</item>
83-
<item row="1" column="1">
84-
<widget class="CodeComboBox" name="language_2_selection"/>
85-
</item>
86-
</layout>
87-
</widget>
88-
</item>
89-
<item>
90-
<widget class="QGroupBox" name="groupBox_2">
91-
<property name="title">
92-
<string>Symbolit</string>
93-
</property>
94-
<layout class="QFormLayout" name="formLayout">
95-
<item row="0" column="0">
81+
<item row="4" column="0">
9682
<widget class="QLabel" name="label_2">
83+
<property name="minimumSize">
84+
<size>
85+
<width>0</width>
86+
<height>25</height>
87+
</size>
88+
</property>
9789
<property name="text">
9890
<string>Symbolien leveys:</string>
9991
</property>
10092
</widget>
10193
</item>
102-
<item row="0" column="1">
94+
<item row="4" column="1">
10395
<widget class="QgsSpinBox" name="symbol_width_spinbox">
10496
<property name="minimum">
10597
<number>4</number>
@@ -112,14 +104,20 @@
112104
</property>
113105
</widget>
114106
</item>
115-
<item row="1" column="0">
107+
<item row="5" column="0">
116108
<widget class="QLabel" name="label_3">
109+
<property name="minimumSize">
110+
<size>
111+
<width>0</width>
112+
<height>25</height>
113+
</size>
114+
</property>
117115
<property name="text">
118116
<string>Symbolien korkeus:</string>
119117
</property>
120118
</widget>
121119
</item>
122-
<item row="1" column="1">
120+
<item row="5" column="1">
123121
<widget class="QgsSpinBox" name="symbol_height_spinbox">
124122
<property name="minimum">
125123
<number>4</number>
@@ -132,21 +130,104 @@
132130
</property>
133131
</widget>
134132
</item>
135-
<item row="2" column="0">
136-
<widget class="QLabel" name="label_7">
133+
<item row="1" column="1">
134+
<widget class="QgsFontButton" name="heading_font_selection">
135+
<property name="minimumSize">
136+
<size>
137+
<width>0</width>
138+
<height>0</height>
139+
</size>
140+
</property>
141+
<property name="mode">
142+
<enum>QgsFontButton::ModeQFont</enum>
143+
</property>
144+
<property name="currentFont">
145+
<font>
146+
<pointsize>10</pointsize>
147+
<weight>75</weight>
148+
<bold>true</bold>
149+
</font>
150+
</property>
151+
</widget>
152+
</item>
153+
<item row="1" column="0">
154+
<widget class="QLabel" name="label_9">
137155
<property name="text">
138-
<string>X marginaali:</string>
156+
<string>Otsikoiden fontti:</string>
139157
</property>
140158
</widget>
141159
</item>
142160
<item row="3" column="0">
143-
<widget class="QLabel" name="label_8">
161+
<widget class="QLabel" name="label_10">
144162
<property name="text">
145-
<string>Y marginaali:</string>
163+
<string>Määräystekstien fontti:</string>
146164
</property>
147165
</widget>
148166
</item>
149-
<item row="2" column="1">
167+
<item row="3" column="1">
168+
<widget class="QgsFontButton" name="text_font_selection">
169+
<property name="minimumSize">
170+
<size>
171+
<width>0</width>
172+
<height>0</height>
173+
</size>
174+
</property>
175+
<property name="mode">
176+
<enum>QgsFontButton::ModeQFont</enum>
177+
</property>
178+
<property name="currentFont">
179+
<font>
180+
<pointsize>10</pointsize>
181+
</font>
182+
</property>
183+
</widget>
184+
</item>
185+
</layout>
186+
</widget>
187+
</item>
188+
<item>
189+
<widget class="QGroupBox" name="groupBox_3">
190+
<property name="title">
191+
<string>Kielet</string>
192+
</property>
193+
<layout class="QFormLayout" name="formLayout_3">
194+
<item row="0" column="0">
195+
<widget class="QLabel" name="label_5">
196+
<property name="text">
197+
<string>Kieli 1:</string>
198+
</property>
199+
</widget>
200+
</item>
201+
<item row="0" column="1">
202+
<widget class="CodeComboBox" name="language_1_selection"/>
203+
</item>
204+
<item row="1" column="0">
205+
<widget class="QLabel" name="label_6">
206+
<property name="text">
207+
<string>Kieli 2:</string>
208+
</property>
209+
</widget>
210+
</item>
211+
<item row="1" column="1">
212+
<widget class="CodeComboBox" name="language_2_selection"/>
213+
</item>
214+
</layout>
215+
</widget>
216+
</item>
217+
<item>
218+
<widget class="QGroupBox" name="groupBox_4">
219+
<property name="title">
220+
<string>Taitto</string>
221+
</property>
222+
<layout class="QFormLayout" name="formLayout_4">
223+
<item row="0" column="0">
224+
<widget class="QLabel" name="label_7">
225+
<property name="text">
226+
<string>X marginaali:</string>
227+
</property>
228+
</widget>
229+
</item>
230+
<item row="0" column="1">
150231
<widget class="QgsSpinBox" name="x_margins_spinbox">
151232
<property name="minimum">
152233
<number>1</number>
@@ -159,7 +240,14 @@
159240
</property>
160241
</widget>
161242
</item>
162-
<item row="3" column="1">
243+
<item row="1" column="0">
244+
<widget class="QLabel" name="label_8">
245+
<property name="text">
246+
<string>Y marginaali:</string>
247+
</property>
248+
</widget>
249+
</item>
250+
<item row="1" column="1">
163251
<widget class="QgsSpinBox" name="y_margins_spinbox">
164252
<property name="minimum">
165253
<number>1</number>
@@ -201,6 +289,11 @@
201289
</layout>
202290
</widget>
203291
<customwidgets>
292+
<customwidget>
293+
<class>QgsFontButton</class>
294+
<extends>QToolButton</extends>
295+
<header>qgsfontbutton.h</header>
296+
</customwidget>
204297
<customwidget>
205298
<class>QgsSpinBox</class>
206299
<extends>QSpinBox</extends>

0 commit comments

Comments
 (0)