本文整理汇总了C++中ktexteditor::Cursor::position方法的典型用法代码示例。如果您正苦于以下问题:C++ Cursor::position方法的具体用法?C++ Cursor::position怎么用?C++ Cursor::position使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ktexteditor::Cursor
的用法示例。
在下文中一共展示了Cursor::position方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getCursorPos
/**
* Returns the current position of the cursor.
* @param nLine Holds the line on which the cursor is currently located
* @param nCol Holds the column on which the cursor is currently located
* @return true if successful, false otherwise (cursor interface was not
* obtained)
*/
bool EditorPage::getCursorPos(uint& nLine, uint& nCol)
{
int line, col;
// Get the cursor position (adjusted to 1-based counting)
const KTextEditor::Cursor c = m_pView->cursorPosition();
c.position(line, col);
nLine = line;
nCol = col;
nLine++;
nCol++;
return true;
}
示例2: getWordUnderCursor
// TODO: will be a word in two lines ?
QString EditorPage::getWordUnderCursor(uint* pPosInWord)
{
QString sLine;
int nLine, nCol, nFrom, nTo, nLast, nLength;
QChar ch;
const KTextEditor::Cursor c = m_pView->cursorPosition();
// Get the line on which the cursor is positioned
c.position(nLine, nCol);
const KTextEditor::Cursor cFrom(nLine, 0);
const KTextEditor::Cursor cTo = m_pDoc->endOfLine(nLine);
KTextEditor::Range range(cFrom, cTo);
sLine = m_pDoc->text(range);
// Find the beginning of the current word
for (nFrom = nCol; nFrom > 0;) {
ch = sLine.at(nFrom - 1);
if (!ch.isLetter() && !ch.isDigit() && ch != '_')
break;
nFrom--;
}
// Find the end of the current word
nLast = sLine.length();
for (nTo = nCol; nTo < nLast;) {
ch = sLine.at(nTo);
if (!ch.isLetter() && !ch.isDigit() && ch != '_')
break;
nTo++;
}
// Mark empty words
nLength = nTo - nFrom;
if (nLength == 0)
return QString::null;
// Return the in-word position, if required
if (pPosInWord != NULL)
*pPosInWord = nCol - nFrom;
// Extract the word under the cursor from the entire line
return sLine.mid(nFrom, nLength);
}
示例3: slotCursorPosChange
/**
* Handles changes in the cursor position.
* Emits a signal with the new line and column numbers.
*/
void EditorPage::slotCursorPosChange(KTextEditor::View *view,
const KTextEditor::Cursor &newPosition)
{
int nLine, nCol;
if (view == NULL)
return;
// Find the new line and column number, and emit the signal
newPosition.position(nLine, nCol);
nLine++;
nCol++;
emit cursorPosChanged(nLine, nCol);
// Select the relevant symbol in the tag list
if (Config().getAutoTagHl() && (m_nLine != nLine)) {
m_pCtagsListWidget->gotoLine(nLine);
m_nLine = nLine;
}
m_pView->setFocus();
}