# eric7.IconEditor.IconEditorGrid

Module implementing the icon editor grid.

### Global Attributes

None

### Classes

IconEditCommand | Class implementing an undo command for the icon editor.
IconEditorGrid | Class implementing the icon editor grid.
IconEditorTool | Class defining the edit tools.

### Functions

None

## IconEditCommand

Class implementing an undo command for the icon editor.

### Derived from

QUndoCommand

### Class Attributes

None

### Class Methods

None

### Methods

IconEditCommand | Constructor
redo | Public method to perform the redo.
setAfterImage | Public method to set the image after the changes were applied.
undo | Public method to perform the undo.

### Static Methods

None

#### IconEditCommand (Constructor)

IconEditCommand(grid, text, oldImage, parent=None)

Constructor

grid (IconEditorGrid)
  reference to the icon editor grid
text (str)
  text for the undo command
oldImage (QImage)
  copy of the icon before the changes were applied
parent (QUndoCommand)
  reference to the parent command

#### IconEditCommand.redo

redo()

Public method to perform the redo.

#### IconEditCommand.setAfterImage

setAfterImage(image)

Public method to set the image after the changes were applied.

image (QImage)
  copy of the icon after the changes were applied

#### IconEditCommand.undo

undo()

Public method to perform the undo.

Up

## IconEditorGrid

Class implementing the icon editor grid.

### Signals

canRedoChanged(bool)
  emitted after the redo status has changed
canUndoChanged(bool)
  emitted after the undo status has changed
clipboardImageAvailable(bool)
  emitted to signal the availability of an image to be pasted
colorChanged(QColor)
  emitted after the drawing color was changed
imageChanged(bool)
  emitted after the image was modified
positionChanged(int, int)
  emitted after the cursor poition was changed
previewChanged(QPixmap)
  emitted to signal a new preview pixmap
selectionAvailable(bool)
  emitted to signal a change of the selection
sizeChanged(int, int)
  emitted after the size has been changed
zoomChanged(int)
  emitted to signal a change of the zoom value

### Derived from

QWidget

### Class Attributes

MarkColor
NoMarkColor
ZoomDefault
ZoomMaximum
ZoomMinimum
ZoomPercent
ZoomStep

### Class Methods

None

### Methods

IconEditorGrid | Constructor
__checkClipboard | Private slot to check, if the clipboard contains a valid image, and signal the result.
__cleanChanged | Private slot to handle the undo stack clean state change.
__clipboardImage | Private method to get an image from the clipboard.
__drawFlood | Private method to perform a flood fill operation.
__drawPasteRect | Private slot to draw a rectangle for signaling a paste operation.
__drawTool | Private method to perform a draw operation depending of the current tool.
__getSelectionImage | Private method to get an image from the selection.
__imageCoordinates | Private method to convert from widget to image coordinates.
__initCursors | Private method to initialize the various cursors.
__initUndoTexts | Private method to initialize texts to be associated with undo commands for the various drawing tools.
__isMarked | Private method to check, if a pixel is marked.
__pixelRect | Private method to determine the rectangle for a given pixel coordinate.
__setImagePixel | Private slot to set or erase a pixel.
__unMark | Private slot to remove the mark indicator.
__updateImageRect | Private slot to update parts of the widget.
__updatePreviewPixmap | Private slot to generate and signal an updated preview pixmap.
__updateRect | Private slot to update parts of the widget.
canPaste | Public slot to check the availability of the paste operation.
canRedo | Public method to return the redo status.
canUndo | Public method to return the undo status.
compositingMode | Public method to get the compositing mode.
editClear | Public slot to clear the image.
editCopy | Public slot to copy the selection.
editCut | Public slot to cut the selection.
editNew | Public slot to generate a new, empty image.
editPaste | Public slot to paste an image from the clipboard.
editPasteAsNew | Public slot to paste the clipboard as a new image.
editRedo | Public slot to perform a redo operation.
editResize | Public slot to resize the image.
editSelectAll | Public slot to select the complete image.
editUndo | Public slot to perform an undo operation.
grayScale | Public slot to convert the image to gray preserving transparency.
iconImage | Public method to get a copy of the icon image.
iconSize | Public method to get the size of the icon.
isDirty | Public method to check the dirty status.
isGridEnabled | Public method to get the grid lines status.
isSelectionAvailable | Public method to check the availability of a selection.
mouseMoveEvent | Protected method to handle mouse move events.
mousePressEvent | Protected method to handle mouse button press events.
mouseReleaseEvent | Protected method to handle mouse button release events.
paintEvent | Protected method called to repaint some of the widget.
penColor | Public method to get the current drawing color.
previewPixmap | Public method to generate a preview pixmap.
setCompositingMode | Public method to set the compositing mode.
setDirty | Public slot to set the dirty flag.
setGridEnabled | Public method to enable the display of grid lines.
setIconImage | Public method to set a new icon image.
setPenColor | Public method to set the drawing color.
setTool | Public method to set the current drawing tool.
setZoomFactor | Public method to set the zoom factor in percent.
shutdown | Public slot to perform some shutdown actions.
sizeHint | Public method to report the size hint.
tool | Public method to get the current drawing tool.
zoomFactor | Public method to get the current zoom factor in percent.

