From 19bcc2357bf9c46ba587e9c50960d8e71f35eedf Mon Sep 17 00:00:00 2001 From: Simon Renblad Date: Mon, 15 Jan 2024 16:55:02 +0800 Subject: [PATCH] dndwidgets: improved drag drop splitter --- artiq/gui/dndwidgets.py | 51 +++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/artiq/gui/dndwidgets.py b/artiq/gui/dndwidgets.py index 1024e97f0..f7afd5e0e 100644 --- a/artiq/gui/dndwidgets.py +++ b/artiq/gui/dndwidgets.py @@ -23,7 +23,6 @@ class DragDropSplitter(QtWidgets.QSplitter): pos = e.pos() src = e.source() src_i = self.indexOf(src) - # case 0: smaller than source widget if pos.y() < src.y(): for n in range(src_i): @@ -33,46 +32,34 @@ class DragDropSplitter(QtWidgets.QSplitter): break # case 2: greater than source widget elif pos.y() > src.y() + src.size().height(): - for n in range(src_i): + for n in range(src_i + 1, self.count()): w = self.widget(n) if pos.y() < w.y() + w.size().height(): - self.setRubberBand(w.y()) + self.setRubberBand(w.y() + w.size().height()) break else: self.setRubberBand(-1) - for n in range(self.count()): - w = self.widget(n) - if self.orientation() == QtCore.Qt.Vertical: - pos_p, w_p, w_s = pos.y(), w.y(), w.size().height() - else: - pos_p, w_p, w_s = pos.x(), w.x(), w.size().width() - if pos_p < w_p + w_s // 2: - self.setRubberBand(w_p) - break - elif n == self.count() - 1: - self.setRubberBand(w_p + w_s) e.accept() def dropEvent(self, e): - pos = e.pos() - widget = e.source() - index = self.indexOf(widget) self.setRubberBand(-1) - for n in range(self.count()): - w = self.widget(n) - if n <= index: - k = n - else: - k = n - 1 - if self.orientation() == QtCore.Qt.Vertical: - pos_p, w_p, w_s = pos.y(), w.y(), w.size().height() - else: - pos_p, w_p, w_s = pos.x(), w.x(), w.size().width() - if pos_p < w_p + w_s // 2: - self.insertWidget(k, widget) - break - elif n == self.count() - 1: - self.insertWidget(-1, widget) + pos = e.pos() + src = e.source() + src_i = self.indexOf(src) + # case 0: smaller than source widget + if pos.y() < src.y(): + for n in range(src_i): + w = self.widget(n) + if pos.y() < w.y() + w.size().height(): + self.insertWidget(n, src) + break + # case 2: greater than source widget + elif pos.y() > src.y() + src.size().height(): + for n in range(src_i + 1, self.count()): + w = self.widget(n) + if pos.y() < w.y() + w.size().height(): + self.insertWidget(n, src) + break e.accept()