MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / positionToCursor

Method positionToCursor

app/src/UI/Widgets/Terminal.cpp:877–923  ·  view source on GitHub ↗

* @brief Converts a pixel position to a cursor position. */

Source from the content-addressed store, hash-verified

875 * @brief Converts a pixel position to a cursor position.
876 */
877QPoint Widgets::Terminal::positionToCursor(const QPoint& pos) const
878{
879 int localY = (pos.y() - m_borderY) / m_cHeight;
880 int remainingY = localY;
881
882 if (localY < 0) {
883 if (m_scrollOffsetY < m_data.size())
884 return QPoint(0, m_scrollOffsetY);
885
886 return QPoint(0, 0);
887 }
888
889 for (int i = m_scrollOffsetY; i < m_data.size(); ++i) {
890 const QString& line = m_data[i];
891
892 if (line.isEmpty()) {
893 if (remainingY == 0)
894 return QPoint(0, i);
895
896 remainingY--;
897 continue;
898 }
899
900 const int lines = (line.length() + maxCharsPerLine() - 1) / maxCharsPerLine();
901 if (remainingY >= lines) {
902 remainingY -= lines;
903 continue;
904 }
905
906 const int segmentStart = qMax(0, remainingY) * maxCharsPerLine();
907 const int segmentEnd = qMin(segmentStart + maxCharsPerLine(), line.length());
908
909 int relX = pos.x() - m_borderX;
910 if (Misc::Translator::instance().rtl())
911 relX = (width() - m_borderX) - pos.x();
912
913 return QPoint(findCharAtPixelX(line, segmentStart, segmentEnd, relX), i);
914 }
915
916 if (!m_data.isEmpty()) {
917 int lastLine = m_data.size() - 1;
918 int lastChar = m_data.last().length();
919 return QPoint(lastChar, lastLine);
920 }
921
922 return QPoint(0, 0);
923}
924
925/**
926 * @brief Copies the currently selected text to the system clipboard.

Callers

nothing calls this directly

Calls 6

isEmptyMethod · 0.80
lengthMethod · 0.80
xMethod · 0.80
rtlMethod · 0.80
lastMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected