Add ability to storage images in the page

This commit is contained in:
Miguel Jacq 2025-11-04 15:57:41 +11:00
parent 7548f33de4
commit 74a75eadcb
Signed by: mig5
GPG key ID: 59B3F0C24135C6A9
5 changed files with 331 additions and 5 deletions

View file

@ -105,8 +105,8 @@ class _LockOverlay(QWidget):
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.setWindowTitle(APP_NAME)
self.setMinimumSize(1000, 650)
@ -160,6 +160,7 @@ class MainWindow(QMainWindow):
self.toolBar.numbersRequested.connect(self.editor.toggle_numbers)
self.toolBar.alignRequested.connect(self.editor.setAlignment)
self.toolBar.historyRequested.connect(self._open_history)
self.toolBar.insertImageRequested.connect(self._on_insert_image)
self.editor.currentCharFormatChanged.connect(lambda _f: self._sync_toolbar())
self.editor.cursorPositionChanged.connect(self._sync_toolbar)
@ -446,7 +447,7 @@ class MainWindow(QMainWindow):
"""
if not self._dirty and not explicit:
return
text = self.editor.toHtml()
text = self.editor.to_html_with_embedded_images()
try:
self.db.save_new_version(date_iso, text, note)
except Exception as e:
@ -489,6 +490,18 @@ class MainWindow(QMainWindow):
self._load_selected_date(date_iso)
self._refresh_calendar_marks()
def _on_insert_image(self):
# Let the user pick one or many images
paths, _ = QFileDialog.getOpenFileNames(
self,
"Insert image(s)",
"",
"Images (*.png *.jpg *.jpeg *.bmp *.gif *.webp)",
)
if not paths:
return
self.editor.insert_images(paths) # call into the editor
# ----------- Settings handler ------------#
def _open_settings(self):
dlg = SettingsDialog(self.cfg, self.db, self)