示例#1
0
class LoadedImage(QLabel):
    def __init__(self, parent):
        QLabel.__init__(self)
        self.parent = parent
        self.copyMenu = CopyMenu(self)
        self.copySelectionMenu = CopySelectionMenu(self)
        self.baseImage = QImage()
        self.matrix = QMatrix()
        self.zoomer = 1
        self.maxsize = 1024 * 10 * 10 * 10 * 25
        self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        self.setAlignment(Qt.AlignCenter)
        self.rubberBand = None

    def setParent(self, parent):
        self.parent = parent

    def load(self, node):
        self.matrix.reset()
        self.zoomer = 1
        if node.size() < self.maxsize:
            self.node = node
            file = self.node.open()
            buff = file.read()
            file.close()
            if self.baseImage.loadFromData(buff):
                self.emit(SIGNAL("available(bool)"), True)
            else:
                self.baseImage.load(":file_broken.png")
                self.emit(SIGNAL("available(bool)"), False)
        else:
            self.baseImage.loadFromData("")
            self.emit(SIGNAL("available(bool)"), False)
        self.adjust()

    def adjust(self):
        if self.zoomer == 1:
            if self.baseImage.width() < self.parent.width() - 10:
                self.curWidth = self.baseImage.width()
            else:
                self.curWidth = self.parent.width() - 10
            if self.baseImage.height() < self.parent.height() - 10:
                self.curHeight = self.baseImage.height()
            else:
                self.curHeight = self.parent.height() - 10
        self.updateTransforms()

    def updateTransforms(self):
        if not self.baseImage.isNull():
            self.currentImage = self.baseImage.transformed(self.matrix).scaled(
                QSize(self.curWidth, self.curHeight), Qt.KeepAspectRatio,
                Qt.FastTransformation)
            self.setPixmap(QPixmap.fromImage(self.currentImage))
        else:
            self.clear()
            self.setText("File is too big to be processed")
        self.adjustSize()

    def rotateLeft(self):
        self.matrix.rotate(-90)
        self.updateTransforms()

    def rotateRight(self):
        self.matrix.rotate(90)
        self.updateTransforms()

    def enlarge(self):
        self.zoomer *= 1.25
        self.curWidth *= 1.25
        self.curHeight *= 1.25
        self.updateTransforms()

    def shrink(self):
        self.zoomer *= 0.8
        self.curWidth *= 0.8
        self.curHeight *= 0.8
        self.updateTransforms()

    def fit(self):
        self.zoomer = 1
        self.adjust()

    def normal(self):
        self.curWidth = self.baseImage.width()
        self.curHeight = self.baseImage.height()
        self.updateTransforms()

    def mousePressEvent(self, event):
        self.dragPosition = event.pos()
        if not self.rubberBand:
            self.rubberBand = QRubberBand(QRubberBand.Rectangle, self)
        self.rubberBand.setGeometry(QRect(self.dragPosition, QSize()))
        self.rubberBand.show()

    def mouseMoveEvent(self, event):
        self.rubberBand.setGeometry(
            QRect(self.dragPosition, event.pos()).normalized())

    def mouseReleaseEvent(self, event):
        if not self.rubberBand.size().isEmpty():
            rect = QRect(self.rubberBand.pos(), self.rubberBand.size())
            rect.moveLeft(rect.left() -
                          (self.width() - self.pixmap().width()) / 2.0)
            rect.moveTop(rect.top() -
                         (self.height() - self.pixmap().height()) / 2.0)
            self.currentSelection = rect
            self.copySelectionMenu.popup(QCursor.pos())
        else:
            self.copyMenu.popup(QCursor.pos())
        self.rubberBand.hide()

    def copySelectionToClipboard(self):
        QApplication.clipboard().setPixmap(self.pixmap().copy(
            self.currentSelection))

    def copyPixmapToClipboard(self):
        QApplication.clipboard().setPixmap(self.pixmap())
