E5Gui/E5ClickableLabel.py

Sun, 09 Mar 2014 17:06:40 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 09 Mar 2014 17:06:40 +0100
changeset 3349
2a034a7f1f54
parent 3160
209a07d7e401
child 3375
03f1833b601e
permissions
-rw-r--r--

Made the status LED (right lower corner) clickable (depending on overall VCS status it will show the log browser or the status dialog).

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

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

"""
Module implementing a clickable label.
"""

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


class E5ClickableLabel(QLabel):
    """
    Class implementing a clickable label.
    
    @signal clicked(QPoint) emitted upon a click on the label
        with the left button
    @signal middleClicked(QPoint) emitted upon a click on the label
        with the middle button or CTRL and left button
    """
    clicked = pyqtSignal(QPoint)
    middleClicked = pyqtSignal(QPoint)
    
    def __init__(self, parent=None):
        """
        Constructor
        
        @param parent reference to the parent widget (QWidget)
        """
        super().__init__(parent)
    
    def mouseReleaseEvent(self, evt):
        """
        Protected method handling mouse release events.
        
        @param evt mouse event (QMouseEvent)
        """
        if evt.button() == Qt.LeftButton and self.rect().contains(evt.pos()):
            if evt.modifiers() == Qt.ControlModifier:
                self.middleClicked.emit(evt.globalPos())
            else:
                self.clicked.emit(evt.globalPos())
        elif evt.button() == Qt.MiddleButton and \
                self.rect().contains(evt.pos()):
            self.middleClicked.emit(evt.globalPos())
        else:
            super().mouseReleaseEvent(evt)

eric ide

mercurial