def _draw_textdoc(self, rect, col): """Draw the QTextDocument of an item. Args: rect: The QRect to clip the drawing to. """ # We can't use drawContents because then the color would be ignored. clip = QRectF(0, 0, rect.width(), rect.height()) self._painter.save() if self._opt.state & QStyle.State_Selected: color = config.val.colors.completion.item.selected.fg elif not self._opt.state & QStyle.State_Enabled: color = config.val.colors.completion.category.fg else: colors = config.val.colors.completion.fg # if multiple colors are set, use different colors per column color = colors[col % len(colors)] self._painter.setPen(color) ctx = QAbstractTextDocumentLayout.PaintContext() ctx.palette.setColor(QPalette.Text, self._painter.pen().color()) if clip.isValid(): self._painter.setClipRect(clip) ctx.clip = clip self._doc.documentLayout().draw(self._painter, ctx) self._painter.restore()
def _draw_textdoc(self, rect, col): """Draw the QTextDocument of an item. Args: rect: The QRect to clip the drawing to. """ # We can't use drawContents because then the color would be ignored. clip = QRectF(0, 0, rect.width(), rect.height()) self._painter.save() if self._opt.state & QStyle.State_Selected: color = config.val.colors.completion.item.selected.fg elif not self._opt.state & QStyle.State_Enabled: color = config.val.colors.completion.category.fg else: colors = config.val.colors.completion.fg # if multiple colors are set, use different colors per column color = colors[col % len(colors)] self._painter.setPen(color) ctx = QAbstractTextDocumentLayout.PaintContext() ctx.palette.setColor(QPalette.Text, self._painter.pen().color()) if clip.isValid(): self._painter.setClipRect(clip) ctx.clip = clip self._doc.documentLayout().draw(self._painter, ctx) self._painter.restore()
def _draw_textdoc(self, rect): """Draw the QTextDocument of an item. Args: rect: The QRect to clip the drawing to. """ # We can't use drawContents because then the color would be ignored. # See: https://qt-project.org/forums/viewthread/21492 clip = QRectF(0, 0, rect.width(), rect.height()) self._painter.save() if self._opt.state & QStyle.State_Selected: option = 'completion.item.selected.fg' elif not self._opt.state & QStyle.State_Enabled: option = 'completion.category.fg' else: option = 'completion.fg' try: self._painter.setPen(config.get('colors', option)) except configexc.NoOptionError: self._painter.setPen(config.get('colors', 'completion.fg')) ctx = QAbstractTextDocumentLayout.PaintContext() ctx.palette.setColor(QPalette.Text, self._painter.pen().color()) if clip.isValid(): self._painter.setClipRect(clip) ctx.clip = clip self._doc.documentLayout().draw(self._painter, ctx) self._painter.restore()
def _draw_textdoc(self, rect): """Draw the QTextDocument of an item. Args: rect: The QRect to clip the drawing to. """ # We can't use drawContents because then the color would be ignored. # See: https://qt-project.org/forums/viewthread/21492 clip = QRectF(0, 0, rect.width(), rect.height()) self._painter.save() if self._opt.state & QStyle.State_Selected: option = 'completion.item.selected.fg' elif not self._opt.state & QStyle.State_Enabled: option = 'completion.category.fg' else: option = 'completion.fg' try: self._painter.setPen(config.get('colors', option)) except configexc.NoOptionError: self._painter.setPen(config.get('colors', 'completion.fg')) ctx = QAbstractTextDocumentLayout.PaintContext() ctx.palette.setColor(QPalette.Text, self._painter.pen().color()) if clip.isValid(): self._painter.setClipRect(clip) ctx.clip = clip self._doc.documentLayout().draw(self._painter, ctx) self._painter.restore()
def keyPressEvent(self, event): if self.hasImage(): # Zoom in if event.key() == Qt.Key_Plus: viewBBox = self.zoomStack[-1] if len( self.zoomStack) else self.sceneRect() wh12 = int( max(viewBBox.width(), viewBBox.height()) / self.zoom_in_modifier) x, y = self._lastCursorCoords selectionBBox = QRectF(x - wh12, y - wh12, 2 * wh12, 2 * wh12).intersected(viewBBox) if selectionBBox.isValid() and (selectionBBox != viewBBox): self.zoomStack.append(selectionBBox) self.updateViewer() # Zoom out if event.key() == Qt.Key_Minus: if self.canZoom: viewBBox = self.zoomStack[-1] if len( self.zoomStack) else False if viewBBox: self.zoomStack = self.zoomStack[:-1] self.updateViewer() # Fill mask region if event.key() == Qt.Key_F: try: self.viewport().setCursor(Qt.BusyCursor) self.fillArea() except Exception as e: print("Cannot fill region. Additional information:") print(e) self.viewport().setCursor(Qt.ArrowCursor) # Erase closed contour under cursor with current paint color if event.key() == Qt.Key_X: if QApplication.keyboardModifiers() & Qt.ControlModifier: try: self.viewport().setCursor(Qt.BusyCursor) self.fillArea(remove_closed_contour=True) except Exception as e: print( "Cannot remove the contour. Additional information:" ) print(e) self.viewport().setCursor(Qt.ArrowCursor) # Erase closed contour under cursor and any connected contour regardless of color if event.key() == Qt.Key_Q: if QApplication.keyboardModifiers() & Qt.ControlModifier: try: self.viewport().setCursor(Qt.BusyCursor) self.fillArea(remove_closed_contour=True, remove_only_current_color=False) except Exception as e: print( "Cannot remove the contour. Additional information:" ) print(e) self.viewport().setCursor(Qt.ArrowCursor) # Erase mode enable/disable if event.key() == Qt.Key_D: self.global_erase_override = not self.global_erase_override if self.global_erase_override: self.current_painting_mode = self.MODE_ERASE self._deleteCrossHandles[0].show() self._deleteCrossHandles[1].show() else: self.current_painting_mode = self.MODE_PAINT self._deleteCrossHandles[0].hide() self._deleteCrossHandles[1].hide() # Temporarily hide the overlay if event.key() == Qt.Key_H: self._overlayHandle.hide() # Toggle helper on and off if event.key() == Qt.Key_T: if self._auxHelper is not None: if self.showHelper: self._auxHelper.hide() self.showHelper = False else: self._auxHelper.show() self.showHelper = True # Undo operations if event.key() == Qt.Key_Z: if QApplication.keyboardModifiers() & Qt.ControlModifier: if (len(self._overlay_stack) > 0): self.mask_pixmap = self._overlay_stack.pop() self._overlayHandle.setPixmap(self.mask_pixmap) if self.direct_mask_paint: if len(self._offscreen_mask_stack) > 0: self._offscreen_mask = self._offscreen_mask_stack.pop( ) # When CONTROL is pressed, show the delete cross if event.key( ) == Qt.Key_Control and not self.global_erase_override: self._deleteCrossHandles[0].show() self._deleteCrossHandles[1].show() QGraphicsView.keyPressEvent(self, event)