def paintEvent(self, event): """QWidget.paintEvent() implementation Draw markers """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) block = self._qpart.firstVisibleBlock() blockBoundingGeometry = self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()) top = blockBoundingGeometry.top() bottom = top + blockBoundingGeometry.height() for block in qutepart.iterateBlocksFrom(block): height = self._qpart.blockBoundingGeometry(block).height() if top > event.rect().bottom(): break if block.isVisible() and \ bottom >= event.rect().top(): if block.blockNumber() in self._qpart.lintMarks: msgType, msgText = self._qpart.lintMarks[block.blockNumber()] pixMap = self._lintPixmaps[msgType] yPos = top + ((height - pixMap.height()) / 2) # centered painter.drawPixmap(0, yPos, pixMap) if Bookmarks.isBlockMarked(block): yPos = top + ((height - self._bookmarkPixmap.height()) / 2) # centered painter.drawPixmap(0, yPos, self._bookmarkPixmap) top += height
def paintEvent(self, event): """QWidget.paintEvent() implementation Draw markers """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) block = self._qpart.firstVisibleBlock() blockBoundingGeometry = self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()) top = blockBoundingGeometry.top() bottom = top + blockBoundingGeometry.height() for block in qutepart.iterateBlocksFrom(block): height = self._qpart.blockBoundingGeometry(block).height() if top > event.rect().bottom(): break if block.isVisible() and \ bottom >= event.rect().top(): if block.blockNumber() in self._qpart.lintMarks: msgType, msgText = self._qpart.lintMarks[block.blockNumber()] pixMap = self._lintPixmaps[msgType] yPos = top + ((height - pixMap.height()) / 2) # centered painter.drawPixmap(0, yPos, pixMap) if Bookmarks.isBlockMarked(block): yPos = top + ((height - self._bookmarkPixmap.height()) / 2) # centered painter.drawPixmap(0, yPos, self._bookmarkPixmap) top += height
def __init__(self, qpart): QWidget.__init__(self, qpart) extend_instance(self, MarginBase) MarginBase.__init__(self, qpart, "mark_area", 1) qpart.blockCountChanged.connect(self.update) self.setMouseTracking(True) self._bookmarkPixmap = self._loadIcon('emblem-favorite') self._lintPixmaps = {qpart.LINT_ERROR: self._loadIcon('emblem-error'), qpart.LINT_WARNING: self._loadIcon('emblem-warning'), qpart.LINT_NOTE: self._loadIcon('emblem-information')} self._bookmarks = Bookmarks(qpart, self)
def __init__(self, qpart): QWidget.__init__(self, qpart) extend_instance(self, MarginBase) MarginBase.__init__(self, qpart, "mark_area", 1) qpart.blockCountChanged.connect(self.update) self.setMouseTracking(True) self._bookmarkPixmap = self._loadIcon('bookmark.png') self._lintPixmaps = {qpart.LINT_ERROR: self._loadIcon('lint-error.png'), qpart.LINT_WARNING: self._loadIcon('lint-warning.png'), qpart.LINT_NOTE: self._loadIcon('lint-note.png')} self._bookmarks = Bookmarks(qpart, self)
class MarkArea(QWidget): _MARGIN = 1 def __init__(self, qpart): QWidget.__init__(self, qpart) extend_instance(self, MarginBase) MarginBase.__init__(self, qpart, "mark_area", 1) qpart.blockCountChanged.connect(self.update) self.setMouseTracking(True) self._bookmarkPixmap = self._loadIcon('bookmark.png') self._lintPixmaps = {qpart.LINT_ERROR: self._loadIcon('lint-error.png'), qpart.LINT_WARNING: self._loadIcon('lint-warning.png'), qpart.LINT_NOTE: self._loadIcon('lint-note.png')} self._bookmarks = Bookmarks(qpart, self) def _loadIcon(self, fileName): defaultSizePixmap = QPixmap(qutepart.getIconPath(fileName)) iconSize = self._qpart.cursorRect().height() return defaultSizePixmap.scaled(iconSize, iconSize, transformMode=Qt.SmoothTransformation) def sizeHint(self, ): """QWidget.sizeHint() implementation """ return QSize(self.width(), 0) def paintEvent(self, event): """QWidget.paintEvent() implementation Draw markers """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) block = self._qpart.firstVisibleBlock() blockBoundingGeometry = self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()) top = blockBoundingGeometry.top() bottom = top + blockBoundingGeometry.height() for block in qutepart.iterateBlocksFrom(block): height = self._qpart.blockBoundingGeometry(block).height() if top > event.rect().bottom(): break if block.isVisible() and \ bottom >= event.rect().top(): if block.blockNumber() in self._qpart.lintMarks: msgType, msgText = self._qpart.lintMarks[block.blockNumber()] pixMap = self._lintPixmaps[msgType] yPos = top + ((height - pixMap.height()) / 2) # centered painter.drawPixmap(0, yPos, pixMap) if self.isBlockMarked(block): yPos = top + ((height - self._bookmarkPixmap.height()) / 2) # centered painter.drawPixmap(0, yPos, self._bookmarkPixmap) top += height def width(self): """Desired width. Includes text and margins """ return self._MARGIN + self._bookmarkPixmap.width() + self._MARGIN def mouseMoveEvent(self, event): blockNumber = self._qpart.cursorForPosition(event.pos()).blockNumber() if blockNumber in self._qpart._lintMarks: msgType, msgText = self._qpart._lintMarks[blockNumber] QToolTip.showText(event.globalPos(), msgText) else: QToolTip.hideText() return QWidget.mouseMoveEvent(self, event) def clearBookmarks(self, startBlock, endBlock): """Clears the bookmarks """ self._bookmarks.clear(startBlock, endBlock) def clear(self): self._bookmarks.removeActions() MarginBase.clear(self)
class MarkArea(QWidget): _MARGIN = 1 def __init__(self, qpart): QWidget.__init__(self, qpart) extend_instance(self, MarginBase) MarginBase.__init__(self, qpart, "mark_area", 1) qpart.blockCountChanged.connect(self.update) self.setMouseTracking(True) self._bookmarkPixmap = self._loadIcon('bookmark.png') self._lintPixmaps = {qpart.LINT_ERROR: self._loadIcon('lint-error.png'), qpart.LINT_WARNING: self._loadIcon('lint-warning.png'), qpart.LINT_NOTE: self._loadIcon('lint-note.png')} self._bookmarks = Bookmarks(qpart, self) def _loadIcon(self, fileName): defaultSizePixmap = QPixmap(qutepart.getIconPath(fileName)) iconSize = self._qpart.cursorRect().height() return defaultSizePixmap.scaled(iconSize, iconSize, transformMode=Qt.SmoothTransformation) def sizeHint(self, ): """QWidget.sizeHint() implementation """ return QSize(self.width(), 0) def paintEvent(self, event): """QWidget.paintEvent() implementation Draw markers """ painter = QPainter(self) painter.fillRect(event.rect(), self.palette().color(QPalette.Window)) block = self._qpart.firstVisibleBlock() blockBoundingGeometry = self._qpart.blockBoundingGeometry(block).translated(self._qpart.contentOffset()) top = blockBoundingGeometry.top() bottom = top + blockBoundingGeometry.height() for block in qutepart.iterateBlocksFrom(block): height = self._qpart.blockBoundingGeometry(block).height() if top > event.rect().bottom(): break if block.isVisible() and \ bottom >= event.rect().top(): if block.blockNumber() in self._qpart.lintMarks: msgType, msgText = self._qpart.lintMarks[block.blockNumber()] pixMap = self._lintPixmaps[msgType] yPos = top + ((height - pixMap.height()) / 2) # centered painter.drawPixmap(0, yPos, pixMap) if self.isBlockMarked(block): yPos = top + ((height - self._bookmarkPixmap.height()) / 2) # centered painter.drawPixmap(0, yPos, self._bookmarkPixmap) top += height def width(self): """Desired width. Includes text and margins """ return self._MARGIN + self._bookmarkPixmap.width() + self._MARGIN def mouseMoveEvent(self, event): blockNumber = self._qpart.cursorForPosition(event.pos()).blockNumber() if blockNumber in self._qpart._lintMarks: msgType, msgText = self._qpart._lintMarks[blockNumber] QToolTip.showText(event.globalPos(), msgText) else: QToolTip.hideText() return QWidget.mouseMoveEvent(self, event) def clearBookmarks(self, startBlock, endBlock): """Clears the bookmarks """ self._bookmarks.clear(startBlock, endBlock) def clear(self): self._bookmarks.removeActions() MarginBase.clear(self)