mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Notes should be rendered the same way in the viewer highlights panel and the browse annotations details panel
This commit is contained in:
parent
eb7bdaca4e
commit
c82c7d1a27
@ -19,6 +19,19 @@ from calibre.gui2.viewer.widgets import ResultsDelegate, SearchBox
|
|||||||
from calibre.gui2.widgets2 import Dialog
|
from calibre.gui2.widgets2 import Dialog
|
||||||
|
|
||||||
|
|
||||||
|
def render_notes(notes, tag='p'):
|
||||||
|
current_lines = []
|
||||||
|
for line in notes.splitlines():
|
||||||
|
if line:
|
||||||
|
current_lines.append(line)
|
||||||
|
else:
|
||||||
|
if current_lines:
|
||||||
|
yield '<{0}>{1}</{0}>'.format(tag, '\n'.join(current_lines))
|
||||||
|
current_lines = []
|
||||||
|
if current_lines:
|
||||||
|
yield '<{0}>{1}</{0}>'.format(tag, '\n'.join(current_lines))
|
||||||
|
|
||||||
|
|
||||||
def friendly_username(user_type, user):
|
def friendly_username(user_type, user):
|
||||||
key = user_type, user
|
key = user_type, user
|
||||||
if key == ('web', '*'):
|
if key == ('web', '*'):
|
||||||
@ -459,16 +472,7 @@ class DetailsPanel(QWidget):
|
|||||||
notes = annot.get('notes')
|
notes = annot.get('notes')
|
||||||
if notes:
|
if notes:
|
||||||
p(_('Notes'), 'h4')
|
p(_('Notes'), 'h4')
|
||||||
current_lines = []
|
paras.extend(render_notes(notes))
|
||||||
for line in notes.splitlines():
|
|
||||||
if line:
|
|
||||||
current_lines.append(line)
|
|
||||||
else:
|
|
||||||
if current_lines:
|
|
||||||
p('\n'.join(current_lines))
|
|
||||||
current_lines = []
|
|
||||||
if current_lines:
|
|
||||||
p('\n'.join(current_lines))
|
|
||||||
|
|
||||||
annot_text += '\n'.join(paras)
|
annot_text += '\n'.join(paras)
|
||||||
date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString(Qt.SystemLocaleShortDate)
|
date = QDateTime.fromString(annot['timestamp'], Qt.ISODate).toLocalTime().toString(Qt.SystemLocaleShortDate)
|
||||||
|
@ -15,7 +15,7 @@ from PyQt5.Qt import (
|
|||||||
from calibre.constants import plugins
|
from calibre.constants import plugins
|
||||||
from calibre.ebooks.epub.cfi.parse import cfi_sort_key
|
from calibre.ebooks.epub.cfi.parse import cfi_sort_key
|
||||||
from calibre.gui2 import choose_save_file, error_dialog, question_dialog
|
from calibre.gui2 import choose_save_file, error_dialog, question_dialog
|
||||||
from calibre.gui2.library.annotations import Details
|
from calibre.gui2.library.annotations import Details, render_notes
|
||||||
from calibre.gui2.viewer.config import vprefs
|
from calibre.gui2.viewer.config import vprefs
|
||||||
from calibre.gui2.viewer.search import SearchInput
|
from calibre.gui2.viewer.search import SearchInput
|
||||||
from calibre.gui2.viewer.shortcuts import index_to_key_sequence
|
from calibre.gui2.viewer.shortcuts import index_to_key_sequence
|
||||||
@ -226,6 +226,7 @@ class NotesDisplay(QWidget):
|
|||||||
h.setContentsMargins(0, 0, 0, 0)
|
h.setContentsMargins(0, 0, 0, 0)
|
||||||
self.browser = nd = Details(self)
|
self.browser = nd = Details(self)
|
||||||
h.addWidget(nd)
|
h.addWidget(nd)
|
||||||
|
self.current_notes = ''
|
||||||
self.edit_button = eb = QToolButton(self)
|
self.edit_button = eb = QToolButton(self)
|
||||||
eb.setIcon(QIcon(I('modified.png')))
|
eb.setIcon(QIcon(I('modified.png')))
|
||||||
eb.setToolTip(_('Edit the notes for this highlight'))
|
eb.setToolTip(_('Edit the notes for this highlight'))
|
||||||
@ -235,13 +236,14 @@ class NotesDisplay(QWidget):
|
|||||||
def show_notes(self, text=''):
|
def show_notes(self, text=''):
|
||||||
text = (text or '').strip()
|
text = (text or '').strip()
|
||||||
self.setVisible(bool(text))
|
self.setVisible(bool(text))
|
||||||
self.browser.setPlainText(text)
|
self.current_notes = text
|
||||||
|
self.browser.setHtml('\n'.join(render_notes(text)))
|
||||||
h = self.browser.document().size().height() + 8
|
h = self.browser.document().size().height() + 8
|
||||||
self.browser.setMaximumHeight(h)
|
self.browser.setMaximumHeight(h)
|
||||||
self.setMaximumHeight(max(self.edit_button.sizeHint().height() + 4, h))
|
self.setMaximumHeight(max(self.edit_button.sizeHint().height() + 4, h))
|
||||||
|
|
||||||
def edit_notes(self):
|
def edit_notes(self):
|
||||||
current_text = self.browser.toPlainText()
|
current_text = self.current_notes
|
||||||
d = NotesEditDialog(current_text, self)
|
d = NotesEditDialog(current_text, self)
|
||||||
if d.exec_() == d.Accepted and d.notes != current_text:
|
if d.exec_() == d.Accepted and d.notes != current_text:
|
||||||
self.notes_edited.emit(d.notes)
|
self.notes_edited.emit(d.notes)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user