Simplify notes display widget

This commit is contained in:
Kovid Goyal 2020-09-02 10:24:53 +05:30
parent cac8628fa0
commit 99c1292a55
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,7 +8,7 @@ from itertools import chain
from PyQt5.Qt import ( from PyQt5.Qt import (
QFont, QHBoxLayout, QIcon, QItemSelectionModel, QKeySequence, QLabel, QFont, QHBoxLayout, QIcon, QItemSelectionModel, QKeySequence, QLabel,
QPushButton, Qt, QTextEdit, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, QPushButton, Qt, QTextEdit, QTreeWidget, QTreeWidgetItem, QVBoxLayout, QWidget, QSizePolicy,
pyqtSignal pyqtSignal
) )
@ -220,17 +220,14 @@ class NotesEditDialog(Dialog):
return self.qte.toPlainText().rstrip() return self.qte.toPlainText().rstrip()
class NotesDisplay(QWidget): class NotesDisplay(Details):
notes_edited = pyqtSignal(object) notes_edited = pyqtSignal(object)
def __init__(self, parent=None): def __init__(self, parent=None):
QWidget.__init__(self, parent) Details.__init__(self, parent)
h = QHBoxLayout(self) self.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum)
h.setContentsMargins(0, 0, 0, 0) self.anchorClicked.connect(self.edit_notes)
self.browser = nd = Details(self)
self.browser.anchorClicked.connect(self.edit_notes)
h.addWidget(nd)
self.current_notes = '' self.current_notes = ''
def show_notes(self, text=''): def show_notes(self, text=''):
@ -238,9 +235,9 @@ class NotesDisplay(QWidget):
self.setVisible(bool(text)) self.setVisible(bool(text))
self.current_notes = text self.current_notes = text
html = '\n'.join(render_notes(text)) html = '\n'.join(render_notes(text))
self.browser.setHtml('<div><a href="edit://moo" style="text-decoration: none">{}</a></div>{}'.format(_('Edit notes'), html)) self.setHtml('<div><a href="edit://moo" style="text-decoration: none">{}</a></div>{}'.format(_('Edit notes'), html))
h = self.browser.document().size().height() + 8 h = self.document().size().height() + 2
self.browser.setMaximumHeight(h) self.setMaximumHeight(h)
def edit_notes(self): def edit_notes(self):
current_text = self.current_notes current_text = self.current_notes