Example #1
0
	def lineNumberAreaWidth(self):
		if not globalSettings.lineNumbersEnabled:
			return 0
		cursor = QTextCursor(self.document())
		cursor.movePosition(QTextCursor.End)
		if globalSettings.relativeLineNumbers:
			digits = len(str(cursor.blockNumber())) + 1
		else:
			digits = len(str(cursor.blockNumber() + 1))
		return 5 + self.fontMetrics().width('9') * digits
Example #2
0
File: editor.py Project: rhn/retext
 def lineNumberAreaWidth(self):
     if not globalSettings.lineNumbersEnabled:
         return 0
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.End)
     if globalSettings.relativeLineNumbers:
         digits = len(str(cursor.blockNumber())) + 1
     else:
         digits = len(str(cursor.blockNumber() + 1))
     return 5 + self.fontMetrics().width('9') * digits
Example #3
0
 def paintEvent(self, event):
     if not globalSettings.lineNumbersEnabled:
         return QWidget.paintEvent(self, event)
     painter = QPainter(self)
     painter.fillRect(event.rect(), colorValues['lineNumberArea'])
     cursor = QTextCursor(self.editor.document())
     cursor.movePosition(QTextCursor.Start)
     atEnd = False
     if globalSettings.relativeLineNumbers:
         relativeTo = self.editor.textCursor().blockNumber()
     else:
         relativeTo = -1
     while not atEnd:
         rect = self.editor.cursorRect(cursor)
         block = cursor.block()
         if block.isVisible():
             number = str(cursor.blockNumber() - relativeTo).replace(
                 '-', '−')
             painter.setPen(colorValues['lineNumberAreaText'])
             painter.drawText(0, rect.top(),
                              self.width() - 2,
                              self.fontMetrics().height(), Qt.AlignRight,
                              number)
         cursor.movePosition(QTextCursor.EndOfBlock)
         atEnd = cursor.atEnd()
         if not atEnd:
             cursor.movePosition(QTextCursor.NextBlock)
Example #4
0
    def change_cursor_info(self, data: QTextCursor):
        ss = data.selectionStart()
        se = data.selectionEnd()

        selected_info = ""
        if se - ss:
            selected_info = "{0} {1}  ".format(
                se - ss, "char" if (se - ss) == 1 else "chars")
        self.showMessage("{0}{1}:{2}".format(selected_info, data.blockNumber(),
                                             data.columnNumber()))
Example #5
0
	def lineNumberAreaPaintEvent(self, event):
		painter = QPainter(self.lineNumberArea)
		painter.fillRect(event.rect(), colorValues['lineNumberArea'])
		cursor = QTextCursor(self.document())
		cursor.movePosition(QTextCursor.Start)
		atEnd = False
		while not atEnd:
			rect = self.cursorRect(cursor)
			block = cursor.block()
			if block.isVisible():
				number = str(cursor.blockNumber() + 1)
				painter.setPen(colorValues['lineNumberAreaText'])
				painter.drawText(0, rect.top(), self.lineNumberArea.width()-2,
					self.fontMetrics().height(), Qt.AlignRight, number)
			cursor.movePosition(QTextCursor.EndOfBlock)
			atEnd = cursor.atEnd()
			if not atEnd:
				cursor.movePosition(QTextCursor.NextBlock)
Example #6
0
 def lineNumberAreaPaintEvent(self, event):
     painter = QPainter(self.lineNumberArea)
     painter.fillRect(event.rect(), Qt.cyan)
     cursor = QTextCursor(self.document())
     cursor.movePosition(QTextCursor.Start)
     atEnd = False
     while not atEnd:
         rect = self.cursorRect(cursor)
         block = cursor.block()
         if block.isVisible():
             number = str(cursor.blockNumber() + 1)
             painter.setPen(Qt.darkCyan)
             painter.drawText(0, rect.top(),
                              self.lineNumberArea.width() - 2,
                              self.fontMetrics().height(), Qt.AlignRight,
                              number)
         cursor.movePosition(QTextCursor.EndOfBlock)
         atEnd = cursor.atEnd()
         if not atEnd:
             cursor.movePosition(QTextCursor.NextBlock)
Example #7
0
	def paintEvent(self, event):
		if not globalSettings.lineNumbersEnabled:
			return QWidget.paintEvent(self, event)
		painter = QPainter(self)
		painter.fillRect(event.rect(), colorValues['lineNumberArea'])
		cursor = QTextCursor(self.editor.document())
		cursor.movePosition(QTextCursor.Start)
		atEnd = False
		if globalSettings.relativeLineNumbers:
			relativeTo = self.editor.textCursor().blockNumber()
		else:
			relativeTo = -1
		while not atEnd:
			rect = self.editor.cursorRect(cursor)
			block = cursor.block()
			if block.isVisible():
				number = str(cursor.blockNumber() - relativeTo).replace('-', '−')
				painter.setPen(colorValues['lineNumberAreaText'])
				painter.drawText(0, rect.top(), self.width() - 2,
					self.fontMetrics().height(), Qt.AlignRight, number)
			cursor.movePosition(QTextCursor.EndOfBlock)
			atEnd = cursor.atEnd()
			if not atEnd:
				cursor.movePosition(QTextCursor.NextBlock)