mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement bug #810: Search can be as you type or only on Enter/Return.
This commit is contained in:
parent
ccdc693b97
commit
21140bc72b
@ -71,6 +71,9 @@ def _config():
|
||||
help='Show donation button')
|
||||
c.add_opt('asked_library_thing_password', default=False,
|
||||
help='Asked library thing password at least once.')
|
||||
c.add_opt('search_as_you_type', default=True,
|
||||
help='Start searching as you type. If this is disabled then seaerch will '
|
||||
'only take place when the Enter or Return key is pressed.')
|
||||
return ConfigProxy(c)
|
||||
|
||||
config = _config()
|
||||
|
@ -437,6 +437,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
self.password.setText(opts.password if opts.password else '')
|
||||
self.auto_launch.setChecked(config['autolaunch_server'])
|
||||
self.systray_icon.setChecked(config['systray_icon'])
|
||||
self.search_as_you_type.setChecked(config['search_as_you_type'])
|
||||
self.sync_news.setChecked(config['upload_news_to_device'])
|
||||
self.delete_news.setChecked(config['delete_news_from_library_on_upload'])
|
||||
p = {'normal':0, 'high':1, 'low':2}[prefs['worker_process_priority']]
|
||||
@ -707,6 +708,7 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
||||
sc.set('max_cover', mcs)
|
||||
config['delete_news_from_library_on_upload'] = self.delete_news.isChecked()
|
||||
config['upload_news_to_device'] = self.sync_news.isChecked()
|
||||
config['search_as_you_type'] = self.search_as_you_type.isChecked()
|
||||
fmts = []
|
||||
for i in range(self.viewer.count()):
|
||||
if self.viewer.item(i).checkState() == Qt.Checked:
|
||||
|
@ -8,7 +8,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>800</width>
|
||||
<height>557</height>
|
||||
<height>583</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
@ -426,6 +426,16 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="search_as_you_type">
|
||||
<property name="text">
|
||||
<string>Search as you type</string>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QCheckBox" name="sync_news">
|
||||
<property name="text">
|
||||
@ -591,15 +601,6 @@
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
<zorder>roman_numerals</zorder>
|
||||
<zorder>groupBox_2</zorder>
|
||||
<zorder>systray_icon</zorder>
|
||||
<zorder>sync_news</zorder>
|
||||
<zorder>delete_news</zorder>
|
||||
<zorder>separate_cover_flow</zorder>
|
||||
<zorder>systray_notifications</zorder>
|
||||
<zorder></zorder>
|
||||
<zorder></zorder>
|
||||
</widget>
|
||||
<widget class="QWidget" name="page_6">
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
|
@ -1095,6 +1095,7 @@ class SearchBox(QLineEdit):
|
||||
QLineEdit.__init__(self, parent)
|
||||
self.help_text = help_text
|
||||
self.initial_state = True
|
||||
self.as_you_type = True
|
||||
self.default_palette = QApplication.palette(self)
|
||||
self.gray = QPalette(self.default_palette)
|
||||
self.gray.setBrush(QPalette.Text, QBrush(QColor('gray')))
|
||||
@ -1123,6 +1124,9 @@ class SearchBox(QLineEdit):
|
||||
if self.initial_state:
|
||||
self.normalize_state()
|
||||
self.initial_state = False
|
||||
if not self.as_you_type:
|
||||
if event.key() in (Qt.Key_Return, Qt.Key_Enter):
|
||||
self.do_search()
|
||||
QLineEdit.keyPressEvent(self, event)
|
||||
|
||||
def mouseReleaseEvent(self, event):
|
||||
@ -1132,6 +1136,7 @@ class SearchBox(QLineEdit):
|
||||
QLineEdit.mouseReleaseEvent(self, event)
|
||||
|
||||
def text_edited_slot(self, text):
|
||||
if self.as_you_type:
|
||||
text = qstring_to_unicode(text) if isinstance(text, QString) else unicode(text)
|
||||
self.prev_text = text
|
||||
self.timer = self.startTimer(self.__class__.INTERVAL)
|
||||
@ -1139,6 +1144,9 @@ class SearchBox(QLineEdit):
|
||||
def timerEvent(self, event):
|
||||
self.killTimer(event.timerId())
|
||||
if event.timerId() == self.timer:
|
||||
self.do_search()
|
||||
|
||||
def do_search(self):
|
||||
text = qstring_to_unicode(self.text())
|
||||
refinement = text.startswith(self.prev_search) and ':' not in text
|
||||
self.prev_search = text
|
||||
@ -1161,3 +1169,6 @@ class SearchBox(QLineEdit):
|
||||
self.end(False)
|
||||
self.initial_state = False
|
||||
|
||||
def search_as_you_type(self, enabled):
|
||||
self.as_you_type = enabled
|
||||
|
||||
|
@ -148,6 +148,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.system_tray_icon.hide()
|
||||
else:
|
||||
self.system_tray_icon.show()
|
||||
self.search.search_as_you_type(config['search_as_you_type'])
|
||||
self.system_tray_menu = QMenu(self)
|
||||
self.restore_action = self.system_tray_menu.addAction(
|
||||
QIcon(':/images/page.svg'), _('&Restore'))
|
||||
@ -1422,6 +1423,7 @@ class Main(MainWindow, Ui_MainWindow, DeviceGUI):
|
||||
self.content_server = d.server
|
||||
if d.result() == d.Accepted:
|
||||
self.tool_bar.setIconSize(config['toolbar_icon_size'])
|
||||
self.search.search_as_you_type(config['search_as_you_type'])
|
||||
self.tool_bar.setToolButtonStyle(
|
||||
Qt.ToolButtonTextUnderIcon if \
|
||||
config['show_text_in_toolbar'] else \
|
||||
|
Loading…
x
Reference in New Issue
Block a user