diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a1f513..3e2d232 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ # 0.5.2 * Update icon again to remove background + * Adjust History icon and reorder toolbar items + * Try to address checkbox/bullet size issues (again) # 0.5.1 diff --git a/bouquin/markdown_editor.py b/bouquin/markdown_editor.py index 27850f6..ac8a849 100644 --- a/bouquin/markdown_editor.py +++ b/bouquin/markdown_editor.py @@ -119,6 +119,22 @@ class MarkdownEditor(QTextEdit): self._apply_code_block_spacing() QTimer.singleShot(0, self._update_code_block_row_backgrounds) + def setFont(self, font: QFont) -> None: # type: ignore[override] + """ + Ensure that whenever the base editor font changes, our highlighter + re-computes checkbox / bullet formats. + """ + # Keep qfont in sync + self.qfont = QFont(font) + super().setFont(self.qfont) + + # If the highlighter is already attached, let it rebuild its formats + highlighter = getattr(self, "highlighter", None) + if highlighter is not None: + refresh = getattr(highlighter, "refresh_for_font_change", None) + if callable(refresh): + refresh() + def showEvent(self, e): super().showEvent(e) # First time the widget is shown, Qt may rebuild layout once more. diff --git a/bouquin/markdown_highlighter.py b/bouquin/markdown_highlighter.py index 7674d1b..f9826ff 100644 --- a/bouquin/markdown_highlighter.py +++ b/bouquin/markdown_highlighter.py @@ -6,6 +6,7 @@ from PySide6.QtGui import ( QColor, QFont, QFontDatabase, + QFontMetrics, QGuiApplication, QPalette, QSyntaxHighlighter, @@ -33,6 +34,14 @@ class MarkdownHighlighter(QSyntaxHighlighter): self._setup_formats() self.rehighlight() + def refresh_for_font_change(self) -> None: + """ + Called when the editor's base font changes (zoom / settings). + It rebuilds any formats that depend on the editor font metrics. + """ + self._setup_formats() + self.rehighlight() + def _setup_formats(self): """Setup text formats for different markdown elements.""" @@ -110,8 +119,21 @@ class MarkdownHighlighter(QSyntaxHighlighter): # Use Symbols font for checkbox and bullet glyphs if present if self._editor is not None and hasattr(self._editor, "symbols_font_family"): - base_size = self._editor.qfont.pointSize() - symbols_font = QFont(self._editor.symbols_font_family, base_size) + base_font = QFont(self._editor.qfont) # copy of editor font + symbols_font = QFont(self._editor.symbols_font_family) + symbols_font.setPointSizeF(base_font.pointSizeF()) + + base_metrics = QFontMetrics(base_font) + sym_metrics = QFontMetrics(symbols_font) + + # If Symbols glyphs are noticeably shorter than the text, + # scale them up so the visual heights roughly match. + if sym_metrics.height() > 0: + ratio = base_metrics.height() / sym_metrics.height() + if ratio > 1.05: # more than ~5% smaller + ratio = min(ratio, 1.4) # Oh, Tod, Tod. Don't overdo it. + symbols_font.setPointSizeF(symbols_font.pointSizeF() * ratio) + self.checkbox_format.setFont(symbols_font) self.bullet_format.setFont(symbols_font) diff --git a/bouquin/toolbar.py b/bouquin/toolbar.py index cba1820..c4274a4 100644 --- a/bouquin/toolbar.py +++ b/bouquin/toolbar.py @@ -100,6 +100,17 @@ class ToolBar(QToolBar): self.actCheckboxes.setToolTip(strings._("toolbar_toggle_checkboxes")) self.actCheckboxes.triggered.connect(self.checkboxesRequested) + # Images + self.actInsertImg = QAction("📸", self) + self.actInsertImg.setToolTip(strings._("insert_images")) + self.actInsertImg.setShortcut("Ctrl+Shift+I") + self.actInsertImg.triggered.connect(self.insertImageRequested) + + # History button + self.actHistory = QAction("🔁", self) + self.actHistory.setToolTip(strings._("history")) + self.actHistory.triggered.connect(self.historyRequested) + # Alarm / reminder self.actAlarm = QAction("⏰", self) self.actAlarm.setToolTip(strings._("toolbar_alarm")) @@ -115,17 +126,6 @@ class ToolBar(QToolBar): self.actTable.setToolTip(strings._("toolbar_insert_table")) self.actTable.triggered.connect(self.tableRequested) - # Images - self.actInsertImg = QAction("📸", self) - self.actInsertImg.setToolTip(strings._("insert_images")) - self.actInsertImg.setShortcut("Ctrl+Shift+I") - self.actInsertImg.triggered.connect(self.insertImageRequested) - - # History button - self.actHistory = QAction("⎌", self) - self.actHistory.setToolTip(strings._("history")) - self.actHistory.triggered.connect(self.historyRequested) - # Set exclusive buttons in QActionGroups self.grpHeadings = QActionGroup(self) self.grpHeadings.setExclusive(True) @@ -162,10 +162,10 @@ class ToolBar(QToolBar): self.actBullets, self.actNumbers, self.actCheckboxes, - self.actAlarm, - self.actTimer, self.actTable, self.actInsertImg, + self.actAlarm, + self.actTimer, self.actHistory, ] ) @@ -195,7 +195,7 @@ class ToolBar(QToolBar): self._style_letter_button(self.actTable, "⊞") # History - self._style_letter_button(self.actHistory, "⎌") + self._style_letter_button(self.actHistory, "🔁") def _style_letter_button( self,