def __init__(self, targetImage=None, axeSize=500, layer=None, parent=None, mainForm=None): super().__init__(targetImage=targetImage, axeSize=axeSize, layer=layer, parent=parent, mainForm=mainForm) graphicsScene = self.scene() ######### # L curve ######### cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicR = cubic cubic.channel = channelValues.L # get histogram as a Qimage cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(0, 1), chans=channelValues.L, mode='Lab') # L curve use the default axes cubic.axes = graphicsScene.defaultAxes cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) ########## # a curve (Green--> Magenta axis) ######### cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicG = cubic cubic.channel = channelValues.a cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(-100, 100), chans=channelValues.a, mode='Lab') # add specific axes gradient = QRadialGradient() gradient.setCenter(QPoint(0, 1)) gradient.setRadius(axeSize*1.4) gradient.setColorAt(0.0, Qt.green) gradient.setColorAt(1.0, Qt.magenta) cubic.axes = self.drawPlotGrid(axeSize, gradient) graphicsScene.addItem(cubic.axes) cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) # b curve (Blue-->Yellow axis) cubic = activeCubicSpline(axeSize) graphicsScene.addItem(cubic) graphicsScene.cubicB = cubic cubic.channel = channelValues.b cubic.histImg = graphicsScene.layer.inputImg().histogram(size=graphicsScene.axeSize, bgColor=graphicsScene.bgColor, range=(-100, 100), chans=channelValues.b, mode='Lab') # add specific axes gradient.setColorAt(0.0, Qt.blue) gradient.setColorAt(1.0, Qt.yellow) cubic.axes = self.drawPlotGrid(axeSize, gradient) graphicsScene.addItem(cubic.axes) cubic.initFixedPoints() cubic.axes.setVisible(False) cubic.setVisible(False) # set current to L curve and axes graphicsScene.cubicItem = graphicsScene.cubicR graphicsScene.cubicItem.setVisible(True) graphicsScene.cubicItem.axes.setVisible(True) # buttons pushButton1 = QPushButton("Reset Current") pushButton1.move(100, 20) pushButton1.adjustSize() pushButton1.clicked.connect(self.resetCurve) graphicsScene.addWidget(pushButton1) pushButton2 = QPushButton("Reset All") pushButton2.move(100, 50) pushButton2.adjustSize() pushButton2.clicked.connect(self.resetAllCurves) graphicsScene.addWidget(pushButton2) # options options = ['L', 'a', 'b'] self.listWidget1 = optionsWidget(options=options, exclusive=True) self.listWidget1.setGeometry(0, 10, self.listWidget1.sizeHintForColumn(0) + 5, self.listWidget1.sizeHintForRow(0) * len(options) + 5) graphicsScene.addWidget(self.listWidget1) # selection changed handler curves = [graphicsScene.cubicR, graphicsScene.cubicG, graphicsScene.cubicB] curveDict = dict(zip(options, curves)) def onSelect1(item): cubicItem = self.scene().cubicItem cubicItem.setVisible(False) cubicItem.axes.setVisible(False) self.scene().cubicItem = curveDict[item.text()] self.scene().cubicItem.setVisible(True) self.scene().cubicItem.axes.setVisible(True) # Force to redraw histogram self.scene().invalidate(QRectF(0.0, -self.scene().axeSize, self.scene().axeSize, self.scene().axeSize), QGraphicsScene.BackgroundLayer) self.listWidget1.onSelect = onSelect1 # set initial selection to L item = self.listWidget1.items[options[0]] item.setCheckState(Qt.Checked) self.listWidget1.select(item) self.setWhatsThis("""<b>Lab curves</b><br>""" + self.whatsThis()) def f(): l = graphicsScene.layer l.applyToStack() l.parentImage.onImageChanged() self.scene().cubicR.curveChanged.sig.connect(f) self.scene().cubicG.curveChanged.sig.connect(f) self.scene().cubicB.curveChanged.sig.connect(f)
def paintEvent(self, event): p = QPainter() p.begin(self) self._normalMap.render(p, event.rect()) p.setPen(Qt.black) # p.drawText(self.rect(), Qt.AlignBottom | Qt.TextWordWrap, "Map data CCBYSA 2009 OpenStreetMap.org contributors") p.end() if self.zoomed: dim = min(self.width(), self.height()) magnifierSize = min(MAX_MAGNIFIER, dim * 2 / 3) radius = magnifierSize / 2 ring = radius - 15 box = QSize(magnifierSize, magnifierSize) # reupdate our mask if self.maskPixmap.size() != box: self.maskPixmap = QPixmap(box) self.maskPixmap.fill(Qt.transparent) g = QRadialGradient() g.setCenter(radius, radius) g.setFocalPoint(radius, radius) g.setRadius(radius) g.setColorAt(1.0, QColor(255, 255, 255, 0)) g.setColorAt(0.5, QColor(128, 128, 128, 255)) mask = QPainter(self.maskPixmap) mask.setRenderHint(QPainter.Antialiasing) mask.setCompositionMode(QPainter.CompositionMode_Source) mask.setBrush(g) mask.setPen(Qt.NoPen) mask.drawRect(self.maskPixmap.rect()) mask.setBrush(QColor(Qt.transparent)) mask.drawEllipse(g.center(), ring, ring) mask.end() center = self.dragPos - QPoint(0, radius) center += QPoint(0, radius / 2) corner = center - QPoint(radius, radius) xy = center * 2 - QPoint(radius, radius) # only set the dimension to the magnified portion if self.zoomPixmap.size() != box: self.zoomPixmap = QPixmap(box) self.zoomPixmap.fill(Qt.lightGray) if True: p = QPainter(self.zoomPixmap) p.translate(-xy) self._largeMap.render(p, QRect(xy, box)) p.end() clipPath = QPainterPath() clipPath.addEllipse(QPointF(center), ring, ring) p = QPainter(self) p.setRenderHint(QPainter.Antialiasing) p.setClipPath(clipPath) p.drawPixmap(corner, self.zoomPixmap) p.setClipping(False) p.drawPixmap(corner, self.maskPixmap) p.setPen(Qt.gray) p.drawPath(clipPath) if self.invert: p = QPainter(self) p.setCompositionMode(QPainter.CompositionMode_Difference) p.fillRect(event.rect(), Qt.white) p.end()