diff --git a/src/calibre/gui2/preferences/__init__.py b/src/calibre/gui2/preferences/__init__.py index 8a621804ca..0d1641ba85 100644 --- a/src/calibre/gui2/preferences/__init__.py +++ b/src/calibre/gui2/preferences/__init__.py @@ -9,7 +9,7 @@ import textwrap from qt.core import (QWidget, pyqtSignal, QCheckBox, QAbstractSpinBox, QApplication, QLineEdit, QComboBox, Qt, QIcon, QDialog, QVBoxLayout, - QDialogButtonBox) + QDialogButtonBox, QListView, QEvent, QListWidget, QTableWidget) from calibre.customize.ui import preferences_plugins from calibre.utils.config import ConfigProxy @@ -401,6 +401,58 @@ def show_config_widget(category, name, gui=None, show_restart_msg=False, gui.shutdown() return rr + +class ListViewWithMoveByKeyPress(QListView): + + def set_movement_functions(self, up_function, down_function): + self.up_function = up_function + self.down_function = down_function + + def event(self, event): + if (event.type() == QEvent.KeyPress and + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier): + if event.key() == Qt.Key.Key_Up: + self.up_function() + elif event.key() == Qt.Key.Key_Down: + self.down_function() + return True + return QListView.event(self, event) + + +class ListWidgetWithMoveByKeyPress(QListWidget): + + def set_movement_functions(self, up_function, down_function): + self.up_function = up_function + self.down_function = down_function + + def event(self, event): + if (event.type() == QEvent.KeyPress and + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier): + if event.key() == Qt.Key.Key_Up: + self.up_function() + elif event.key() == Qt.Key.Key_Down: + self.down_function() + return True + return QListWidget.event(self, event) + + +class TableWidgetWithMoveByKeyPress(QTableWidget): + + def set_movement_functions(self, up_function, down_function): + self.up_function = up_function + self.down_function = down_function + + def event(self, event): + if (event.type() == QEvent.KeyPress and + QApplication.keyboardModifiers() == Qt.KeyboardModifier.ControlModifier): + if event.key() == Qt.Key.Key_Up: + self.up_function() + elif event.key() == Qt.Key.Key_Down: + self.down_function() + return True + return QTableWidget.event(self, event) + + # Testing {{{ diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py index 61e75dfe77..15d38ed0a8 100644 --- a/src/calibre/gui2/preferences/behavior.py +++ b/src/calibre/gui2/preferences/behavior.py @@ -69,6 +69,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.input_up_button.clicked.connect(self.up_input) self.input_down_button.clicked.connect(self.down_input) + self.opt_input_order.set_movement_functions(self.up_input, self.down_input) self.opt_input_order.dropEvent = partial(input_order_drop_event, self) for signal in ('Activated', 'Changed', 'DoubleClicked', 'Clicked'): signal = getattr(self.opt_internally_viewed_formats, 'item'+signal) diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui index e4917da2ca..8bc012d5bf 100644 --- a/src/calibre/gui2/preferences/behavior.ui +++ b/src/calibre/gui2/preferences/behavior.ui @@ -90,7 +90,7 @@ - + 0 @@ -311,6 +311,13 @@ per library.</p> + + + ListWidgetWithMoveByKeyPress + QListWidget +
calibre/gui2/preferences.h
+
+
diff --git a/src/calibre/gui2/preferences/coloring.py b/src/calibre/gui2/preferences/coloring.py index 3234deb53f..ed79a9e498 100644 --- a/src/calibre/gui2/preferences/coloring.py +++ b/src/calibre/gui2/preferences/coloring.py @@ -26,6 +26,7 @@ from calibre.gui2 import ( ) from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.metadata.single_download import RichTextDelegate +from calibre.gui2.preferences import ListViewWithMoveByKeyPress from calibre.gui2.widgets2 import ColorButton, FlowLayout, Separator from calibre.library.coloring import ( Rule, color_row_key, conditionable_columns, displayable_columns, @@ -956,10 +957,10 @@ class RulesModel(QAbstractListModel): # {{{ # }}} -class RulesView(QListView): # {{{ +class RulesView(ListViewWithMoveByKeyPress): # {{{ def __init__(self, parent, enable_convert_buttons_function): - QListView.__init__(self, parent) + ListViewWithMoveByKeyPress.__init__(self, parent) self.enable_convert_buttons_function = enable_convert_buttons_function def currentChanged(self, new, prev): @@ -1016,6 +1017,8 @@ class EditRules(QWidget): # {{{ b.setIcon(QIcon.ic('arrow-down.png')) b.setToolTip(_('Move the selected rule down')) b.clicked.connect(partial(self.move_rows, moving_up=False)) + self.rules_view.set_movement_functions(partial(self.move_rows, moving_up=True), + partial(self.move_rows, moving_up=False)) g.addWidget(b, 1, 1, 1, 1, Qt.AlignmentFlag.AlignBottom) l.addLayout(g, l.rowCount(), 0, 1, 2) diff --git a/src/calibre/gui2/preferences/columns.py b/src/calibre/gui2/preferences/columns.py index f0b259bb96..1e9988f1ad 100644 --- a/src/calibre/gui2/preferences/columns.py +++ b/src/calibre/gui2/preferences/columns.py @@ -8,7 +8,7 @@ __docformat__ = 'restructuredtext en' import copy, sys from contextlib import suppress -from qt.core import Qt, QTableWidgetItem, QIcon +from qt.core import Qt, QTableWidgetItem, QIcon, QAbstractItemView from calibre.gui2 import gprefs, Application from calibre.gui2.preferences import ConfigWidgetBase, test_widget @@ -34,6 +34,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.column_up.clicked.connect(self.up_column) self.column_down.clicked.connect(self.down_column) + self.opt_columns.setSelectionMode(QAbstractItemView.SingleSelection) + self.opt_columns.set_movement_functions(self.up_column, self.down_column) self.del_custcol_button.clicked.connect(self.del_custcol) self.add_custcol_button.clicked.connect(self.add_custcol) self.add_col_button.clicked.connect(self.add_custcol) diff --git a/src/calibre/gui2/preferences/columns.ui b/src/calibre/gui2/preferences/columns.ui index 1e80ed88fe..32996814dd 100644 --- a/src/calibre/gui2/preferences/columns.ui +++ b/src/calibre/gui2/preferences/columns.ui @@ -25,7 +25,7 @@
- + true @@ -203,6 +203,13 @@ + + + TableWidgetWithMoveByKeyPress + QTableWidget +
calibre/gui2/preferences.h
+
+
diff --git a/src/calibre/gui2/preferences/look_feel.py b/src/calibre/gui2/preferences/look_feel.py index f8ed2ebcba..73deaa876e 100644 --- a/src/calibre/gui2/preferences/look_feel.py +++ b/src/calibre/gui2/preferences/look_feel.py @@ -642,56 +642,50 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.current_font = self.initial_font = None self.change_font_button.clicked.connect(self.change_font) - self.display_model = DisplayedFields(self.gui.current_db, - self.field_display_order) + self.display_model = DisplayedFields(self.gui.current_db, self.field_display_order) self.display_model.dataChanged.connect(self.changed_signal) self.field_display_order.setModel(self.display_model) - connect_lambda(self.df_up_button.clicked, self, - lambda self: move_field_up(self.field_display_order, self.display_model)) - connect_lambda(self.df_down_button.clicked, self, - lambda self: move_field_down(self.field_display_order, self.display_model)) + mu = partial(move_field_up, self.field_display_order, self.display_model) + md = partial(move_field_down, self.field_display_order, self.display_model) + self.df_up_button.clicked.connect(mu) + self.df_down_button.clicked.connect(md) + self.field_display_order.set_movement_functions(mu, md) - self.em_display_model = EMDisplayedFields(self.gui.current_db, - self.em_display_order) + self.em_display_model = EMDisplayedFields(self.gui.current_db, self.em_display_order) self.em_display_model.dataChanged.connect(self.changed_signal) self.em_display_order.setModel(self.em_display_model) - connect_lambda(self.em_up_button.clicked, self, - lambda self: move_field_up(self.em_display_order, self.em_display_model)) - connect_lambda(self.em_down_button.clicked, self, - lambda self: move_field_down(self.em_display_order, self.em_display_model)) - self.em_export_layout_button.clicked.connect(partial(self.export_layout, - model=self.em_display_model)) - self.em_import_layout_button.clicked.connect(partial(self.import_layout, - model=self.em_display_model)) - self.em_reset_layout_button.clicked.connect(partial(self.reset_layout, - model=self.em_display_model)) + mu = partial(move_field_up, self.em_display_order, self.em_display_model) + md = partial(move_field_down, self.em_display_order, self.em_display_model) + self.em_display_order.set_movement_functions(mu, md) + self.em_up_button.clicked.connect(mu) + self.em_down_button.clicked.connect(md) + self.em_export_layout_button.clicked.connect(partial(self.export_layout, model=self.em_display_model)) + self.em_import_layout_button.clicked.connect(partial(self.import_layout, model=self.em_display_model)) + self.em_reset_layout_button.clicked.connect(partial(self.reset_layout, model=self.em_display_model)) - self.qv_display_model = QVDisplayedFields(self.gui.current_db, - self.qv_display_order) + self.qv_display_model = QVDisplayedFields(self.gui.current_db, self.qv_display_order) self.qv_display_model.dataChanged.connect(self.changed_signal) self.qv_display_order.setModel(self.qv_display_model) - connect_lambda(self.qv_up_button.clicked, self, - lambda self: move_field_up(self.qv_display_order, self.qv_display_model)) - connect_lambda(self.qv_down_button.clicked, self, - lambda self: move_field_down(self.qv_display_order, self.qv_display_model)) + mu = partial(move_field_up, self.qv_display_order, self.qv_display_model) + md = partial(move_field_down, self.qv_display_order, self.qv_display_model) + self.qv_display_order.set_movement_functions(mu, md) + self.qv_up_button.clicked.connect(mu) + self.qv_down_button.clicked.connect(md) - self.tb_display_model = TBDisplayedFields(self.gui.current_db, - self.tb_display_order, - category_icons=self.gui.tags_view.model().category_custom_icons) + self.tb_display_model = TBDisplayedFields(self.gui.current_db, self.tb_display_order, + category_icons=self.gui.tags_view.model().category_custom_icons) self.tb_display_model.dataChanged.connect(self.changed_signal) self.tb_display_order.setModel(self.tb_display_model) - self.tb_reset_layout_button.clicked.connect(partial(self.reset_layout, - model=self.tb_display_model)) - self.tb_export_layout_button.clicked.connect(partial(self.export_layout, - model=self.tb_display_model)) - self.tb_import_layout_button.clicked.connect(partial(self.import_layout, - model=self.tb_display_model)) + self.tb_reset_layout_button.clicked.connect(partial(self.reset_layout, model=self.tb_display_model)) + self.tb_export_layout_button.clicked.connect(partial(self.export_layout, model=self.tb_display_model)) + self.tb_import_layout_button.clicked.connect(partial(self.import_layout, model=self.tb_display_model)) self.tb_up_button.clicked.connect(self.tb_up_button_clicked) self.tb_down_button.clicked.connect(self.tb_down_button_clicked) + self.tb_display_order.set_movement_functions(self.tb_up_button_clicked, self.tb_down_button_clicked) self.tb_categories_to_part_model = TBPartitionedFields(self.gui.current_db, - self.tb_cats_to_partition, - category_icons=self.gui.tags_view.model().category_custom_icons) + self.tb_cats_to_partition, + category_icons=self.gui.tags_view.model().category_custom_icons) self.tb_categories_to_part_model.dataChanged.connect(self.changed_signal) self.tb_cats_to_partition.setModel(self.tb_categories_to_part_model) self.tb_partition_reset_button.clicked.connect(partial(self.reset_layout, @@ -701,9 +695,8 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.tb_partition_import_layout_button.clicked.connect(partial(self.import_layout, model=self.tb_categories_to_part_model)) - self.tb_hierarchical_cats_model = TBHierarchicalFields(self.gui.current_db, - self.tb_hierarchical_cats, - category_icons=self.gui.tags_view.model().category_custom_icons) + self.tb_hierarchical_cats_model = TBHierarchicalFields(self.gui.current_db, self.tb_hierarchical_cats, + category_icons=self.gui.tags_view.model().category_custom_icons) self.tb_hierarchical_cats_model.dataChanged.connect(self.changed_signal) self.tb_hierarchical_cats.setModel(self.tb_hierarchical_cats_model) self.tb_hierarchy_reset_layout_button.clicked.connect(partial(self.reset_layout, @@ -716,17 +709,16 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.fill_tb_search_order_box() self.tb_search_order_up_button.clicked.connect(self.move_tb_search_up) self.tb_search_order_down_button.clicked.connect(self.move_tb_search_down) + self.tb_search_order.set_movement_functions(self.move_tb_search_up, self.move_tb_search_down) self.tb_search_order_reset_button.clicked.connect(self.reset_tb_search_order) self.edit_rules = EditRules(self.tabWidget) self.edit_rules.changed.connect(self.changed_signal) - self.tabWidget.addTab(self.edit_rules, - QIcon.ic('format-fill-color.png'), _('Column &coloring')) + self.tabWidget.addTab(self.edit_rules, QIcon.ic('format-fill-color.png'), _('Column &coloring')) self.icon_rules = EditRules(self.tabWidget) self.icon_rules.changed.connect(self.changed_signal) - self.tabWidget.addTab(self.icon_rules, - QIcon.ic('icon_choose.png'), _('Column &icons')) + self.tabWidget.addTab(self.icon_rules, QIcon.ic('icon_choose.png'), _('Column &icons')) self.grid_rules = EditRules(self.emblems_tab) self.grid_rules.changed.connect(self.changed_signal) diff --git a/src/calibre/gui2/preferences/look_feel.ui b/src/calibre/gui2/preferences/look_feel.ui index d5aed65773..4d7f2c96e7 100644 --- a/src/calibre/gui2/preferences/look_feel.ui +++ b/src/calibre/gui2/preferences/look_feel.ui @@ -753,7 +753,7 @@ A value of zero means calculate automatically. - Move down + Move down. Keyboard shortcut: Ctrl-Down arrow @@ -764,7 +764,7 @@ A value of zero means calculate automatically. - Move up + Move up. Keyboard shortcut: Ctrl-Up arrow @@ -786,7 +786,7 @@ A value of zero means calculate automatically. - + true @@ -914,7 +914,7 @@ A value of zero means calculate automatically. - Move down + Move down. Keyboard shortcut: Ctrl-Down arrow @@ -925,7 +925,7 @@ A value of zero means calculate automatically. - Move up + Move up. Keyboard shortcut: Ctrl-Up arrow @@ -947,7 +947,7 @@ A value of zero means calculate automatically. - + true @@ -1162,7 +1162,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p& - + 0 @@ -1177,7 +1177,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p& - Move up. User categories and Saved searches cannot be moved + Move up. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Up arrow @@ -1201,7 +1201,7 @@ using the Tab key. The F2 (Edit) key will still open the template editor.</p& - Move down. User categories and Saved searches cannot be moved + Move down. User categories and Saved searches cannot be moved. Keyboard shortcut: Ctrl-Down arrow @@ -1691,7 +1691,7 @@ that don't have children.</p> - + QAbstractScrollArea::AdjustToContents @@ -1700,7 +1700,7 @@ that don't have children.</p> - Move up. + Move up. Keyboard shortcut: Ctrl-Up arrow @@ -1724,7 +1724,7 @@ that don't have children.</p> - Move down. + Move down. Keyboard shortcut: Ctrl-Down arrow @@ -1985,7 +1985,7 @@ column being examined (the left-hand pane)</p> - Move up + Move up. Keyboard shortcut: Ctrl-Up arrow @@ -1996,7 +1996,7 @@ column being examined (the left-hand pane)</p> - Move down + Move down. Keyboard shortcut: Ctrl-Down arrow @@ -2005,7 +2005,7 @@ column being examined (the left-hand pane)</p> - + true @@ -2043,7 +2043,17 @@ column being examined (the left-hand pane)</p> - + ListWidgetWithMoveByKeyPress + + ListViewWithMoveByKeyPress + QListView +
calibre/gui2/preferences.h
+
+ + ListWidgetWithMoveByKeyPress + QListWidget +
calibre/gui2/preferences.h
+
EditWithComplete QComboBox