eric6/IconEditor/IconEditorGrid.py

branch
maintenance
changeset 8273
698ae46f40a4
parent 8176
31965986ecd1
parent 8269
87f521f359d5
equal deleted inserted replaced
8190:fb0ef164f536 8273:698ae46f40a4
32 @param text text for the undo command (string) 32 @param text text for the undo command (string)
33 @param oldImage copy of the icon before the changes were applied 33 @param oldImage copy of the icon before the changes were applied
34 (QImage) 34 (QImage)
35 @param parent reference to the parent command (QUndoCommand) 35 @param parent reference to the parent command (QUndoCommand)
36 """ 36 """
37 super(IconEditCommand, self).__init__(text, parent) 37 super().__init__(text, parent)
38 38
39 self.__grid = grid 39 self.__grid = grid
40 self.__imageBefore = QImage(oldImage) 40 self.__imageBefore = QImage(oldImage)
41 self.__imageAfter = None 41 self.__imageAfter = None
42 42
89 previewChanged = pyqtSignal(QPixmap) 89 previewChanged = pyqtSignal(QPixmap)
90 selectionAvailable = pyqtSignal(bool) 90 selectionAvailable = pyqtSignal(bool)
91 sizeChanged = pyqtSignal(int, int) 91 sizeChanged = pyqtSignal(int, int)
92 zoomChanged = pyqtSignal(int) 92 zoomChanged = pyqtSignal(int)
93 93
94 # convert to Enum
94 Pencil = 1 95 Pencil = 1
95 Rubber = 2 96 Rubber = 2
96 Line = 3 97 Line = 3
97 Rectangle = 4 98 Rectangle = 4
98 FilledRectangle = 5 99 FilledRectangle = 5
101 Ellipse = 8 102 Ellipse = 8
102 FilledEllipse = 9 103 FilledEllipse = 9
103 Fill = 10 104 Fill = 10
104 ColorPicker = 11 105 ColorPicker = 11
105 106
107 # convert to Enum
106 RectangleSelection = 20 108 RectangleSelection = 20
107 CircleSelection = 21 109 CircleSelection = 21
108 110
109 MarkColor = QColor(255, 255, 255, 255) 111 MarkColor = QColor(255, 255, 255, 255)
110 NoMarkColor = QColor(0, 0, 0, 0) 112 NoMarkColor = QColor(0, 0, 0, 0)
119 """ 121 """
120 Constructor 122 Constructor
121 123
122 @param parent reference to the parent widget (QWidget) 124 @param parent reference to the parent widget (QWidget)
123 """ 125 """
124 super(IconEditorGrid, self).__init__(parent) 126 super().__init__(parent)
125 127
126 self.setAttribute(Qt.WidgetAttribute.WA_StaticContents) 128 self.setAttribute(Qt.WidgetAttribute.WA_StaticContents)
127 self.setSizePolicy(QSizePolicy.Policy.Minimum, 129 self.setSizePolicy(QSizePolicy.Policy.Minimum,
128 QSizePolicy.Policy.Minimum) 130 QSizePolicy.Policy.Minimum)
129 131
547 Protected method to handle mouse button release events. 549 Protected method to handle mouse button release events.
548 550
549 @param evt reference to the mouse event object (QMouseEvent) 551 @param evt reference to the mouse event object (QMouseEvent)
550 """ 552 """
551 if evt.button() == Qt.MouseButton.LeftButton: 553 if evt.button() == Qt.MouseButton.LeftButton:
552 if self.__curTool in [self.Pencil, self.Rubber]: 554 if (
553 if self.__currentUndoCmd: 555 self.__curTool in [self.Pencil, self.Rubber] and
554 self.__currentUndoCmd.setAfterImage(self.__image) 556 self.__currentUndoCmd
555 self.__currentUndoCmd = None 557 ):
558 self.__currentUndoCmd.setAfterImage(self.__image)
559 self.__currentUndoCmd = None
556 560
557 if self.__curTool not in [self.Pencil, self.Rubber, 561 if self.__curTool not in [self.Pencil, self.Rubber,
558 self.Fill, self.ColorPicker, 562 self.Fill, self.ColorPicker,
559 self.RectangleSelection, 563 self.RectangleSelection,
560 self.CircleSelection]: 564 self.CircleSelection]:
609 self.__pasteRect.topLeft(), 613 self.__pasteRect.topLeft(),
610 self.__pasteRect.bottomRight() + QPoint(1, 1)) 614 self.__pasteRect.bottomRight() + QPoint(1, 1))
611 615
612 x, y = self.__imageCoordinates(pos) 616 x, y = self.__imageCoordinates(pos)
613 isize = self.__image.size() 617 isize = self.__image.size()
614 if x + self.__clipboardSize.width() <= isize.width(): 618 sx = (
615 sx = self.__clipboardSize.width() 619 self.__clipboardSize.width()
616 else: 620 if x + self.__clipboardSize.width() <= isize.width() else
617 sx = isize.width() - x 621 isize.width() - x
618 if y + self.__clipboardSize.height() <= isize.height(): 622 )
619 sy = self.__clipboardSize.height() 623 sy = (
620 else: 624 self.__clipboardSize.height()
621 sy = isize.height() - y 625 if y + self.__clipboardSize.height() <= isize.height() else
626 isize.height() - y
627 )
622 628
623 self.__pasteRect = QRect(QPoint(x, y), QSize(sx - 1, sy - 1)) 629 self.__pasteRect = QRect(QPoint(x, y), QSize(sx - 1, sy - 1))
624 630
625 painter = QPainter(self.__markImage) 631 painter = QPainter(self.__markImage)
626 painter.setPen(self.MarkColor) 632 painter.setPen(self.MarkColor)
855 861
856 img = QImage(self.__selRect.size(), QImage.Format.Format_ARGB32) 862 img = QImage(self.__selRect.size(), QImage.Format.Format_ARGB32)
857 img.fill(qRgba(0, 0, 0, 0)) 863 img.fill(qRgba(0, 0, 0, 0))
858 for i in range(0, self.__selRect.width()): 864 for i in range(0, self.__selRect.width()):
859 for j in range(0, self.__selRect.height()): 865 for j in range(0, self.__selRect.height()):
860 if self.__image.rect().contains(self.__selRect.x() + i, 866 if (
861 self.__selRect.y() + j): 867 self.__image.rect().contains(
862 if self.__isMarked( 868 self.__selRect.x() + i, self.__selRect.y() + j) and
863 self.__selRect.x() + i, self.__selRect.y() + j): 869 self.__isMarked(self.__selRect.x() + i,
864 img.setPixel(i, j, self.__image.pixel( 870 self.__selRect.y() + j)
865 self.__selRect.x() + i, self.__selRect.y() + j)) 871 ):
866 if cut: 872 img.setPixel(i, j, self.__image.pixel(
867 self.__image.setPixel(self.__selRect.x() + i, 873 self.__selRect.x() + i, self.__selRect.y() + j))
868 self.__selRect.y() + j, 874 if cut:
869 qRgba(0, 0, 0, 0)) 875 self.__image.setPixel(self.__selRect.x() + i,
876 self.__selRect.y() + j,
877 qRgba(0, 0, 0, 0))
870 878
871 if cut: 879 if cut:
872 self.__undoStack.push(cmd) 880 self.__undoStack.push(cmd)
873 cmd.setAfterImage(self.__image) 881 cmd.setAfterImage(self.__image)
874 882

eric ide

mercurial