Source

codeaide / codeaide / modes / lines.py

Full commit
from codeaide.base import *


class VerticalLine(ModeBase):


    def init(self):
        self.width = 78
        self.x = self.textedit.fontMetrics().width("W"*78)
        self.color = QColor("lightgrey")
        self.pen = QPen(self.color)
        self.brush = QBrush(QColor(self.color.lighter(115)))


    def resize_hook(self, event):
        cr = self.textedit.contentsRect()
        y = cr.top()
        x = cr.left() + self.x
        h = cr.height()
        w = cr.width()
        self.line = QLine(x, y, x, h)
        self.rect = QRect(x+1, y, w, h)

    
    def paint_hook(self, event, painter, viewport):
        rect = event.rect()
        if rect.right() < self.x:
            return
        painter.setPen(self.pen)
        painter.drawLine(self.line)
        painter.fillRect(self.rect, self.brush)


class HighlightLine(ModeBase):


    def init(self):
        #color = self.textedit.palette().highlight().color().lighter(175)
        color = QColor("blue").lighter(190)
        self.brush = QBrush(QColor(color))
        self.textedit.connect(self.textedit, 
                              SIGNAL("cursorPositionChanged()"),
                              self.update)
        self.old_row = -1


    def update(self):
        cursor = self.textedit.textCursor()
        row = cursor.blockNumber()
        if row != self.old_row:
            self.textedit.viewport().update()
            self.old_row = row


    def paint_hook(self, event, painter, viewport):
        r = self.textedit.cursorRect()
        r.setX(0)
        r.setWidth(viewport.width())
        painter.fillRect(r, self.brush)