IconEditor/IconEditorGrid.py

changeset 3190
a9a94491c4fd
parent 3160
209a07d7e401
child 3345
071afe8be2a1
equal deleted inserted replaced
3189:9a21c547de5f 3190:a9a94491c4fd
198 """ 198 """
199 Private method to initialize texts to be associated with undo commands 199 Private method to initialize texts to be associated with undo commands
200 for the various drawing tools. 200 for the various drawing tools.
201 """ 201 """
202 self.__undoTexts = { 202 self.__undoTexts = {
203 self.Pencil: self.trUtf8("Set Pixel"), 203 self.Pencil: self.tr("Set Pixel"),
204 self.Rubber: self.trUtf8("Erase Pixel"), 204 self.Rubber: self.tr("Erase Pixel"),
205 self.Line: self.trUtf8("Draw Line"), 205 self.Line: self.tr("Draw Line"),
206 self.Rectangle: self.trUtf8("Draw Rectangle"), 206 self.Rectangle: self.tr("Draw Rectangle"),
207 self.FilledRectangle: self.trUtf8("Draw Filled Rectangle"), 207 self.FilledRectangle: self.tr("Draw Filled Rectangle"),
208 self.Circle: self.trUtf8("Draw Circle"), 208 self.Circle: self.tr("Draw Circle"),
209 self.FilledCircle: self.trUtf8("Draw Filled Circle"), 209 self.FilledCircle: self.tr("Draw Filled Circle"),
210 self.Ellipse: self.trUtf8("Draw Ellipse"), 210 self.Ellipse: self.tr("Draw Ellipse"),
211 self.FilledEllipse: self.trUtf8("Draw Filled Ellipse"), 211 self.FilledEllipse: self.tr("Draw Filled Ellipse"),
212 self.Fill: self.trUtf8("Fill Region"), 212 self.Fill: self.tr("Fill Region"),
213 } 213 }
214 214
215 def isDirty(self): 215 def isDirty(self):
216 """ 216 """
217 Public method to check the dirty status. 217 Public method to check the dirty status.
832 832
833 @param cut flag indicating to cut the selection (boolean) 833 @param cut flag indicating to cut the selection (boolean)
834 @return image of the selection (QImage) 834 @return image of the selection (QImage)
835 """ 835 """
836 if cut: 836 if cut:
837 cmd = IconEditCommand(self, self.trUtf8("Cut Selection"), 837 cmd = IconEditCommand(self, self.tr("Cut Selection"),
838 self.__image) 838 self.__image)
839 839
840 img = QImage(self.__selRect.size(), QImage.Format_ARGB32) 840 img = QImage(self.__selRect.size(), QImage.Format_ARGB32)
841 img.fill(qRgba(0, 0, 0, 0)) 841 img.fill(qRgba(0, 0, 0, 0))
842 for i in range(0, self.__selRect.width()): 842 for i in range(0, self.__selRect.width()):
890 if ok: 890 if ok:
891 if img.width() > self.__image.width() or \ 891 if img.width() > self.__image.width() or \
892 img.height() > self.__image.height(): 892 img.height() > self.__image.height():
893 res = E5MessageBox.yesNo( 893 res = E5MessageBox.yesNo(
894 self, 894 self,
895 self.trUtf8("Paste"), 895 self.tr("Paste"),
896 self.trUtf8( 896 self.tr(
897 """<p>The clipboard image is larger than the""" 897 """<p>The clipboard image is larger than the"""
898 """ current image.<br/>Paste as new image?</p>""")) 898 """ current image.<br/>Paste as new image?</p>"""))
899 if res: 899 if res:
900 self.editPasteAsNew() 900 self.editPasteAsNew()
901 return 901 return
902 elif not pasting: 902 elif not pasting:
903 self.__isPasting = True 903 self.__isPasting = True
904 self.__clipboardSize = img.size() 904 self.__clipboardSize = img.size()
905 else: 905 else:
906 cmd = IconEditCommand(self, self.trUtf8("Paste Clipboard"), 906 cmd = IconEditCommand(self, self.tr("Paste Clipboard"),
907 self.__image) 907 self.__image)
908 self.__markImage.fill(self.NoMarkColor.rgba()) 908 self.__markImage.fill(self.NoMarkColor.rgba())
909 painter = QPainter(self.__image) 909 painter = QPainter(self.__image)
910 painter.setPen(self.penColor()) 910 painter.setPen(self.penColor())
911 painter.setCompositionMode(self.__compositingMode) 911 painter.setCompositionMode(self.__compositingMode)
921 self.__pasteRect.topLeft(), 921 self.__pasteRect.topLeft(),
922 self.__pasteRect.bottomRight() + QPoint(1, 1)) 922 self.__pasteRect.bottomRight() + QPoint(1, 1))
923 else: 923 else:
924 E5MessageBox.warning( 924 E5MessageBox.warning(
925 self, 925 self,
926 self.trUtf8("Pasting Image"), 926 self.tr("Pasting Image"),
927 self.trUtf8("""Invalid image data in clipboard.""")) 927 self.tr("""Invalid image data in clipboard."""))
928 928
929 def editPasteAsNew(self): 929 def editPasteAsNew(self):
930 """ 930 """
931 Public slot to paste the clipboard as a new image. 931 Public slot to paste the clipboard as a new image.
932 """ 932 """
933 img, ok = self.__clipboardImage() 933 img, ok = self.__clipboardImage()
934 if ok: 934 if ok:
935 cmd = IconEditCommand( 935 cmd = IconEditCommand(
936 self, self.trUtf8("Paste Clipboard as New Image"), 936 self, self.tr("Paste Clipboard as New Image"),
937 self.__image) 937 self.__image)
938 self.setIconImage(img) 938 self.setIconImage(img)
939 self.setDirty(True) 939 self.setDirty(True)
940 self.__undoStack.push(cmd) 940 self.__undoStack.push(cmd)
941 cmd.setAfterImage(self.__image) 941 cmd.setAfterImage(self.__image)
959 """ 959 """
960 Public slot to clear the image. 960 Public slot to clear the image.
961 """ 961 """
962 self.__unMark() 962 self.__unMark()
963 963
964 cmd = IconEditCommand(self, self.trUtf8("Clear Image"), self.__image) 964 cmd = IconEditCommand(self, self.tr("Clear Image"), self.__image)
965 self.__image.fill(qRgba(0, 0, 0, 0)) 965 self.__image.fill(qRgba(0, 0, 0, 0))
966 self.update() 966 self.update()
967 self.setDirty(True) 967 self.setDirty(True)
968 self.__undoStack.push(cmd) 968 self.__undoStack.push(cmd)
969 cmd.setAfterImage(self.__image) 969 cmd.setAfterImage(self.__image)
977 res = dlg.exec_() 977 res = dlg.exec_()
978 if res == QDialog.Accepted: 978 if res == QDialog.Accepted:
979 newWidth, newHeight = dlg.getData() 979 newWidth, newHeight = dlg.getData()
980 if newWidth != self.__image.width() or \ 980 if newWidth != self.__image.width() or \
981 newHeight != self.__image.height(): 981 newHeight != self.__image.height():
982 cmd = IconEditCommand(self, self.trUtf8("Resize Image"), 982 cmd = IconEditCommand(self, self.tr("Resize Image"),
983 self.__image) 983 self.__image)
984 img = self.__image.scaled( 984 img = self.__image.scaled(
985 newWidth, newHeight, Qt.IgnoreAspectRatio, 985 newWidth, newHeight, Qt.IgnoreAspectRatio,
986 Qt.SmoothTransformation) 986 Qt.SmoothTransformation)
987 self.setIconImage(img) 987 self.setIconImage(img)
1004 1004
1005 def grayScale(self): 1005 def grayScale(self):
1006 """ 1006 """
1007 Public slot to convert the image to gray preserving transparency. 1007 Public slot to convert the image to gray preserving transparency.
1008 """ 1008 """
1009 cmd = IconEditCommand(self, self.trUtf8("Convert to Grayscale"), 1009 cmd = IconEditCommand(self, self.tr("Convert to Grayscale"),
1010 self.__image) 1010 self.__image)
1011 for x in range(self.__image.width()): 1011 for x in range(self.__image.width()):
1012 for y in range(self.__image.height()): 1012 for y in range(self.__image.height()):
1013 col = self.__image.pixel(x, y) 1013 col = self.__image.pixel(x, y)
1014 if col != qRgba(0, 0, 0, 0): 1014 if col != qRgba(0, 0, 0, 0):

eric ide

mercurial