diff --git a/src/locales.py b/src/locales.py index c06a950..46bbd0a 100644 --- a/src/locales.py +++ b/src/locales.py @@ -144,6 +144,7 @@ class Locale: WarningPathNotClosed = "When cutting the model, not closed areas were found! Check that the shapes are positioned correctly" RemoveFirstPlaneError = "First figure cannot be removed" + CannotDropHere = "Figure cannot be dropped here" def __init__(self, **entries): self.__dict__.update(entries) @@ -295,6 +296,7 @@ def __init__(self, **entries): M10CutDistance="Дистанция отреза филамента, мм:", RemoveFirstPlaneError="Первая фигура не может быть убрана", WarningPathNotClosed="При разрезании модели были обнаружены незамкнутые участки! Проверьте корректность расположения фигур", + CannotDropHere="Фигура не может быть перенесена сюда", ), } diff --git a/src/window.py b/src/window.py index 683cd7c..ec5f5e2 100644 --- a/src/window.py +++ b/src/window.py @@ -29,7 +29,7 @@ from src import locales, gui_utils, interactor_style from src.InteractorAroundActivePlane import InteractionAroundActivePlane -from src.gui_utils import plane_tf, Plane, Cone +from src.gui_utils import plane_tf, Plane, Cone, showErrorDialog from src.settings import ( sett, get_color, @@ -70,10 +70,28 @@ def __init__(self, parent=None): self.setDropIndicatorShown(True) self.setAcceptDrops(True) - def dragMoveEvent(self, event): + def dragEnterEvent(self, e: QtGui.QDragEnterEvent) -> None: + # we cannot start dragging the first row + item = self.selectedItems()[0] + idx = self.indexFromItem(item) + if idx.row() == 0: + e.ignore() + return + + return super().dragEnterEvent(e) + + def dragMoveEvent(self, event: QtGui.QDragMoveEvent) -> None: self.itemIsMoving = True super().dragMoveEvent(event) + def dropEvent(self, event): + # we cannot drop on the first row + if self.indexAt(event.pos()).row() == 0: + showErrorDialog(locales.getLocale().CannotDropHere) + return + + super().dropEvent(event) + class MainWindow(QMainWindow): from src.figure_editor import FigureEditor