* @brief Returns the id of the first visible block inside a QTextEdit * @details Taken from * Stackoverflow */
| 20 | * href="https://stackoverflow.com/questions/2443358/how-to-add-lines-numbers-to-qtextedit/24596246#24596246">Stackoverflow</a> |
| 21 | */ |
| 22 | inline std::int32_t getFirstVisibleBlockId(const QTextEdit& text) |
| 23 | { |
| 24 | QTextCursor curs = QTextCursor(text.document()); |
| 25 | curs.movePosition(QTextCursor::Start); |
| 26 | for (std::int32_t i = 0; i < text.document()->blockCount(); ++i) |
| 27 | { |
| 28 | QTextBlock block = curs.block(); |
| 29 | |
| 30 | QRect r1 = text.viewport()->geometry(); |
| 31 | QRect r2 = text.document() |
| 32 | ->documentLayout() |
| 33 | ->blockBoundingRect(block) |
| 34 | .translated(text.viewport()->geometry().x(), |
| 35 | text.viewport()->geometry().y() - (text.verticalScrollBar()->sliderPosition())) |
| 36 | .toRect(); |
| 37 | |
| 38 | if (r1.contains(r2, true)) |
| 39 | { |
| 40 | return i; |
| 41 | } |
| 42 | |
| 43 | curs.movePosition(QTextCursor::NextBlock); |
| 44 | } |
| 45 | |
| 46 | return 0; |
| 47 | }; |
| 48 | |
| 49 | inline QString stripFilename(const QString& filepath) |
| 50 | { |