| 505 | } |
| 506 | |
| 507 | void SidebarWidget::paintEvent(QPaintEvent *event) |
| 508 | { |
| 509 | QPainter p(this); |
| 510 | p.fillRect(event->rect(), backgroundColor); |
| 511 | p.setPen(lineNumberColor); |
| 512 | p.setFont(font); |
| 513 | int fh = QFontMetrics(font).height(); |
| 514 | foreach (BlockInfo ln, lineNumbers) |
| 515 | p.drawText(0, ln.position, width() - 4 - foldIndicatorWidth, fh, Qt::AlignRight, QString::number(ln.number)); |
| 516 | |
| 517 | if (foldIndicatorWidth > 0) { |
| 518 | int xofs = width() - foldIndicatorWidth; |
| 519 | p.fillRect(xofs, 0, foldIndicatorWidth, height(), indicatorColor); |
| 520 | |
| 521 | // initialize (or recreate) the arrow icons whenever necessary |
| 522 | if (foldIndicatorWidth != rightArrowIcon.width()) { |
| 523 | QPainter iconPainter; |
| 524 | QPolygonF polygon; |
| 525 | |
| 526 | int dim = foldIndicatorWidth; |
| 527 | rightArrowIcon = QPixmap(dim, dim); |
| 528 | rightArrowIcon.fill(Qt::transparent); |
| 529 | downArrowIcon = rightArrowIcon; |
| 530 | |
| 531 | polygon << QPointF(dim * 0.4, dim * 0.25); |
| 532 | polygon << QPointF(dim * 0.4, dim * 0.75); |
| 533 | polygon << QPointF(dim * 0.8, dim * 0.5); |
| 534 | iconPainter.begin(&rightArrowIcon); |
| 535 | iconPainter.setRenderHint(QPainter::Antialiasing); |
| 536 | iconPainter.setPen(Qt::NoPen); |
| 537 | iconPainter.setBrush(foldIndicatorColor); |
| 538 | iconPainter.drawPolygon(polygon); |
| 539 | iconPainter.end(); |
| 540 | |
| 541 | polygon.clear(); |
| 542 | polygon << QPointF(dim * 0.25, dim * 0.4); |
| 543 | polygon << QPointF(dim * 0.75, dim * 0.4); |
| 544 | polygon << QPointF(dim * 0.5, dim * 0.8); |
| 545 | iconPainter.begin(&downArrowIcon); |
| 546 | iconPainter.setRenderHint(QPainter::Antialiasing); |
| 547 | iconPainter.setPen(Qt::NoPen); |
| 548 | iconPainter.setBrush(foldIndicatorColor); |
| 549 | iconPainter.drawPolygon(polygon); |
| 550 | iconPainter.end(); |
| 551 | } |
| 552 | |
| 553 | foreach (BlockInfo ln, lineNumbers) |
| 554 | if (ln.foldable) { |
| 555 | if (ln.folded) |
| 556 | p.drawPixmap(xofs, ln.position, rightArrowIcon); |
| 557 | else |
| 558 | p.drawPixmap(xofs, ln.position, downArrowIcon); |
| 559 | } |
| 560 | } |
| 561 | } |
| 562 | |
| 563 | static int findClosingMatch(const QTextDocument *doc, int cursorPosition) |
| 564 | { |