--- a/E5Gui/E5Led.py Sun Mar 30 22:00:14 2014 +0200 +++ b/E5Gui/E5Led.py Thu Apr 03 23:05:31 2014 +0200 @@ -11,7 +11,7 @@ from __future__ import unicode_literals -from PyQt4.QtCore import Qt, QSize +from PyQt4.QtCore import pyqtSignal, Qt, QSize, QPoint from PyQt4.QtGui import QWidget, QColor, QRadialGradient, QPalette, QPainter, \ QBrush @@ -271,3 +271,45 @@ @return size hint (QSize) """ return QSize(18, 18) + + +class E5ClickableLed(E5Led): + """ + Class implementing a clickable LED widget. + + @signal clicked(QPoint) emitted upon a click on the LED with the + left button + @signal middleClicked(QPoint) emitted upon a click on the LED with + the middle button or CTRL and left button + """ + clicked = pyqtSignal(QPoint) + middleClicked = pyqtSignal(QPoint) + + def __init__(self, parent=None, color=None, shape=E5LedCircular, + rectRatio=1): + """ + Constructor + + @param parent reference to parent widget (QWidget) + @param color color of the LED (QColor) + @param shape shape of the LED (E5LedCircular, E5LedRectangular) + @param rectRatio ratio width to height, if shape is rectangular (float) + """ + super(E5ClickableLed, self).__init__(parent, color, shape, rectRatio) + + 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.MidButton and \ + self.rect().contains(evt.pos()): + self.middleClicked.emit(evt.globalPos()) + else: + super(E5ClickableLed, self).mouseReleaseEvent(evt)