Fix #1864152 [[Enhancement] Look of the Choose Virtual library](https://bugs.launchpad.net/calibre/+bug/1864152)

This commit is contained in:
Kovid Goyal 2020-02-21 11:47:40 +05:30
parent 6e8a80341b
commit f77c3bf3a6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 14 additions and 8 deletions

View File

@ -495,15 +495,15 @@ class SearchRestrictionMixin(object):
self._remove_vl(name, reapply=True) self._remove_vl(name, reapply=True)
def choose_vl_triggerred(self): def choose_vl_triggerred(self):
from calibre.gui2.tweak_book.widgets import QuickOpen, Results from calibre.gui2.tweak_book.widgets import QuickOpen, emphasis_style
db = self.library_view.model().db db = self.library_view.model().db
virt_libs = db.prefs.get('virtual_libraries', {}) virt_libs = db.prefs.get('virtual_libraries', {})
if not virt_libs: if not virt_libs:
return error_dialog(self, _('No virtual libraries'), _( return error_dialog(self, _('No virtual libraries'), _(
'No Virtual libraries present, create some first'), show=True) 'No Virtual libraries present, create some first'), show=True)
example = '<pre>{0}S{1}ome {0}B{1}ook {0}C{1}ollection</pre>'.format( example = '<pre>{0}S{1}ome {0}B{1}ook {0}C{1}ollection</pre>'.format(
'<span style="%s">' % Results.EMPH, '</span>') '<span style="%s">' % emphasis_style(), '</span>')
chars = '<pre style="%s">sbc</pre>' % Results.EMPH chars = '<pre style="%s">sbc</pre>' % emphasis_style()
help_text = _('''<p>Quickly choose a Virtual library by typing in just a few characters from the file name into the field above. help_text = _('''<p>Quickly choose a Virtual library by typing in just a few characters from the file name into the field above.
For example, if want to choose the VL: For example, if want to choose the VL:
{example} {example}

View File

@ -275,9 +275,13 @@ def make_highlighted_text(emph, text, positions):
return text return text
def emphasis_style():
pal = QApplication.instance().palette()
return 'color: {}; font-weight: bold'.format(pal.color(pal.Link).name())
class Results(QWidget): class Results(QWidget):
EMPH = "color:magenta; font-weight:bold"
MARGIN = 4 MARGIN = 4
item_selected = pyqtSignal() item_selected = pyqtSignal()
@ -355,7 +359,7 @@ class Results(QWidget):
self.update() self.update()
def make_text(self, text, positions): def make_text(self, text, positions):
text = QStaticText(make_highlighted_text(self.EMPH, text, positions)) text = QStaticText(make_highlighted_text(emphasis_style(), text, positions))
text.setTextOption(self.text_option) text.setTextOption(self.text_option)
text.setTextFormat(Qt.RichText) text.setTextFormat(Qt.RichText)
return text return text
@ -423,8 +427,8 @@ class QuickOpen(Dialog):
def default_help_text(self): def default_help_text(self):
example = '<pre>{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg</pre>'.format( example = '<pre>{0}i{1}mages/{0}c{1}hapter1/{0}s{1}cene{0}3{1}.jpg</pre>'.format(
'<span style="%s">' % Results.EMPH, '</span>') '<span style="%s">' % emphasis_style(), '</span>')
chars = '<pre style="%s">ics3</pre>' % Results.EMPH chars = '<pre style="%s">ics3</pre>' % emphasis_style()
return _('''<p>Quickly choose a file by typing in just a few characters from the file name into the field above. return _('''<p>Quickly choose a file by typing in just a few characters from the file name into the field above.
For example, if want to choose the file: For example, if want to choose the file:
@ -439,6 +443,8 @@ class QuickOpen(Dialog):
self.text = t = QLineEdit(self) self.text = t = QLineEdit(self)
t.textEdited.connect(self.update_matches) t.textEdited.connect(self.update_matches)
t.setClearButtonEnabled(True)
t.setPlaceholderText(_('Search'))
l.addWidget(t, alignment=Qt.AlignTop) l.addWidget(t, alignment=Qt.AlignTop)
self.help_label = hl = QLabel(self.help_text) self.help_label = hl = QLabel(self.help_text)
@ -509,7 +515,7 @@ class NamesDelegate(QStyledItemDelegate):
to.setWrapMode(to.NoWrap) to.setWrapMode(to.NoWrap)
to.setAlignment(Qt.AlignLeft | Qt.AlignVCenter) to.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
positions = sorted(set(positions) - {-1}, reverse=True) positions = sorted(set(positions) - {-1}, reverse=True)
text = '<body>%s</body>' % make_highlighted_text(Results.EMPH, text, positions) text = '<body>%s</body>' % make_highlighted_text(emphasis_style(), text, positions)
doc = QTextDocument() doc = QTextDocument()
c = 'rgb(%d, %d, %d)'%c.getRgb()[:3] c = 'rgb(%d, %d, %d)'%c.getRgb()[:3]
doc.setDefaultStyleSheet(' body { color: %s }'%c) doc.setDefaultStyleSheet(' body { color: %s }'%c)