Make it possible to change the font size for regular text
This commit is contained in:
parent
0923fb4395
commit
0e5d622a4e
7 changed files with 64 additions and 4 deletions
|
|
@ -3,6 +3,7 @@
|
||||||
* Improve Statistics widget height
|
* Improve Statistics widget height
|
||||||
* Improve SaveDialog widget width
|
* Improve SaveDialog widget width
|
||||||
* Make Tags and TimeLog optional features that can be switched on/off in Settings (enabled by default)
|
* 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
|
# 0.4.1
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -64,6 +64,7 @@ class DBConfig:
|
||||||
tags: bool = True
|
tags: bool = True
|
||||||
time_log: bool = True
|
time_log: bool = True
|
||||||
locale: str = "en"
|
locale: str = "en"
|
||||||
|
font_size: int = 11
|
||||||
|
|
||||||
|
|
||||||
class DBManager:
|
class DBManager:
|
||||||
|
|
|
||||||
|
|
@ -107,6 +107,8 @@
|
||||||
"toolbar_italic": "Italic",
|
"toolbar_italic": "Italic",
|
||||||
"toolbar_strikethrough": "Strikethrough",
|
"toolbar_strikethrough": "Strikethrough",
|
||||||
"toolbar_normal_paragraph_text": "Normal paragraph text",
|
"toolbar_normal_paragraph_text": "Normal paragraph text",
|
||||||
|
"toolbar_font_smaller": "Smaller text",
|
||||||
|
"toolbar_font_larger": "Larger text",
|
||||||
"toolbar_bulleted_list": "Bulleted list",
|
"toolbar_bulleted_list": "Bulleted list",
|
||||||
"toolbar_numbered_list": "Numbered list",
|
"toolbar_numbered_list": "Numbered list",
|
||||||
"toolbar_code_block": "Code block",
|
"toolbar_code_block": "Code block",
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ class MainWindow(QMainWindow):
|
||||||
else:
|
else:
|
||||||
self._try_connect()
|
self._try_connect()
|
||||||
|
|
||||||
|
self.settings = QSettings(APP_ORG, APP_NAME)
|
||||||
|
|
||||||
# ---- UI: Left fixed panel (calendar) + right editor -----------------
|
# ---- UI: Left fixed panel (calendar) + right editor -----------------
|
||||||
self.calendar = QCalendarWidget()
|
self.calendar = QCalendarWidget()
|
||||||
self.calendar.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
self.calendar.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
|
||||||
|
|
@ -319,7 +321,6 @@ class MainWindow(QMainWindow):
|
||||||
self.time_log.hide()
|
self.time_log.hide()
|
||||||
|
|
||||||
# Restore window position from settings
|
# Restore window position from settings
|
||||||
self.settings = QSettings(APP_ORG, APP_NAME)
|
|
||||||
self._restore_window_position()
|
self._restore_window_position()
|
||||||
|
|
||||||
# re-apply all runtime color tweaks when theme changes
|
# re-apply all runtime color tweaks when theme changes
|
||||||
|
|
@ -485,6 +486,9 @@ class MainWindow(QMainWindow):
|
||||||
|
|
||||||
editor = MarkdownEditor(self.themes)
|
editor = MarkdownEditor(self.themes)
|
||||||
|
|
||||||
|
# Apply user’s preferred font size
|
||||||
|
self._apply_font_size(editor)
|
||||||
|
|
||||||
# Set up the editor's event connections
|
# Set up the editor's event connections
|
||||||
editor.currentCharFormatChanged.connect(lambda _f: self._sync_toolbar())
|
editor.currentCharFormatChanged.connect(lambda _f: self._sync_toolbar())
|
||||||
editor.cursorPositionChanged.connect(self._sync_toolbar)
|
editor.cursorPositionChanged.connect(self._sync_toolbar)
|
||||||
|
|
@ -912,6 +916,15 @@ class MainWindow(QMainWindow):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# ----------------- Some theme helpers -------------------#
|
# ----------------- 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):
|
def _retheme_overrides(self):
|
||||||
self._apply_calendar_text_colors()
|
self._apply_calendar_text_colors()
|
||||||
self._apply_search_highlights(getattr(self, "_search_highlighted_dates", set()))
|
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_numbers = lambda: self._call_editor("toggle_numbers")
|
||||||
self._tb_checkboxes = lambda: self._call_editor("toggle_checkboxes")
|
self._tb_checkboxes = lambda: self._call_editor("toggle_checkboxes")
|
||||||
self._tb_alarm = self._on_alarm_requested
|
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.boldRequested.connect(self._tb_bold)
|
||||||
tb.italicRequested.connect(self._tb_italic)
|
tb.italicRequested.connect(self._tb_italic)
|
||||||
|
|
@ -1007,6 +1022,8 @@ class MainWindow(QMainWindow):
|
||||||
tb.alarmRequested.connect(self._tb_alarm)
|
tb.alarmRequested.connect(self._tb_alarm)
|
||||||
tb.insertImageRequested.connect(self._on_insert_image)
|
tb.insertImageRequested.connect(self._on_insert_image)
|
||||||
tb.historyRequested.connect(self._open_history)
|
tb.historyRequested.connect(self._open_history)
|
||||||
|
tb.fontSizeLargerRequested.connect(self._tb_font_larger)
|
||||||
|
tb.fontSizeSmallerRequested.connect(self._tb_font_smaller)
|
||||||
|
|
||||||
self._toolbar_bound = True
|
self._toolbar_bound = True
|
||||||
|
|
||||||
|
|
@ -1052,6 +1069,28 @@ class MainWindow(QMainWindow):
|
||||||
self.toolBar.actBullets.setChecked(bool(bullets_on))
|
self.toolBar.actBullets.setChecked(bool(bullets_on))
|
||||||
self.toolBar.actNumbers.setChecked(bool(numbers_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 ------------#
|
# ----------- Alarms handler ------------#
|
||||||
def _on_alarm_requested(self):
|
def _on_alarm_requested(self):
|
||||||
"""Create a one-shot reminder based on the current line in the editor."""
|
"""Create a one-shot reminder based on the current line in the editor."""
|
||||||
|
|
|
||||||
|
|
@ -41,9 +41,9 @@ class MarkdownEditor(QTextEdit):
|
||||||
self.setAcceptRichText(False)
|
self.setAcceptRichText(False)
|
||||||
|
|
||||||
# Normal text
|
# Normal text
|
||||||
font = QFont()
|
self.qfont = QFont()
|
||||||
font.setPointSize(10)
|
self.qfont.setPointSize(11)
|
||||||
self.setFont(font)
|
self.setFont(self.qfont)
|
||||||
|
|
||||||
self._apply_line_spacing() # 1.25× initial spacing
|
self._apply_line_spacing() # 1.25× initial spacing
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,7 @@ def load_db_config() -> DBConfig:
|
||||||
tags = s.value("ui/tags", True, type=bool)
|
tags = s.value("ui/tags", True, type=bool)
|
||||||
time_log = s.value("ui/time_log", True, type=bool)
|
time_log = s.value("ui/time_log", True, type=bool)
|
||||||
locale = s.value("ui/locale", "en", type=str)
|
locale = s.value("ui/locale", "en", type=str)
|
||||||
|
font_size = s.value("ui/font_size", 11, type=int)
|
||||||
return DBConfig(
|
return DBConfig(
|
||||||
path=path,
|
path=path,
|
||||||
key=key,
|
key=key,
|
||||||
|
|
@ -53,6 +54,7 @@ def load_db_config() -> DBConfig:
|
||||||
tags=tags,
|
tags=tags,
|
||||||
time_log=time_log,
|
time_log=time_log,
|
||||||
locale=locale,
|
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/tags", str(cfg.tags))
|
||||||
s.setValue("ui/time_log", str(cfg.time_log))
|
s.setValue("ui/time_log", str(cfg.time_log))
|
||||||
s.setValue("ui/locale", str(cfg.locale))
|
s.setValue("ui/locale", str(cfg.locale))
|
||||||
|
s.setValue("ui/font_size", str(cfg.font_size))
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@ class ToolBar(QToolBar):
|
||||||
historyRequested = Signal()
|
historyRequested = Signal()
|
||||||
insertImageRequested = Signal()
|
insertImageRequested = Signal()
|
||||||
alarmRequested = Signal()
|
alarmRequested = Signal()
|
||||||
|
fontSizeLargerRequested = Signal()
|
||||||
|
fontSizeSmallerRequested = Signal()
|
||||||
|
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(strings._("toolbar_format"), parent)
|
super().__init__(strings._("toolbar_format"), parent)
|
||||||
|
|
@ -73,6 +75,14 @@ class ToolBar(QToolBar):
|
||||||
self.actNormal.setShortcut("Ctrl+N")
|
self.actNormal.setShortcut("Ctrl+N")
|
||||||
self.actNormal.triggered.connect(lambda: self.headingRequested.emit(0))
|
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
|
# Lists
|
||||||
self.actBullets = QAction("•", self)
|
self.actBullets = QAction("•", self)
|
||||||
self.actBullets.setToolTip(strings._("toolbar_bulleted_list"))
|
self.actBullets.setToolTip(strings._("toolbar_bulleted_list"))
|
||||||
|
|
@ -132,6 +142,8 @@ class ToolBar(QToolBar):
|
||||||
self.actH2,
|
self.actH2,
|
||||||
self.actH3,
|
self.actH3,
|
||||||
self.actNormal,
|
self.actNormal,
|
||||||
|
self.actFontSmaller,
|
||||||
|
self.actFontLarger,
|
||||||
self.actBullets,
|
self.actBullets,
|
||||||
self.actNumbers,
|
self.actNumbers,
|
||||||
self.actCheckboxes,
|
self.actCheckboxes,
|
||||||
|
|
@ -154,6 +166,8 @@ class ToolBar(QToolBar):
|
||||||
self._style_letter_button(self.actH2, "H2")
|
self._style_letter_button(self.actH2, "H2")
|
||||||
self._style_letter_button(self.actH3, "H3")
|
self._style_letter_button(self.actH3, "H3")
|
||||||
self._style_letter_button(self.actNormal, "N")
|
self._style_letter_button(self.actNormal, "N")
|
||||||
|
self._style_letter_button(self.actFontSmaller, "N-")
|
||||||
|
self._style_letter_button(self.actFontLarger, "N+")
|
||||||
|
|
||||||
# Lists
|
# Lists
|
||||||
self._style_letter_button(self.actBullets, "•")
|
self._style_letter_button(self.actBullets, "•")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue