eric7/IconEditor/IconEditorGrid.py

branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8353
799196d0b05d
equal deleted inserted replaced
8316:0c7a44af84bc 8318:962bce857696
7 Module implementing the icon editor grid. 7 Module implementing the icon editor grid.
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt5.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QRect, QSize 12 from PyQt6.QtCore import pyqtSignal, pyqtSlot, Qt, QPoint, QRect, QSize
13 from PyQt5.QtGui import ( 13 from PyQt6.QtGui import (
14 QImage, QColor, QPixmap, qRgba, QPainter, QCursor, QBrush, qGray, qAlpha 14 QImage, QColor, QPixmap, qRgba, QPainter, QCursor, QBrush, qGray, qAlpha,
15 QUndoCommand, QUndoStack
15 ) 16 )
16 from PyQt5.QtWidgets import ( 17 from PyQt6.QtWidgets import QWidget, QSizePolicy, QApplication, QDialog
17 QUndoCommand, QWidget, QSizePolicy, QUndoStack, QApplication, QDialog
18 )
19 18
20 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
21 20
22 21
23 class IconEditCommand(QUndoCommand): 22 class IconEditCommand(QUndoCommand):
484 return 483 return
485 484
486 if self.__curTool == self.Pencil: 485 if self.__curTool == self.Pencil:
487 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool], 486 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool],
488 self.__image) 487 self.__image)
489 self.__setImagePixel(evt.pos(), True) 488 self.__setImagePixel(evt.position().toPoint(), True)
490 self.setDirty(True) 489 self.setDirty(True)
491 self.__undoStack.push(cmd) 490 self.__undoStack.push(cmd)
492 self.__currentUndoCmd = cmd 491 self.__currentUndoCmd = cmd
493 elif self.__curTool == self.Rubber: 492 elif self.__curTool == self.Rubber:
494 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool], 493 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool],
495 self.__image) 494 self.__image)
496 self.__setImagePixel(evt.pos(), False) 495 self.__setImagePixel(evt.position().toPoint(), False)
497 self.setDirty(True) 496 self.setDirty(True)
498 self.__undoStack.push(cmd) 497 self.__undoStack.push(cmd)
499 self.__currentUndoCmd = cmd 498 self.__currentUndoCmd = cmd
500 elif self.__curTool == self.Fill: 499 elif self.__curTool == self.Fill:
501 i, j = self.__imageCoordinates(evt.pos()) 500 i, j = self.__imageCoordinates(evt.position().toPoint())
502 col = QColor() 501 col = QColor()
503 col.setRgba(self.__image.pixel(i, j)) 502 col.setRgba(self.__image.pixel(i, j))
504 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool], 503 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool],
505 self.__image) 504 self.__image)
506 self.__drawFlood(i, j, col) 505 self.__drawFlood(i, j, col)
507 self.setDirty(True) 506 self.setDirty(True)
508 self.__undoStack.push(cmd) 507 self.__undoStack.push(cmd)
509 cmd.setAfterImage(self.__image) 508 cmd.setAfterImage(self.__image)
510 elif self.__curTool == self.ColorPicker: 509 elif self.__curTool == self.ColorPicker:
511 i, j = self.__imageCoordinates(evt.pos()) 510 i, j = self.__imageCoordinates(evt.position().toPoint())
512 col = QColor() 511 col = QColor()
513 col.setRgba(self.__image.pixel(i, j)) 512 col.setRgba(self.__image.pixel(i, j))
514 self.setPenColor(col) 513 self.setPenColor(col)
515 else: 514 else:
516 self.__unMark() 515 self.__unMark()
517 self.__startPos = evt.pos() 516 self.__startPos = evt.position().toPoint()
518 self.__endPos = evt.pos() 517 self.__endPos = evt.position().toPoint()
519 518
520 def mouseMoveEvent(self, evt): 519 def mouseMoveEvent(self, evt):
521 """ 520 """
522 Protected method to handle mouse move events. 521 Protected method to handle mouse move events.
523 522
524 @param evt reference to the mouse event object (QMouseEvent) 523 @param evt reference to the mouse event object (QMouseEvent)
525 """ 524 """
526 self.positionChanged.emit(*self.__imageCoordinates(evt.pos())) 525 self.positionChanged.emit(*self.__imageCoordinates(evt.position().toPoint()))
527 526
528 if ( 527 if (
529 self.__isPasting and 528 self.__isPasting and
530 not (evt.buttons() & Qt.MouseButton.LeftButton) 529 not (evt.buttons() & Qt.MouseButton.LeftButton)
531 ): 530 ):
532 self.__drawPasteRect(evt.pos()) 531 self.__drawPasteRect(evt.position().toPoint())
533 return 532 return
534 533
535 if evt.buttons() & Qt.MouseButton.LeftButton: 534 if evt.buttons() & Qt.MouseButton.LeftButton:
536 if self.__curTool == self.Pencil: 535 if self.__curTool == self.Pencil:
537 self.__setImagePixel(evt.pos(), True) 536 self.__setImagePixel(evt.position().toPoint(), True)
538 self.setDirty(True) 537 self.setDirty(True)
539 elif self.__curTool == self.Rubber: 538 elif self.__curTool == self.Rubber:
540 self.__setImagePixel(evt.pos(), False) 539 self.__setImagePixel(evt.position().toPoint(), False)
541 self.setDirty(True) 540 self.setDirty(True)
542 elif self.__curTool in [self.Fill, self.ColorPicker]: 541 elif self.__curTool in [self.Fill, self.ColorPicker]:
543 pass # do nothing 542 pass # do nothing
544 else: 543 else:
545 self.__drawTool(evt.pos(), True) 544 self.__drawTool(evt.position().toPoint(), True)
546 545
547 def mouseReleaseEvent(self, evt): 546 def mouseReleaseEvent(self, evt):
548 """ 547 """
549 Protected method to handle mouse button release events. 548 Protected method to handle mouse button release events.
550 549
562 self.Fill, self.ColorPicker, 561 self.Fill, self.ColorPicker,
563 self.RectangleSelection, 562 self.RectangleSelection,
564 self.CircleSelection]: 563 self.CircleSelection]:
565 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool], 564 cmd = IconEditCommand(self, self.__undoTexts[self.__curTool],
566 self.__image) 565 self.__image)
567 if self.__drawTool(evt.pos(), False): 566 if self.__drawTool(evt.position().toPoint(), False):
568 self.__undoStack.push(cmd) 567 self.__undoStack.push(cmd)
569 cmd.setAfterImage(self.__image) 568 cmd.setAfterImage(self.__image)
570 self.setDirty(True) 569 self.setDirty(True)
571 570
572 def __setImagePixel(self, pos, opaque): 571 def __setImagePixel(self, pos, opaque):

eric ide

mercurial