From 0e5d622a4e963a2b95b1ad019b71950006950673 Mon Sep 17 00:00:00 2001 From: Miguel Jacq Date: Fri, 21 Nov 2025 10:30:40 +1100 Subject: [PATCH] Make it possible to change the font size for regular text --- CHANGELOG.md | 1 + bouquin/db.py | 1 + bouquin/locales/en.json | 2 ++ bouquin/main_window.py | 41 +++++++++++++++++++++++++++++++++++++- bouquin/markdown_editor.py | 6 +++--- bouquin/settings.py | 3 +++ bouquin/toolbar.py | 14 +++++++++++++ 7 files changed, 64 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ea07c2..268726b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ * Improve Statistics widget height * Improve SaveDialog widget width * Make Tags and TimeLog optional features that can be switched on/off in Settings (enabled by default) + * Make it possible to change regular text size # 0.4.1 diff --git a/bouquin/db.py b/bouquin/db.py index 37b56d8..6a862b5 100644 --- a/bouquin/db.py +++ b/bouquin/db.py @@ -64,6 +64,7 @@ class DBConfig: tags: bool = True time_log: bool = True locale: str = "en" + font_size: int = 11 class DBManager: diff --git a/bouquin/locales/en.json b/bouquin/locales/en.json index e367254..9ec462c 100644 --- a/bouquin/locales/en.json +++ b/bouquin/locales/en.json @@ -107,6 +107,8 @@ "toolbar_italic": "Italic", "toolbar_strikethrough": "Strikethrough", "toolbar_normal_paragraph_text": "Normal paragraph text", + "toolbar_font_smaller": "Smaller text", + "toolbar_font_larger": "Larger text", "toolbar_bulleted_list": "Bulleted list", "toolbar_numbered_list": "Numbered list", "toolbar_code_block": "Code block", diff --git a/bouquin/main_window.py b/bouquin/main_window.py index 97e5ccf..019a68d 100644 --- a/bouquin/main_window.py +++ b/bouquin/main_window.py @@ -92,6 +92,8 @@ class MainWindow(QMainWindow): else: self._try_connect() + self.settings = QSettings(APP_ORG, APP_NAME) + # ---- UI: Left fixed panel (calendar) + right editor ----------------- self.calendar = QCalendarWidget() self.calendar.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed) @@ -319,7 +321,6 @@ class MainWindow(QMainWindow): self.time_log.hide() # Restore window position from settings - self.settings = QSettings(APP_ORG, APP_NAME) self._restore_window_position() # re-apply all runtime color tweaks when theme changes @@ -485,6 +486,9 @@ class MainWindow(QMainWindow): editor = MarkdownEditor(self.themes) + # Apply user’s preferred font size + self._apply_font_size(editor) + # Set up the editor's event connections editor.currentCharFormatChanged.connect(lambda _f: self._sync_toolbar()) editor.cursorPositionChanged.connect(self._sync_toolbar) @@ -912,6 +916,15 @@ class MainWindow(QMainWindow): pass # ----------------- Some theme helpers -------------------# + def _apply_font_size(self, editor: MarkdownEditor) -> None: + """Apply the saved font size to a newly created editor.""" + size = self.cfg.font_size + editor.qfont.setPointSize(size) + editor.setFont(editor.qfont) + # save size to settings + self.cfg.font_size = size + save_db_config(self.cfg) + def _retheme_overrides(self): self._apply_calendar_text_colors() self._apply_search_highlights(getattr(self, "_search_highlighted_dates", set())) @@ -995,6 +1008,8 @@ class MainWindow(QMainWindow): self._tb_numbers = lambda: self._call_editor("toggle_numbers") self._tb_checkboxes = lambda: self._call_editor("toggle_checkboxes") self._tb_alarm = self._on_alarm_requested + self._tb_font_larger = self._on_font_larger_requested + self._tb_font_smaller = self._on_font_smaller_requested tb.boldRequested.connect(self._tb_bold) tb.italicRequested.connect(self._tb_italic) @@ -1007,6 +1022,8 @@ class MainWindow(QMainWindow): tb.alarmRequested.connect(self._tb_alarm) tb.insertImageRequested.connect(self._on_insert_image) tb.historyRequested.connect(self._open_history) + tb.fontSizeLargerRequested.connect(self._tb_font_larger) + tb.fontSizeSmallerRequested.connect(self._tb_font_smaller) self._toolbar_bound = True @@ -1052,6 +1069,28 @@ class MainWindow(QMainWindow): self.toolBar.actBullets.setChecked(bool(bullets_on)) self.toolBar.actNumbers.setChecked(bool(numbers_on)) + def _change_font_size(self, delta: int) -> None: + """Change font size for all editor tabs and save the setting.""" + old_size = self.cfg.font_size + new_size = old_size + delta + + self.cfg.font_size = new_size + save_db_config(self.cfg) + + # Apply font size change to all open editors + for i in range(self.tab_widget.count()): + ed = self.tab_widget.widget(i) + if not isinstance(ed, MarkdownEditor): + continue + ed.qfont.setPointSize(new_size) + ed.setFont(ed.qfont) + + def _on_font_larger_requested(self) -> None: + self._change_font_size(+1) + + def _on_font_smaller_requested(self) -> None: + self._change_font_size(-1) + # ----------- Alarms handler ------------# def _on_alarm_requested(self): """Create a one-shot reminder based on the current line in the editor.""" diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index 7fea40c..95b099d 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -41,9 +41,9 @@ class MarkdownEditor(QTextEdit): self.setAcceptRichText(False) # Normal text - font = QFont() - font.setPointSize(10) - self.setFont(font) + self.qfont = QFont() + self.qfont.setPointSize(11) + self.setFont(self.qfont) self._apply_line_spacing() # 1.25× initial spacing diff --git a/bouquin/settings.py b/bouquin/settings.py index 5a52f18..ad5436d 100644 --- a/bouquin/settings.py +++ b/bouquin/settings.py @@ -44,6 +44,7 @@ def load_db_config() -> DBConfig: tags = s.value("ui/tags", True, type=bool) time_log = s.value("ui/time_log", True, type=bool) locale = s.value("ui/locale", "en", type=str) + font_size = s.value("ui/font_size", 11, type=int) return DBConfig( path=path, key=key, @@ -53,6 +54,7 @@ def load_db_config() -> DBConfig: tags=tags, time_log=time_log, locale=locale, + font_size=font_size, ) @@ -66,3 +68,4 @@ def save_db_config(cfg: DBConfig) -> None: s.setValue("ui/tags", str(cfg.tags)) s.setValue("ui/time_log", str(cfg.time_log)) s.setValue("ui/locale", str(cfg.locale)) + s.setValue("ui/font_size", str(cfg.font_size)) diff --git a/bouquin/toolbar.py b/bouquin/toolbar.py index 8179925..afff8f6 100644 --- a/bouquin/toolbar.py +++ b/bouquin/toolbar.py @@ -19,6 +19,8 @@ class ToolBar(QToolBar): historyRequested = Signal() insertImageRequested = Signal() alarmRequested = Signal() + fontSizeLargerRequested = Signal() + fontSizeSmallerRequested = Signal() def __init__(self, parent=None): super().__init__(strings._("toolbar_format"), parent) @@ -73,6 +75,14 @@ class ToolBar(QToolBar): self.actNormal.setShortcut("Ctrl+N") self.actNormal.triggered.connect(lambda: self.headingRequested.emit(0)) + self.actFontSmaller = QAction("N-", self) + self.actFontSmaller.setToolTip(strings._("toolbar_font_smaller")) + self.actFontSmaller.triggered.connect(self.fontSizeSmallerRequested) + + self.actFontLarger = QAction("N+", self) + self.actFontLarger.setToolTip(strings._("toolbar_font_larger")) + self.actFontLarger.triggered.connect(self.fontSizeLargerRequested) + # Lists self.actBullets = QAction("•", self) self.actBullets.setToolTip(strings._("toolbar_bulleted_list")) @@ -132,6 +142,8 @@ class ToolBar(QToolBar): self.actH2, self.actH3, self.actNormal, + self.actFontSmaller, + self.actFontLarger, self.actBullets, self.actNumbers, self.actCheckboxes, @@ -154,6 +166,8 @@ class ToolBar(QToolBar): self._style_letter_button(self.actH2, "H2") self._style_letter_button(self.actH3, "H3") self._style_letter_button(self.actNormal, "N") + self._style_letter_button(self.actFontSmaller, "N-") + self._style_letter_button(self.actFontLarger, "N+") # Lists self._style_letter_button(self.actBullets, "•")