121 |
121 |
122 @param parent reference to the parent widget (QWidget) |
122 @param parent reference to the parent widget (QWidget) |
123 """ |
123 """ |
124 super(IconEditorGrid, self).__init__(parent) |
124 super(IconEditorGrid, self).__init__(parent) |
125 |
125 |
126 self.setAttribute(Qt.WA_StaticContents) |
126 self.setAttribute(Qt.WidgetAttribute.WA_StaticContents) |
127 self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum) |
127 self.setSizePolicy(QSizePolicy.Policy.Minimum, |
128 |
128 QSizePolicy.Policy.Minimum) |
129 self.__curColor = Qt.black |
129 |
|
130 self.__curColor = Qt.GlobalColor.black |
130 self.__zoom = 12 |
131 self.__zoom = 12 |
131 self.__curTool = self.Pencil |
132 self.__curTool = self.Pencil |
132 self.__startPos = QPoint() |
133 self.__startPos = QPoint() |
133 self.__endPos = QPoint() |
134 self.__endPos = QPoint() |
134 self.__dirty = False |
135 self.__dirty = False |
139 self.__pasteRect = QRect() |
140 self.__pasteRect = QRect() |
140 |
141 |
141 self.__undoStack = QUndoStack(self) |
142 self.__undoStack = QUndoStack(self) |
142 self.__currentUndoCmd = None |
143 self.__currentUndoCmd = None |
143 |
144 |
144 self.__image = QImage(32, 32, QImage.Format_ARGB32) |
145 self.__image = QImage(32, 32, QImage.Format.Format_ARGB32) |
145 self.__image.fill(qRgba(0, 0, 0, 0)) |
146 self.__image.fill(qRgba(0, 0, 0, 0)) |
146 self.__markImage = QImage(self.__image) |
147 self.__markImage = QImage(self.__image) |
147 self.__markImage.fill(self.NoMarkColor.rgba()) |
148 self.__markImage.fill(self.NoMarkColor.rgba()) |
148 |
149 |
149 self.__compositingMode = QPainter.CompositionMode_SourceOver |
150 self.__compositingMode = ( |
|
151 QPainter.CompositionMode.CompositionMode_SourceOver |
|
152 ) |
150 self.__lastPos = (-1, -1) |
153 self.__lastPos = (-1, -1) |
151 |
154 |
152 self.__gridEnabled = True |
155 self.__gridEnabled = True |
153 self.__selectionAvailable = False |
156 self.__selectionAvailable = False |
154 |
157 |
170 """ |
173 """ |
171 Private method to initialize the various cursors. |
174 Private method to initialize the various cursors. |
172 """ |
175 """ |
173 cursorsPath = os.path.join(os.path.dirname(__file__), "cursors") |
176 cursorsPath = os.path.join(os.path.dirname(__file__), "cursors") |
174 |
177 |
175 self.__normalCursor = QCursor(Qt.ArrowCursor) |
178 self.__normalCursor = QCursor(Qt.CursorShape.ArrowCursor) |
176 |
179 |
177 pix = QPixmap(os.path.join(cursorsPath, "colorpicker-cursor.xpm")) |
180 pix = QPixmap(os.path.join(cursorsPath, "colorpicker-cursor.xpm")) |
178 mask = pix.createHeuristicMask() |
181 mask = pix.createHeuristicMask() |
179 pix.setMask(mask) |
182 pix.setMask(mask) |
180 self.__colorPickerCursor = QCursor(pix, 1, 21) |
183 self.__colorPickerCursor = QCursor(pix, 1, 21) |
330 @param newImage reference to the new image (QImage) |
333 @param newImage reference to the new image (QImage) |
331 @param undoRedo flag indicating an undo or redo operation (boolean) |
334 @param undoRedo flag indicating an undo or redo operation (boolean) |
332 @param clearUndo flag indicating to clear the undo stack (boolean) |
335 @param clearUndo flag indicating to clear the undo stack (boolean) |
333 """ |
336 """ |
334 if newImage != self.__image: |
337 if newImage != self.__image: |
335 self.__image = newImage.convertToFormat(QImage.Format_ARGB32) |
338 self.__image = newImage.convertToFormat( |
|
339 QImage.Format.Format_ARGB32) |
336 self.update() |
340 self.update() |
337 self.updateGeometry() |
341 self.updateGeometry() |
338 self.resize(self.sizeHint()) |
342 self.resize(self.sizeHint()) |
339 |
343 |
340 self.__markImage = QImage(self.__image) |
344 self.__markImage = QImage(self.__image) |
428 0, self.__zoom * j, |
432 0, self.__zoom * j, |
429 self.__zoom * self.__image.width(), self.__zoom * j) |
433 self.__zoom * self.__image.width(), self.__zoom * j) |
430 j += 1 |
434 j += 1 |
431 |
435 |
432 col = QColor("#aaa") |
436 col = QColor("#aaa") |
433 painter.setPen(Qt.DashLine) |
437 painter.setPen(Qt.PenStyle.DashLine) |
434 for i in range(0, self.__image.width()): |
438 for i in range(0, self.__image.width()): |
435 for j in range(0, self.__image.height()): |
439 for j in range(0, self.__image.height()): |
436 rect = self.__pixelRect(i, j) |
440 rect = self.__pixelRect(i, j) |
437 if evt.region().intersects(rect): |
441 if evt.region().intersects(rect): |
438 color = QColor.fromRgba(self.__image.pixel(i, j)) |
442 color = QColor.fromRgba(self.__image.pixel(i, j)) |
439 painter.fillRect(rect, QBrush(Qt.white)) |
443 painter.fillRect(rect, QBrush(Qt.GlobalColor.white)) |
440 painter.fillRect(QRect(rect.topLeft(), rect.center()), col) |
444 painter.fillRect(QRect(rect.topLeft(), rect.center()), col) |
441 painter.fillRect(QRect(rect.center(), rect.bottomRight()), |
445 painter.fillRect(QRect(rect.center(), rect.bottomRight()), |
442 col) |
446 col) |
443 painter.fillRect(rect, QBrush(color)) |
447 painter.fillRect(rect, QBrush(color)) |
444 |
448 |
466 """ |
470 """ |
467 Protected method to handle mouse button press events. |
471 Protected method to handle mouse button press events. |
468 |
472 |
469 @param evt reference to the mouse event object (QMouseEvent) |
473 @param evt reference to the mouse event object (QMouseEvent) |
470 """ |
474 """ |
471 if evt.button() == Qt.LeftButton: |
475 if evt.button() == Qt.MouseButton.LeftButton: |
472 if self.__isPasting: |
476 if self.__isPasting: |
473 self.__isPasting = False |
477 self.__isPasting = False |
474 self.editPaste(True) |
478 self.editPaste(True) |
475 self.__markImage.fill(self.NoMarkColor.rgba()) |
479 self.__markImage.fill(self.NoMarkColor.rgba()) |
476 self.update(self.__pasteRect) |
480 self.update(self.__pasteRect) |
517 |
521 |
518 @param evt reference to the mouse event object (QMouseEvent) |
522 @param evt reference to the mouse event object (QMouseEvent) |
519 """ |
523 """ |
520 self.positionChanged.emit(*self.__imageCoordinates(evt.pos())) |
524 self.positionChanged.emit(*self.__imageCoordinates(evt.pos())) |
521 |
525 |
522 if self.__isPasting and not (evt.buttons() & Qt.LeftButton): |
526 if ( |
|
527 self.__isPasting and |
|
528 not (evt.buttons() & Qt.MouseButton.LeftButton) |
|
529 ): |
523 self.__drawPasteRect(evt.pos()) |
530 self.__drawPasteRect(evt.pos()) |
524 return |
531 return |
525 |
532 |
526 if evt.buttons() & Qt.LeftButton: |
533 if evt.buttons() & Qt.MouseButton.LeftButton: |
527 if self.__curTool == self.Pencil: |
534 if self.__curTool == self.Pencil: |
528 self.__setImagePixel(evt.pos(), True) |
535 self.__setImagePixel(evt.pos(), True) |
529 self.setDirty(True) |
536 self.setDirty(True) |
530 elif self.__curTool == self.Rubber: |
537 elif self.__curTool == self.Rubber: |
531 self.__setImagePixel(evt.pos(), False) |
538 self.__setImagePixel(evt.pos(), False) |
539 """ |
546 """ |
540 Protected method to handle mouse button release events. |
547 Protected method to handle mouse button release events. |
541 |
548 |
542 @param evt reference to the mouse event object (QMouseEvent) |
549 @param evt reference to the mouse event object (QMouseEvent) |
543 """ |
550 """ |
544 if evt.button() == Qt.LeftButton: |
551 if evt.button() == Qt.MouseButton.LeftButton: |
545 if self.__curTool in [self.Pencil, self.Rubber]: |
552 if self.__curTool in [self.Pencil, self.Rubber]: |
546 if self.__currentUndoCmd: |
553 if self.__currentUndoCmd: |
547 self.__currentUndoCmd.setAfterImage(self.__image) |
554 self.__currentUndoCmd.setAfterImage(self.__image) |
548 self.__currentUndoCmd = None |
555 self.__currentUndoCmd = None |
549 |
556 |
829 valid image (boolean) |
836 valid image (boolean) |
830 """ |
837 """ |
831 img = QApplication.clipboard().image() |
838 img = QApplication.clipboard().image() |
832 ok = not img.isNull() |
839 ok = not img.isNull() |
833 if ok: |
840 if ok: |
834 img = img.convertToFormat(QImage.Format_ARGB32) |
841 img = img.convertToFormat(QImage.Format.Format_ARGB32) |
835 |
842 |
836 return img, ok |
843 return img, ok |
837 |
844 |
838 def __getSelectionImage(self, cut): |
845 def __getSelectionImage(self, cut): |
839 """ |
846 """ |
844 """ |
851 """ |
845 if cut: |
852 if cut: |
846 cmd = IconEditCommand(self, self.tr("Cut Selection"), |
853 cmd = IconEditCommand(self, self.tr("Cut Selection"), |
847 self.__image) |
854 self.__image) |
848 |
855 |
849 img = QImage(self.__selRect.size(), QImage.Format_ARGB32) |
856 img = QImage(self.__selRect.size(), QImage.Format.Format_ARGB32) |
850 img.fill(qRgba(0, 0, 0, 0)) |
857 img.fill(qRgba(0, 0, 0, 0)) |
851 for i in range(0, self.__selRect.width()): |
858 for i in range(0, self.__selRect.width()): |
852 for j in range(0, self.__selRect.height()): |
859 for j in range(0, self.__selRect.height()): |
853 if self.__image.rect().contains(self.__selRect.x() + i, |
860 if self.__image.rect().contains(self.__selRect.x() + i, |
854 self.__selRect.y() + j): |
861 self.__selRect.y() + j): |
985 Public slot to resize the image. |
992 Public slot to resize the image. |
986 """ |
993 """ |
987 from .IconSizeDialog import IconSizeDialog |
994 from .IconSizeDialog import IconSizeDialog |
988 dlg = IconSizeDialog(self.__image.width(), self.__image.height()) |
995 dlg = IconSizeDialog(self.__image.width(), self.__image.height()) |
989 res = dlg.exec() |
996 res = dlg.exec() |
990 if res == QDialog.Accepted: |
997 if res == QDialog.DialogCode.Accepted: |
991 newWidth, newHeight = dlg.getData() |
998 newWidth, newHeight = dlg.getData() |
992 if ( |
999 if ( |
993 newWidth != self.__image.width() or |
1000 newWidth != self.__image.width() or |
994 newHeight != self.__image.height() |
1001 newHeight != self.__image.height() |
995 ): |
1002 ): |
996 cmd = IconEditCommand(self, self.tr("Resize Image"), |
1003 cmd = IconEditCommand(self, self.tr("Resize Image"), |
997 self.__image) |
1004 self.__image) |
998 img = self.__image.scaled( |
1005 img = self.__image.scaled( |
999 newWidth, newHeight, Qt.IgnoreAspectRatio, |
1006 newWidth, newHeight, Qt.AspectRatioMode.IgnoreAspectRatio, |
1000 Qt.SmoothTransformation) |
1007 Qt.TransformationMode.SmoothTransformation) |
1001 self.setIconImage(img) |
1008 self.setIconImage(img) |
1002 self.setDirty(True) |
1009 self.setDirty(True) |
1003 self.__undoStack.push(cmd) |
1010 self.__undoStack.push(cmd) |
1004 cmd.setAfterImage(self.__image) |
1011 cmd.setAfterImage(self.__image) |
1005 |
1012 |
1008 Public slot to generate a new, empty image. |
1015 Public slot to generate a new, empty image. |
1009 """ |
1016 """ |
1010 from .IconSizeDialog import IconSizeDialog |
1017 from .IconSizeDialog import IconSizeDialog |
1011 dlg = IconSizeDialog(self.__image.width(), self.__image.height()) |
1018 dlg = IconSizeDialog(self.__image.width(), self.__image.height()) |
1012 res = dlg.exec() |
1019 res = dlg.exec() |
1013 if res == QDialog.Accepted: |
1020 if res == QDialog.DialogCode.Accepted: |
1014 width, height = dlg.getData() |
1021 width, height = dlg.getData() |
1015 img = QImage(width, height, QImage.Format_ARGB32) |
1022 img = QImage(width, height, QImage.Format.Format_ARGB32) |
1016 img.fill(qRgba(0, 0, 0, 0)) |
1023 img.fill(qRgba(0, 0, 0, 0)) |
1017 self.setIconImage(img) |
1024 self.setIconImage(img) |
1018 |
1025 |
1019 def grayScale(self): |
1026 def grayScale(self): |
1020 """ |
1027 """ |