Use both a colored border and an icon to indicate errors in line edits. Fixes #2007764 [Enhancement Request: Valid/invalid metadata display options](https://bugs.launchpad.net/calibre/+bug/2007764)

This commit is contained in:
Kovid Goyal 2023-04-02 11:24:27 +05:30
parent bcfb519afb
commit 02f50bf6ce
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 4 deletions

View File

@ -15,6 +15,7 @@ from qt.core import (
QIcon, QApplication, QKeyEvent)
from calibre.gui2 import config, question_dialog, gprefs, QT_HIDDEN_CLEAR_ACTION
from calibre.gui2.widgets import stylesheet_for_lineedit
from calibre.gui2.dialogs.saved_search_editor import SavedSearchEditor
from calibre.gui2.dialogs.search import SearchDialog
from calibre.utils.icu import primary_sort_key
@ -174,7 +175,7 @@ class SearchBox2(QComboBox): # {{{
def normalize_state(self):
self.setToolTip(self.tool_tip_text)
self.line_edit.setStyleSheet('')
self.setStyleSheet('')
self.show_parse_error_action(False)
def text(self):
@ -194,11 +195,9 @@ class SearchBox2(QComboBox): # {{{
self.setFocus(Qt.FocusReason.OtherFocusReason)
def show_parse_error_action(self, to_show, tooltip=''):
try:
if self.parse_error_action is not None:
self.parse_error_action.setVisible(to_show)
self.parse_error_action.setToolTip(tooltip)
except Exception:
pass
def search_done(self, ok):
if isinstance(ok, string_or_bytes):
@ -206,9 +205,14 @@ class SearchBox2(QComboBox): # {{{
self.show_parse_error_action(True, tooltip=ok)
ok = False
if not str(self.currentText()).strip():
self.setStyleSheet('')
self.clear(emit_search=False)
return
self._in_a_search = ok
if self.parse_error_action is not None and not ok:
self.setStyleSheet(stylesheet_for_lineedit(bool(ok), 'QComboBox'))
else:
self.setStyleSheet('')
# Comes from the lineEdit control
def key_pressed(self, event):

View File

@ -555,6 +555,14 @@ def setup_status_actions(self: QLineEdit):
self.status_actions[0].setVisible(False)
self.status_actions[1].setVisible(False)
def stylesheet_for_lineedit(ok, selector='QLineEdit') -> str:
if ok is None:
return ''
col = '#50c878' if ok else '#FF2400'
return f'{selector} {{ border: 2px solid {col}; border-radius: 3px }}'
def update_status_actions(self: QLineEdit, ok, tooltip: str = ''):
self.status_actions[0].setVisible(bool(ok))
self.status_actions[1].setVisible(not ok)
@ -564,6 +572,8 @@ def update_status_actions(self: QLineEdit, ok, tooltip: str = ''):
self.status_actions[1].setVisible(False)
else:
self.status_actions[1].setToolTip(tooltip)
self.setStyleSheet(stylesheet_for_lineedit(ok))
class LineEditIndicators: