MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / moveCursor

Method moveCursor

launcher/ui/instanceview/InstanceView.cpp:851–986  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

849}
850
851QModelIndex InstanceView::moveCursor(QAbstractItemView::CursorAction cursorAction, Qt::KeyboardModifiers modifiers)
852{
853 auto current = currentIndex();
854 if (!current.isValid()) {
855 return current;
856 }
857 auto cat = category(current);
858 int group_index = m_groups.indexOf(cat);
859 if (group_index < 0)
860 return current;
861
862 QPair<int, int> pos = cat->positionOf(current);
863 int column = pos.first;
864 int row = pos.second;
865 if (m_currentCursorColumn < 0) {
866 m_currentCursorColumn = column;
867 }
868 // Handle different movement actions.
869 switch (cursorAction) {
870 case MoveUp: {
871 if (row == 0) {
872 int prevGroupIndex = group_index - 1;
873 while (prevGroupIndex >= 0) {
874 auto prevGroup = m_groups[prevGroupIndex];
875 if (prevGroup->collapsed) {
876 prevGroupIndex--;
877 continue;
878 }
879 int newRow = prevGroup->numRows() - 1;
880 int newRowSize = prevGroup->rows[newRow].size();
881 int newColumn = m_currentCursorColumn;
882 if (m_currentCursorColumn >= newRowSize) {
883 newColumn = newRowSize - 1;
884 }
885 return prevGroup->rows[newRow][newColumn];
886 }
887 } else {
888 int newRow = row - 1;
889 int newRowSize = cat->rows[newRow].size();
890 int newColumn = m_currentCursorColumn;
891 if (m_currentCursorColumn >= newRowSize) {
892 newColumn = newRowSize - 1;
893 }
894 return cat->rows[newRow][newColumn];
895 }
896 return current;
897 }
898 case MoveDown: {
899 if (row == cat->rows.size() - 1) {
900 int nextGroupIndex = group_index + 1;
901 while (nextGroupIndex < m_groups.size()) {
902 auto nextGroup = m_groups[nextGroupIndex];
903 if (nextGroup->collapsed) {
904 nextGroupIndex++;
905 continue;
906 }
907 int newRowSize = nextGroup->rows[0].size();
908 int newColumn = m_currentCursorColumn;

Callers

nothing calls this directly

Calls 4

positionOfMethod · 0.80
numRowsMethod · 0.80
isValidMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected