* @brief Draws the blinking cursor at the current cursor position. */
| 279 | * @brief Draws the blinking cursor at the current cursor position. |
| 280 | */ |
| 281 | void Widgets::Terminal::drawCursor(QPainter* painter, int firstLine, int lastVLine, int lineHeight) |
| 282 | { |
| 283 | const int cursorLine = m_cursorPosition.y(); |
| 284 | const int cursorCol = m_cursorPosition.x(); |
| 285 | const bool rtl = Misc::Translator::instance().rtl(); |
| 286 | const int emptyCursorX = |
| 287 | rtl ? (width() - m_borderX - painter->fontMetrics().horizontalAdvance(QChar(0x2588))) |
| 288 | : m_borderX; |
| 289 | |
| 290 | int visualLineY = m_borderY; |
| 291 | bool cursorDrawn = false; |
| 292 | |
| 293 | for (int i = firstLine; i <= lastVLine && i < m_data.size(); ++i) { |
| 294 | const QString& line = m_data[i]; |
| 295 | |
| 296 | if (line.isEmpty()) { |
| 297 | if (i == cursorLine) { |
| 298 | painter->setPen(m_palette.color(QPalette::Text)); |
| 299 | // code-verify off |
| 300 | painter->drawText(emptyCursorX, visualLineY + m_cHeight, QStringLiteral("█")); |
| 301 | // code-verify on |
| 302 | cursorDrawn = true; |
| 303 | break; |
| 304 | } |
| 305 | visualLineY += lineHeight; |
| 306 | continue; |
| 307 | } |
| 308 | |
| 309 | int start = 0; |
| 310 | while (start < line.length()) { |
| 311 | const int end = qMin<int>(start + maxCharsPerLine(), line.length()); |
| 312 | |
| 313 | if (i == cursorLine && cursorCol >= start && cursorCol <= end) { |
| 314 | const int cursorX = calcCursorPixelX(painter, line, start, cursorCol, end); |
| 315 | painter->setPen(m_palette.color(QPalette::Text)); |
| 316 | // code-verify off |
| 317 | painter->drawText(cursorX, visualLineY + m_cHeight, QStringLiteral("█")); |
| 318 | // code-verify on |
| 319 | cursorDrawn = true; |
| 320 | break; |
| 321 | } |
| 322 | |
| 323 | visualLineY += lineHeight; |
| 324 | start = end; |
| 325 | } |
| 326 | |
| 327 | if (cursorDrawn) |
| 328 | break; |
| 329 | } |
| 330 | |
| 331 | if (!cursorDrawn && cursorLine >= m_data.size()) { |
| 332 | painter->setPen(m_palette.color(QPalette::Text)); |
| 333 | // code-verify off |
| 334 | painter->drawText(emptyCursorX, visualLineY + m_cHeight, QStringLiteral("█")); |
| 335 | // code-verify on |
| 336 | } |
| 337 | } |
| 338 |