### Static Methods

None

#### IconEditorGrid (Constructor)

IconEditorGrid(parent=None)

Constructor

parent (QWidget)
  reference to the parent widget

#### IconEditorGrid.__checkClipboard

__checkClipboard()

Private slot to check, if the clipboard contains a valid image, and signal the result.

#### IconEditorGrid.__cleanChanged

__cleanChanged(clean)

Private slot to handle the undo stack clean state change.

clean (bool)
  flag indicating the clean state

#### IconEditorGrid.__clipboardImage

__clipboardImage()

Private method to get an image from the clipboard.

Return:
  tuple with the image (QImage) and a flag indicating a valid image

Return Type:
  bool

#### IconEditorGrid.__drawFlood

__drawFlood(i, j, oldColor, doUpdate=True)

Private method to perform a flood fill operation.

i (int)
  x-value in image coordinates
j (int)
  y-value in image coordinates
oldColor (QColor)
  reference to the color at position i, j
doUpdate (bool)
  flag indicating an update is requested (used for speed optimizations)

#### IconEditorGrid.__drawPasteRect

__drawPasteRect(pos)

Private slot to draw a rectangle for signaling a paste operation.

pos (QPoint)
  widget position of the paste rectangle

#### IconEditorGrid.__drawTool

__drawTool(pos, mark)

Private method to perform a draw operation depending of the current tool.

pos (QPoint)
  widget coordinate to perform the draw operation at
mark (bool)
  flag indicating a mark operation

Return:
  flag indicating a successful draw

Return Type:
  bool

#### IconEditorGrid.__getSelectionImage

__getSelectionImage(cut)

Private method to get an image from the selection.

cut (bool)
  flag indicating to cut the selection

Return:
  image of the selection

Return Type:
  QImage

#### IconEditorGrid.__imageCoordinates

__imageCoordinates(pos)

Private method to convert from widget to image coordinates.

pos (QPoint)
  widget coordinate

Return:
  tuple with the image coordinates

Return Type:
  tuple of (int, int)

#### IconEditorGrid.__initCursors

__initCursors()

Private method to initialize the various cursors.

#### IconEditorGrid.__initUndoTexts

__initUndoTexts()

Private method to initialize texts to be associated with undo commands for the various drawing tools.

#### IconEditorGrid.__isMarked

__isMarked(i, j)

Private method to check, if a pixel is marked.

i (int)
  x-value in image coordinates
j (int)
  y-value in image coordinates

Return:
  flag indicating a marked pixel

Return Type:
  bool

#### IconEditorGrid.__pixelRect

__pixelRect(i, j)

Private method to determine the rectangle for a given pixel coordinate.

i (int)
  x-coordinate of the pixel in the image
j (int)
  y-coordinate of the pixel in the image

Return:
  rectangle for the given pixel coordinates

Return Type:
  QRect

#### IconEditorGrid.__setImagePixel

__setImagePixel(pos, opaque)

Private slot to set or erase a pixel.

pos (QPoint)
  position of the pixel in the widget
opaque (bool)
  flag indicating a set operation

#### IconEditorGrid.__unMark

__unMark()

Private slot to remove the mark indicator.

#### IconEditorGrid.__updateImageRect

__updateImageRect(ipos1, ipos2)

Private slot to update parts of the widget.

ipos1 (QPoint)
  top, left position for the update in image coordinates
ipos2 (QPoint)
  bottom, right position for the update in image coordinates

#### IconEditorGrid.__updatePreviewPixmap

__updatePreviewPixmap()

Private slot to generate and signal an updated preview pixmap.

#### IconEditorGrid.__updateRect

__updateRect(pos1, pos2)

Private slot to update parts of the widget.

pos1 (QPoint)
  top, left position for the update in widget coordinates
pos2 (QPoint)
  bottom, right position for the update in widget coordinates

#### IconEditorGrid.canPaste

canPaste()

Public slot to check the availability of the paste operation.

Return:
  flag indicating availability of paste

Return Type:
  bool

#### IconEditorGrid.canRedo

canRedo()

Public method to return the redo status.

Return:
  flag indicating the availability of redo

Return Type:
  bool

#### IconEditorGrid.canUndo

canUndo()

Public method to return the undo status.

Return:
  flag indicating the availability of undo

Return Type:
  bool

#### IconEditorGrid.compositingMode

compositingMode()

Public method to get the compositing mode.

Return:
  compositing mode

Return Type:
  QPainter.CompositionMode

#### IconEditorGrid.editClear

editClear()

Public slot to clear the image.

#### IconEditorGrid.editCopy

editCopy()

Public slot to copy the selection.

#### IconEditorGrid.editCut

editCut()

Public slot to cut the selection.

#### IconEditorGrid.editNew

editNew()