示例#2
0
class LoadedImage(QLabel):
  def __init__(self, parent):
    QLabel.__init__(self)
    self.parent = parent
    self.baseImage = QImage()
    self.matrix = QMatrix()
    self.zoomer = 1
    self.maxsize = 1024*10*10*10*25
    self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored);
    self.setAlignment(Qt.AlignCenter)

  def setParent(self, parent):
    self.parent = parent

  def load(self, node):
    self.matrix.reset()
    self.zoomer = 1
    if node.size() < self.maxsize:
       self.node = node
       file = self.node.open()
       buff = file.read()
       file.close()
       if self.baseImage.loadFromData(buff):
         self.emit(SIGNAL("available(bool)"), True)
       else:
         self.baseImage.load(":file_broken.png")
         self.emit(SIGNAL("available(bool)"), False)
    else:
      self.baseImage.loadFromData("")
      self.emit(SIGNAL("available(bool)"), False)
    self.adjust()


  def adjust(self):
    if self.zoomer == 1:
      if self.baseImage.width() < self.parent.width() - 10:
        self.curWidth = self.baseImage.width()
      else:
        self.curWidth = self.parent.width() - 10
      if self.baseImage.height() < self.parent.height() - 10:
        self.curHeight = self.baseImage.height()
      else:
        self.curHeight = self.parent.height() - 10
    self.updateTransforms()


  def updateTransforms(self):
    if not self.baseImage.isNull():
      self.currentImage = self.baseImage.transformed(self.matrix).scaled(QSize(self.curWidth, self.curHeight), Qt.KeepAspectRatio, Qt.FastTransformation)
      self.setPixmap(QPixmap.fromImage(self.currentImage))
    else:
      self.clear()
      self.setText("File is too big to be processed")
    self.adjustSize()


  def rotateLeft(self):
    self.matrix.rotate(-90)
    self.updateTransforms()


  def rotateRight(self):
    self.matrix.rotate(90)
    self.updateTransforms()


  def enlarge(self):
    self.zoomer *= 1.25
    self.curWidth *= 1.25
    self.curHeight *= 1.25
    self.updateTransforms()


  def shrink(self):
    self.zoomer *= 0.8
    self.curWidth *= 0.8
    self.curHeight *= 0.8
    self.updateTransforms()


  def fit(self):
    self.zoomer = 1
    self.adjust()


  def normal(self):
    self.curWidth = self.baseImage.width()
    self.curHeight = self.baseImage.height()
    self.updateTransforms()
示例#3
0
class LoadedImage(QLabel):
    def __init__(self, parent):
        QLabel.__init__(self)
        self.parent = parent
        self.baseImage = QImage()
        self.matrix = QMatrix()
        self.zoomer = 1
        self.maxsize = 1024 * 10 * 10 * 10 * 25
        self.setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
        self.setAlignment(Qt.AlignCenter)

    def setParent(self, parent):
        self.parent = parent

    def load(self, node):
        self.matrix.reset()
        self.zoomer = 1
        if node.size() < self.maxsize:
            self.node = node
            file = self.node.open()
            buff = file.read()
            file.close()
            if self.baseImage.loadFromData(buff):
                self.emit(SIGNAL("available(bool)"), True)
            else:
                self.baseImage.load(":file_broken.png")
                self.emit(SIGNAL("available(bool)"), False)
        else:
            self.baseImage.loadFromData("")
            self.emit(SIGNAL("available(bool)"), False)
        self.adjust()

    def adjust(self):
        if self.zoomer == 1:
            if self.baseImage.width() < self.parent.width() - 10:
                self.curWidth = self.baseImage.width()
            else:
                self.curWidth = self.parent.width() - 10
            if self.baseImage.height() < self.parent.height() - 10:
                self.curHeight = self.baseImage.height()
            else:
                self.curHeight = self.parent.height() - 10
        self.updateTransforms()

    def updateTransforms(self):
        if not self.baseImage.isNull():
            self.currentImage = self.baseImage.transformed(self.matrix).scaled(
                QSize(self.curWidth, self.curHeight), Qt.KeepAspectRatio,
                Qt.FastTransformation)
            self.setPixmap(QPixmap.fromImage(self.currentImage))
        else:
            self.clear()
            self.setText("File is too big to be processed")
        self.adjustSize()

    def rotateLeft(self):
        self.matrix.rotate(-90)
        self.updateTransforms()

    def rotateRight(self):
        self.matrix.rotate(90)
        self.updateTransforms()

    def enlarge(self):
        self.zoomer *= 1.25
        self.curWidth *= 1.25
        self.curHeight *= 1.25
        self.updateTransforms()

    def shrink(self):
        self.zoomer *= 0.8
        self.curWidth *= 0.8
        self.curHeight *= 0.8
        self.updateTransforms()

    def fit(self):
        self.zoomer = 1
        self.adjust()

    def normal(self):
        self.curWidth = self.baseImage.width()
        self.curHeight = self.baseImage.height()
        self.updateTransforms()