Snapshot/SnapshotPreview.py

Sun, 17 Feb 2013 19:07:15 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 17 Feb 2013 19:07:15 +0100
changeset 2426
da76c71624de
parent 2302
f29e9405c851
child 2525
8b507a9a2d40
child 2993
4933ac9daa80
child 3163
9f50365a0870
permissions
-rw-r--r--

Updated to Pygments 1.6.

# -*- coding: utf-8 -*-

# Copyright (c) 2012 - 2013 Detlev Offenbach <detlev@die-offenbachs.de>
#

"""
Module implementing the snapshot preview label.
"""

from PyQt4.QtCore import pyqtSignal, QPoint, Qt
from PyQt4.QtGui import QLabel, QApplication


class SnapshotPreview(QLabel):
    """
    Class implementing the snapshot preview label.
    
    @signal startDrag() emitted to indicate the start of a drag operation
    """
    startDrag = pyqtSignal()
    
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        super().__init__(parent)
        
        self.setAlignment(Qt.AlignHCenter | Qt.AlignCenter)
        self.setCursor(Qt.OpenHandCursor)
        
        self.__mouseClickPoint = QPoint(0, 0)
    
    def setPreview(self, preview):
        """
        Public slot to set the preview picture.
        
        @param preview preview picture to be shown (QPixmap)
        """
        if not preview.isNull():
            pixmap = preview.scaled(
                self.width(), self.height(), Qt.KeepAspectRatio, Qt.SmoothTransformation)
        else:
            pixmap = preview
        self.setPixmap(pixmap)
    
    def mousePressEvent(self, evt):
        """
        Protected method to handle mouse button presses.
        
        @param evt mouse button press event (QMouseEvent)
        """
        if evt.button() == Qt.LeftButton:
            self.__mouseClickPoint = evt.pos()
    
    def mouseReleaseEvent(self, evt):
        """
        Protected method to handle mouse button releases.
        
        @param evt mouse button release event (QMouseEvent)
        """
        self.__mouseClickPoint = QPoint(0, 0)
    
    def mouseMoveEvent(self, evt):
        """
        Protected method to handle mouse moves.
        
        @param evt mouse move event (QMouseEvent)
        """
        if self.__mouseClickPoint != QPoint(0, 0) and \
           (evt.pos() - self.__mouseClickPoint).manhattanLength() > \
                QApplication.startDragDistance():
            self.__mouseClickPoint = QPoint(0, 0)
            self.startDrag.emit()

eric ide

mercurial