From 14025af9e62c66dd18ff406a49f6223f56544210 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 5 Mar 2020 09:56:52 +0530 Subject: [PATCH] Fix #1865915 [[Enhancement] Change list order by drag and drop](https://bugs.launchpad.net/calibre/+bug/1865915) --- src/calibre/gui2/preferences/behavior.py | 15 ++++++++++++--- src/calibre/gui2/preferences/behavior.ui | 9 +++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/calibre/gui2/preferences/behavior.py b/src/calibre/gui2/preferences/behavior.py index d390d7a216..e93a449952 100644 --- a/src/calibre/gui2/preferences/behavior.py +++ b/src/calibre/gui2/preferences/behavior.py @@ -7,6 +7,7 @@ __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' import re +from functools import partial from PyQt5.Qt import Qt, QListWidgetItem @@ -22,6 +23,13 @@ from calibre.utils.icu import sort_key from polyglot.builtins import unicode_type, range +def input_order_drop_event(self, ev): + ret = self.opt_input_order.__class__.dropEvent(self.opt_input_order, ev) + if ev.isAccepted(): + self.changed_signal.emit() + return ret + + class OutputFormatSetting(Setting): CHOICES_SEARCH_FLAGS = Qt.MatchFixedString @@ -62,6 +70,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.dropEvent = partial(input_order_drop_event, self) for signal in ('Activated', 'Changed', 'DoubleClicked', 'Clicked'): signal = getattr(self.opt_internally_viewed_formats, 'item'+signal) signal.connect(self.internally_viewed_formats_changed) @@ -147,7 +156,7 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): for format in input_map + list(all_formats.difference(input_map)): item = QListWidgetItem(format, self.opt_input_order) item.setData(Qt.UserRole, (format)) - item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable) + item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsSelectable|Qt.ItemIsDragEnabled) def up_input(self, *args): idx = self.opt_input_order.currentRow() @@ -175,6 +184,6 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): if __name__ == '__main__': - from PyQt5.Qt import QApplication - app = QApplication([]) + from calibre.gui2 import Application + app = Application([]) test_widget('Interface', 'Behavior') diff --git a/src/calibre/gui2/preferences/behavior.ui b/src/calibre/gui2/preferences/behavior.ui index 72bc8958e2..d700aa33c9 100644 --- a/src/calibre/gui2/preferences/behavior.ui +++ b/src/calibre/gui2/preferences/behavior.ui @@ -104,6 +104,15 @@ 0 + + true + + + QAbstractItemView::InternalMove + + + Qt::MoveAction + true