IconEditor/IconEditorGrid.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3345
071afe8be2a1
child 3539
0c2dc1446ebf
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
7 Module implementing the icon editor grid. 7 Module implementing the icon editor grid.
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 from PyQt4.QtCore import pyqtSignal, Qt, QPoint, QRect, QSize 12 from PyQt4.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QRect, QSize
13 from PyQt4.QtGui import QUndoCommand, QImage, QWidget, QColor, QPixmap, \ 13 from PyQt4.QtGui import QUndoCommand, QImage, QWidget, QColor, QPixmap, \
14 QSizePolicy, QUndoStack, qRgba, QPainter, QApplication, QCursor, \ 14 QSizePolicy, QUndoStack, qRgba, QPainter, QApplication, QCursor, \
15 QBrush, QDialog, qGray, qAlpha 15 QBrush, QDialog, qGray, qAlpha
16 16
17 from E5Gui import E5MessageBox 17 from E5Gui import E5MessageBox
200 """ 200 """
201 Private method to initialize texts to be associated with undo commands 201 Private method to initialize texts to be associated with undo commands
202 for the various drawing tools. 202 for the various drawing tools.
203 """ 203 """
204 self.__undoTexts = { 204 self.__undoTexts = {
205 self.Pencil: self.trUtf8("Set Pixel"), 205 self.Pencil: self.tr("Set Pixel"),
206 self.Rubber: self.trUtf8("Erase Pixel"), 206 self.Rubber: self.tr("Erase Pixel"),
207 self.Line: self.trUtf8("Draw Line"), 207 self.Line: self.tr("Draw Line"),
208 self.Rectangle: self.trUtf8("Draw Rectangle"), 208 self.Rectangle: self.tr("Draw Rectangle"),
209 self.FilledRectangle: self.trUtf8("Draw Filled Rectangle"), 209 self.FilledRectangle: self.tr("Draw Filled Rectangle"),
210 self.Circle: self.trUtf8("Draw Circle"), 210 self.Circle: self.tr("Draw Circle"),
211 self.FilledCircle: self.trUtf8("Draw Filled Circle"), 211 self.FilledCircle: self.tr("Draw Filled Circle"),
212 self.Ellipse: self.trUtf8("Draw Ellipse"), 212 self.Ellipse: self.tr("Draw Ellipse"),
213 self.FilledEllipse: self.trUtf8("Draw Filled Ellipse"), 213 self.FilledEllipse: self.tr("Draw Filled Ellipse"),
214 self.Fill: self.trUtf8("Fill Region"), 214 self.Fill: self.tr("Fill Region"),
215 } 215 }
216 216
217 def isDirty(self): 217 def isDirty(self):
218 """ 218 """
219 Public method to check the dirty status. 219 Public method to check the dirty status.
834 834
835 @param cut flag indicating to cut the selection (boolean) 835 @param cut flag indicating to cut the selection (boolean)
836 @return image of the selection (QImage) 836 @return image of the selection (QImage)
837 """ 837 """
838 if cut: 838 if cut:
839 cmd = IconEditCommand(self, self.trUtf8("Cut Selection"), 839 cmd = IconEditCommand(self, self.tr("Cut Selection"),
840 self.__image) 840 self.__image)
841 841
842 img = QImage(self.__selRect.size(), QImage.Format_ARGB32) 842 img = QImage(self.__selRect.size(), QImage.Format_ARGB32)
843 img.fill(qRgba(0, 0, 0, 0)) 843 img.fill(qRgba(0, 0, 0, 0))
844 for i in range(0, self.__selRect.width()): 844 for i in range(0, self.__selRect.width()):
879 """ 879 """
880 if self.__selRect.isValid(): 880 if self.__selRect.isValid():
881 img = self.__getSelectionImage(True) 881 img = self.__getSelectionImage(True)
882 QApplication.clipboard().setImage(img) 882 QApplication.clipboard().setImage(img)
883 883
884 @pyqtSlot()
884 def editPaste(self, pasting=False): 885 def editPaste(self, pasting=False):
885 """ 886 """
886 Public slot to paste an image from the clipboard. 887 Public slot to paste an image from the clipboard.
887 888
888 @param pasting flag indicating part two of the paste operation 889 @param pasting flag indicating part two of the paste operation
892 if ok: 893 if ok:
893 if img.width() > self.__image.width() or \ 894 if img.width() > self.__image.width() or \
894 img.height() > self.__image.height(): 895 img.height() > self.__image.height():
895 res = E5MessageBox.yesNo( 896 res = E5MessageBox.yesNo(
896 self, 897 self,
897 self.trUtf8("Paste"), 898 self.tr("Paste"),
898 self.trUtf8( 899 self.tr(
899 """<p>The clipboard image is larger than the""" 900 """<p>The clipboard image is larger than the"""
900 """ current image.<br/>Paste as new image?</p>""")) 901 """ current image.<br/>Paste as new image?</p>"""))
901 if res: 902 if res:
902 self.editPasteAsNew() 903 self.editPasteAsNew()
903 return 904 return
904 elif not pasting: 905 elif not pasting:
905 self.__isPasting = True 906 self.__isPasting = True
906 self.__clipboardSize = img.size() 907 self.__clipboardSize = img.size()
907 else: 908 else:
908 cmd = IconEditCommand(self, self.trUtf8("Paste Clipboard"), 909 cmd = IconEditCommand(self, self.tr("Paste Clipboard"),
909 self.__image) 910 self.__image)
910 self.__markImage.fill(self.NoMarkColor.rgba()) 911 self.__markImage.fill(self.NoMarkColor.rgba())
911 painter = QPainter(self.__image) 912 painter = QPainter(self.__image)
912 painter.setPen(self.penColor()) 913 painter.setPen(self.penColor())
913 painter.setCompositionMode(self.__compositingMode) 914 painter.setCompositionMode(self.__compositingMode)
923 self.__pasteRect.topLeft(), 924 self.__pasteRect.topLeft(),
924 self.__pasteRect.bottomRight() + QPoint(1, 1)) 925 self.__pasteRect.bottomRight() + QPoint(1, 1))
925 else: 926 else:
926 E5MessageBox.warning( 927 E5MessageBox.warning(
927 self, 928 self,
928 self.trUtf8("Pasting Image"), 929 self.tr("Pasting Image"),
929 self.trUtf8("""Invalid image data in clipboard.""")) 930 self.tr("""Invalid image data in clipboard."""))
930 931
931 def editPasteAsNew(self): 932 def editPasteAsNew(self):
932 """ 933 """
933 Public slot to paste the clipboard as a new image. 934 Public slot to paste the clipboard as a new image.
934 """ 935 """
935 img, ok = self.__clipboardImage() 936 img, ok = self.__clipboardImage()
936 if ok: 937 if ok:
937 cmd = IconEditCommand( 938 cmd = IconEditCommand(
938 self, self.trUtf8("Paste Clipboard as New Image"), 939 self, self.tr("Paste Clipboard as New Image"),
939 self.__image) 940 self.__image)
940 self.setIconImage(img) 941 self.setIconImage(img)
941 self.setDirty(True) 942 self.setDirty(True)
942 self.__undoStack.push(cmd) 943 self.__undoStack.push(cmd)
943 cmd.setAfterImage(self.__image) 944 cmd.setAfterImage(self.__image)
961 """ 962 """
962 Public slot to clear the image. 963 Public slot to clear the image.
963 """ 964 """
964 self.__unMark() 965 self.__unMark()
965 966
966 cmd = IconEditCommand(self, self.trUtf8("Clear Image"), self.__image) 967 cmd = IconEditCommand(self, self.tr("Clear Image"), self.__image)
967 self.__image.fill(qRgba(0, 0, 0, 0)) 968 self.__image.fill(qRgba(0, 0, 0, 0))
968 self.update() 969 self.update()
969 self.setDirty(True) 970 self.setDirty(True)
970 self.__undoStack.push(cmd) 971 self.__undoStack.push(cmd)
971 cmd.setAfterImage(self.__image) 972 cmd.setAfterImage(self.__image)
979 res = dlg.exec_() 980 res = dlg.exec_()
980 if res == QDialog.Accepted: 981 if res == QDialog.Accepted:
981 newWidth, newHeight = dlg.getData() 982 newWidth, newHeight = dlg.getData()
982 if newWidth != self.__image.width() or \ 983 if newWidth != self.__image.width() or \
983 newHeight != self.__image.height(): 984 newHeight != self.__image.height():
984 cmd = IconEditCommand(self, self.trUtf8("Resize Image"), 985 cmd = IconEditCommand(self, self.tr("Resize Image"),
985 self.__image) 986 self.__image)
986 img = self.__image.scaled( 987 img = self.__image.scaled(
987 newWidth, newHeight, Qt.IgnoreAspectRatio, 988 newWidth, newHeight, Qt.IgnoreAspectRatio,
988 Qt.SmoothTransformation) 989 Qt.SmoothTransformation)
989 self.setIconImage(img) 990 self.setIconImage(img)
1006 1007
1007 def grayScale(self): 1008 def grayScale(self):
1008 """ 1009 """
1009 Public slot to convert the image to gray preserving transparency. 1010 Public slot to convert the image to gray preserving transparency.
1010 """ 1011 """
1011 cmd = IconEditCommand(self, self.trUtf8("Convert to Grayscale"), 1012 cmd = IconEditCommand(self, self.tr("Convert to Grayscale"),
1012 self.__image) 1013 self.__image)
1013 for x in range(self.__image.width()): 1014 for x in range(self.__image.width()):
1014 for y in range(self.__image.height()): 1015 for y in range(self.__image.height()):
1015 col = self.__image.pixel(x, y) 1016 col = self.__image.pixel(x, y)
1016 if col != qRgba(0, 0, 0, 0): 1017 if col != qRgba(0, 0, 0, 0):

eric ide

mercurial