MCPcopy Create free account
hub / github.com/Simsys/qhexedit2 / setCursorPosition

Method setCursorPosition

src/qhexedit.cpp:139–193  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137}
138
139void QHexEdit::setCursorPosition(qint64 position)
140{
141 // 1. delete old cursor
142 _blink = false;
143 viewport()->update(_cursorRect);
144
145 // 2. Check, if cursor in range?
146 if (position > (_chunks->size() * 2 - 1))
147 position = _chunks->size() * 2 - (_overwriteMode ? 1 : 0);
148
149 if (position < 0)
150 position = 0;
151
152 // 3. Calc new position of cursor
153 _bPosCurrent = position / 2;
154 _pxCursorY = ((position / 2 - _bPosFirst) / _bytesPerLine + 1) * _pxCharHeight;
155 int x = (position % (2 * _bytesPerLine));
156 if (_editAreaIsAscii)
157 {
158 _pxCursorX = x / 2 * _pxCharWidth + _pxPosAsciiX;
159 _cursorPosition = position & 0xFFFFFFFFFFFFFFFE;
160 } else {
161 _pxCursorX = (((x / 2) * 3) + (x % 2)) * _pxCharWidth + _pxPosHexX;
162 _cursorPosition = position;
163 }
164
165 int pxOfsX = horizontalScrollBar()->value();
166 if (_readOnly)
167 _cursorRect = QRect(
168 _pxCursorX - pxOfsX,
169 _pxCursorY - _pxCharHeight + _pxSelectionSub,
170 _pxCharWidth,
171 _pxCharHeight
172 );
173 else
174 if (_overwriteMode)
175 _cursorRect = QRect(
176 _pxCursorX - pxOfsX,
177 _pxCursorY + _pxCursorWidth,
178 _pxCharWidth,
179 _pxCursorWidth
180 );
181 else
182 _cursorRect = QRect(
183 _pxCursorX - pxOfsX,
184 _pxCursorY - _pxCharHeight + _pxSelectionSub,
185 _pxCursorWidth,
186 _pxCharHeight
187 );
188
189 // 4. Immediately draw new cursor
190 _blink = true;
191 viewport()->update(_cursorRect);
192 emit currentAddressChanged(_bPosCurrent);
193}
194
195qint64 QHexEdit::cursorPosition(QPoint pos)
196{

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected