* @brief Draws the rounded scrollbar thumb when manual scrolling is active. */
| 484 | * @brief Draws the rounded scrollbar thumb when manual scrolling is active. |
| 485 | */ |
| 486 | void Widgets::Terminal::paintScrollbar(QPainter* painter) |
| 487 | { |
| 488 | if (autoscroll() || lineCount() <= linesPerPage()) |
| 489 | return; |
| 490 | |
| 491 | const int availableHeight = height() - 2 * m_borderY; |
| 492 | const int scrollbarWidth = 6; |
| 493 | int scrollbarHeight = qMax(20.0, qPow(availableHeight, 2) / lineCount()); |
| 494 | if (scrollbarHeight > availableHeight / 2) |
| 495 | scrollbarHeight = availableHeight / 2; |
| 496 | |
| 497 | const bool rtl = Misc::Translator::instance().rtl(); |
| 498 | const int x = rtl ? m_borderX : (width() - scrollbarWidth - m_borderX); |
| 499 | int y = (m_scrollOffsetY / static_cast<float>(lineCount() - linesPerPage())) |
| 500 | * (availableHeight - scrollbarHeight) |
| 501 | - m_borderY; |
| 502 | y = qMax(m_borderY, y); |
| 503 | |
| 504 | QRect scrollbarRect(x, y, scrollbarWidth, scrollbarHeight); |
| 505 | QBrush scrollbarBrush(m_palette.color(QPalette::Window)); |
| 506 | painter->setRenderHint(QPainter::Antialiasing); |
| 507 | painter->setBrush(scrollbarBrush); |
| 508 | painter->setPen(Qt::NoPen); |
| 509 | painter->drawRoundedRect(scrollbarRect, scrollbarWidth / 2, scrollbarWidth / 2); |
| 510 | } |
| 511 | |
| 512 | //-------------------------------------------------------------------------------------------------- |
| 513 | // Character metrics |