Public slot to generate a new, empty image.

#### IconEditorGrid.editPaste

editPaste(pasting=False)

Public slot to paste an image from the clipboard.

pasting (bool)
  flag indicating part two of the paste operation

#### IconEditorGrid.editPasteAsNew

editPasteAsNew()

Public slot to paste the clipboard as a new image.

#### IconEditorGrid.editRedo

editRedo()

Public slot to perform a redo operation.

#### IconEditorGrid.editResize

editResize()

Public slot to resize the image.

#### IconEditorGrid.editSelectAll

editSelectAll()

Public slot to select the complete image.

#### IconEditorGrid.editUndo

editUndo()

Public slot to perform an undo operation.

#### IconEditorGrid.grayScale

grayScale()

Public slot to convert the image to gray preserving transparency.

#### IconEditorGrid.iconImage

iconImage()

Public method to get a copy of the icon image.

Return:
  copy of the icon image

Return Type:
  QImage

#### IconEditorGrid.iconSize

iconSize()

Public method to get the size of the icon.

Return:
  width and height of the image as a tuple

Return Type:
  tuple of (int, int)

#### IconEditorGrid.isDirty

isDirty()

Public method to check the dirty status.

Return:
  flag indicating a modified status

Return Type:
  bool

#### IconEditorGrid.isGridEnabled

isGridEnabled()

Public method to get the grid lines status.

Return:
  enabled status of the grid lines

Return Type:
  bool

#### IconEditorGrid.isSelectionAvailable

isSelectionAvailable()

Public method to check the availability of a selection.

Return:
  flag indicating the availability of a selection

Return Type:
  bool

#### IconEditorGrid.mouseMoveEvent

mouseMoveEvent(evt)

Protected method to handle mouse move events.

evt (QMouseEvent)
  reference to the mouse event object

#### IconEditorGrid.mousePressEvent

mousePressEvent(evt)

Protected method to handle mouse button press events.

evt (QMouseEvent)
  reference to the mouse event object

#### IconEditorGrid.mouseReleaseEvent

mouseReleaseEvent(evt)

Protected method to handle mouse button release events.

evt (QMouseEvent)
  reference to the mouse event object

#### IconEditorGrid.paintEvent

paintEvent(evt)

Protected method called to repaint some of the widget.

evt (QPaintEvent)
  reference to the paint event object

#### IconEditorGrid.penColor

penColor()

Public method to get the current drawing color.

Return:
  current drawing color

Return Type:
  QColor

#### IconEditorGrid.previewPixmap

previewPixmap()

Public method to generate a preview pixmap.

Return:
  preview pixmap

Return Type:
  QPixmap

#### IconEditorGrid.setCompositingMode

setCompositingMode(mode)

Public method to set the compositing mode.

mode (QPainter.CompositionMode)
  compositing mode to set

#### IconEditorGrid.setDirty

setDirty(dirty, setCleanState=False)

Public slot to set the dirty flag.

dirty (bool)
  flag indicating the new modification status
setCleanState (bool)
  flag indicating to set the undo stack to clean

#### IconEditorGrid.setGridEnabled

setGridEnabled(enable)

Public method to enable the display of grid lines.

enable (bool)
  enabled status of the grid lines

#### IconEditorGrid.setIconImage

setIconImage(newImage, undoRedo=False, clearUndo=False)

Public method to set a new icon image.

newImage (QImage)
  reference to the new image
undoRedo (bool)
  flag indicating an undo or redo operation
clearUndo (bool)
  flag indicating to clear the undo stack

#### IconEditorGrid.setPenColor

setPenColor(newColor)

Public method to set the drawing color.

newColor (QColor)
  reference to the new color

#### IconEditorGrid.setTool

setTool(tool)

Public method to set the current drawing tool.

tool (IconEditorTool)
  drawing tool to be used

#### IconEditorGrid.setZoomFactor

setZoomFactor(newZoom)

Public method to set the zoom factor in percent.

newZoom (int)
  zoom factor (>= 100)

#### IconEditorGrid.shutdown

shutdown()

Public slot to perform some shutdown actions.

#### IconEditorGrid.sizeHint

sizeHint()

Public method to report the size hint.

Return:
  size hint

Return Type:
  QSize

#### IconEditorGrid.tool

tool()

Public method to get the current drawing tool.

Return:
  current drawing tool

Return Type:
  IconEditorTool

#### IconEditorGrid.zoomFactor

zoomFactor()

Public method to get the current zoom factor in percent.

Return:
  zoom factor

Return Type:
  int

Up

## IconEditorTool

Class defining the edit tools.

### Derived from

enum.IntEnum

### Class Attributes

CIRCLE
COLOR_PICKER
ELLIPSE
FILL
FILLED_CIRCLE
FILLED_ELLIPSE
FILLED_RECTANGLE
LINE
PENCIL
RECTANGLE
RUBBER
SELECT_CIRCLE
SELECT_RECTANGLE

### Class Methods

None

### Methods

None

### Static Methods

None

Up