bool RtfCssEditor::isPropriety() { QTextCursor tc = textCursor(); int currentPos = tc.position(); tc.select(QTextCursor::LineUnderCursor); QString line = tc.selectedText(); tc.movePosition(QTextCursor::StartOfLine); int startposition = tc.position(); tc.setPosition(currentPos); if ((line.indexOf(':') > 2) && (startposition + line.indexOf(':') < currentPos)) { if ((line.indexOf(';') != -1) && (startposition + line.indexOf(';') >= currentPos)) { return true; } else if (line.indexOf(';') == -1) { return true; } } return false; }
QString DataWidget::getSelectedAddr() { if (!isEnabled()) { return QStringLiteral("000000"); } QTextCursor c = textCursor(); c.movePosition(QTextCursor::StartOfLine, QTextCursor::MoveAnchor); c.setPosition(c.position()+6, QTextCursor::KeepAnchor); // +6 == size of the address // See MainWindow::drawNextDisassembleLine() for details return c.selectedText(); }
void NoteEditorUtils::addCheckmark(QTextCursor &cursor) { static const QChar unicode[] = {0x2713}; const int size = sizeof(unicode) / sizeof(QChar); const int position = cursor.position(); cursor.movePosition(QTextCursor::StartOfLine); const QString checkMark = QString::fromRawData(unicode, size); cursor.insertText(checkMark); cursor.setPosition(position + checkMark.size()); }
void PythonTypeIn::prompt(bool storeOnly) { const char * c = storeOnly ? "...> " : "py> "; commandPrompt_ = c; append(c); QTextCursor tc = textCursor(); tc.movePosition(QTextCursor::End); tail_ = tc.position(); }
void LineIndicator::mousePressEvent( QMouseEvent *e ) { QTextCursor cursor = mEditor->cursorForPosition(QPoint(0, e->pos().y())); if(cursor.isNull()) { mLastCursorPos = -1; return; } mEditor->setTextCursor(cursor); mLastCursorPos = cursor.position(); }
void ConsoleWidget::LimitCursorSelectionTo(int start) { QTextCursor cursor = textCursor(); int anchor = cursor.anchor(), position = cursor.position(); if (anchor != position && (anchor < start || position < start)) { cursor.setPosition(qMax(start, anchor), QTextCursor::MoveAnchor); cursor.setPosition(qMax(start, position), QTextCursor::KeepAnchor); setTextCursor(cursor); } }
void SchematicName::onContentsChanged() { QString text = document()->toPlainText(); QTextCursor cursor = textCursor(); int position = cursor.position(); if (position > 0 && text.at(position - 1) == '\n') { text.remove("\n"); setPlainText(text); ; emit focusOut(); } }
void QConsoleWidget::mousePressEvent( QMouseEvent *e ) { //TODO: mousepressevent int eval_index; bool haveDone_; { QTextCursor tc = this->textCursor(); if (tc.hasSelection()) { auto se = tc.selectionEnd(); auto sb = tc.selectionStart(); if (sb >= promptEndPos_) { eval_index = 0;/*rw*/ } else if (se <= promptEndPos_) { eval_index = 1;/*r*/ } else { eval_index = 2/*a*/; } } else { if (e->button()&Qt::RightButton) { auto tc_ = this->cursorForPosition(e->pos()); this->setTextCursor(tc_); } auto pos_ = tc.position(); if (pos_>=this->promptEndPos_) { eval_index = 3;//read write } else { if (pos_>=this->promptBeginPos_) { QTextCursor tc = this->textCursor(); tc.setPosition( this->promptEndPos_ ); this->setTextCursor(tc); eval_index = 3;//read write } else { eval_index = 4;//read only } } } } switch (eval_index) { case 0: haveDone_ = _pf<bool, SelectMousePressedReadWrite>(this,e); break; case 1: haveDone_ = _pf<bool, SelectMousePressedReadOnly>(this, e); break; case 2: haveDone_ = _pf<bool, SelectMousePressedAll>(this, e); break; case 3: haveDone_ = _pf<bool, MousePressedReadWrite>(this, e); break; case 4: haveDone_ = _pf<bool, MousePressedReadOnly>(this, e); break; } if (haveDone_) { return; } return TP::mousePressEvent(e); }
QPair<int, int> KoTextInlineRdf::findExtent() { if (d->bookmark && d->document) { KoBookmark *e = d->bookmark->endBookmark(); return QPair<int, int>(d->bookmark->position(), e->position()); } if (d->kotextmeta && d->document) { KoTextMeta *e = d->kotextmeta->endBookmark(); if (!e) { return QPair<int, int>(0, 0); } return QPair<int, int>(d->kotextmeta->position(), e->position()); } if (d->cell.isValid() && d->document) { QTextCursor b = d->cell.firstCursorPosition(); QTextCursor e = d->cell.lastCursorPosition(); return QPair<int, int>(b.position(), e.position()); } return QPair<int, int>(0, 0); }
QString KoTextInlineRdf::object() { if (d->isObjectAttriuteUsed) { return d->object; } if (d->bookmark && d->document) { KoBookmark *e = d->bookmark->endBookmark(); QTextCursor cursor(d->document); cursor.setPosition(d->bookmark->position(), QTextCursor::MoveAnchor); cursor.setPosition(e->position(), QTextCursor::KeepAnchor); QString ret = cursor.QTextCursor::selectedText(); return ret.remove(QChar::ObjectReplacementCharacter); } if (d->kotextmeta && d->document) { KoTextMeta *e = d->kotextmeta->endBookmark(); QTextCursor cursor(d->document); if (!e) { kDebug(30015) << "Broken KoTextMeta, no end tag found!"; return QString(); } else { cursor.setPosition(d->kotextmeta->position(), QTextCursor::MoveAnchor); cursor.setPosition(e->position(), QTextCursor::KeepAnchor); QString ret = cursor.selectedText(); return ret.remove(QChar::ObjectReplacementCharacter); } } if (d->cell.isValid() && d->document) { QTextCursor b = d->cell.firstCursorPosition(); QTextCursor e = d->cell.lastCursorPosition(); QTextCursor cursor(d->document); cursor.setPosition(b.position(), QTextCursor::MoveAnchor); cursor.setPosition(e.position(), QTextCursor::KeepAnchor); QString ret = cursor.selectedText(); return ret.remove(QChar::ObjectReplacementCharacter); } return d->block.text(); }
QTextCursor FindEditor::findEditor(QTextDocument *doc, const QTextCursor &cursor, FindOption *opt, bool wrap) { int from = cursor.position(); if (cursor.hasSelection()) { if (opt->backWard) { from = cursor.selectionStart(); } else { from = cursor.selectionEnd(); } } return findEditorHelper(doc,from,opt,wrap); }
bool TabSettings::tabShouldIndent(const QTextDocument *document, QTextCursor cursor, int *suggestedPosition) const { if (m_tabKeyBehavior == TabNeverIndents) return false; QTextCursor tc = cursor; if (suggestedPosition) *suggestedPosition = tc.position(); // At least suggest original position tc.movePosition(QTextCursor::StartOfLine); if (tc.atBlockEnd()) // cursor was on a blank line return true; if (document->characterAt(tc.position()).isSpace()) { tc.movePosition(QTextCursor::WordRight); if (tc.columnNumber() >= cursor.columnNumber()) { if (suggestedPosition) *suggestedPosition = tc.position(); // Suggest position after whitespace if (m_tabKeyBehavior == TabLeadingWhitespaceIndents) return true; } } return (m_tabKeyBehavior == TabAlwaysIndents); }
static void from_pos(CTEXTAREA *_object, int pos, int *par, int *car) { QTextCursor cursor = WIDGET->textCursor(); if (pos >= get_length(THIS)) cursor.movePosition(QTextCursor::End); else cursor.setPosition(pos); *par = cursor.blockNumber(); *car = cursor.position() - cursor.block().position(); }
QString GLSLTextEditorWidget::wordUnderCursor() const { QTextCursor tc = textCursor(); const QChar ch = characterAt(tc.position() - 1); // make sure that we're not at the start of the next word. if (ch.isLetterOrNumber() || ch == QLatin1Char('_')) tc.movePosition(QTextCursor::Left); tc.movePosition(QTextCursor::StartOfWord); tc.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); const QString word = tc.selectedText(); return word; }
void Console::enableOutput() { if(_ioDevice){ setPlainText( toPlainText() + _ioDevice->readAll()); setEnabled(true); QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::End); setTextCursor(cursor); _lastCursorPos = cursor.position(); } }
void QmlExpressionUnderCursor::operator()(const QTextCursor &cursor, QmlJS::AST::UiProgram *program) { _pos = cursor.position(); _expressionNode = 0; _expressionOffset = -1; _expressionLength = -1; _scopes.clear(); if (program) program->accept(this); }
void QConsoleWidget::dropEvent(QDropEvent *e){ {/*测试是否在可drop区域*/ QTextCursor tc = this->cursorForPosition(e->pos()); if (tc.position() < this->promptEndPos_) { e->setAccepted(false); return; } } TP::dropEvent(e); }
void SchematicName::keyPressEvent(QKeyEvent *ke) { if (ke->key() == Qt::Key_Left || ke->key() == Qt::Key_Right) { QTextCursor cursor = textCursor(); int currentPos = cursor.position(); if (ke->key() == Qt::Key_Left) cursor.setPosition(currentPos - 1); else cursor.setPosition(currentPos + 1); setTextCursor(cursor); } else QGraphicsTextItem::keyPressEvent(ke); }
QT_BEGIN_NAMESPACE QTextCopyHelper::QTextCopyHelper(const QTextCursor &_source, const QTextCursor &_destination, bool forceCharFormat, const QTextCharFormat &fmt) : formatCollection(*_destination.d->priv->formatCollection()), originalText(_source.d->priv->buffer()) { src = _source.d->priv; dst = _destination.d->priv; insertPos = _destination.position(); this->forceCharFormat = forceCharFormat; primaryCharFormatIndex = convertFormatIndex(fmt); cursor = _source; }
/** La completion n'est réalisée que si aucune sélection n'est actuellement définie */ bool RzxTextEdit::nickAutocompletion() { QTextCursor cursor = textCursor(); //Si y'a une sélection, on zappe if(cursor.hasSelection()) return false; //On récupère la position du curseur et la paragraphe concerné int index = cursor.position(); index -= cursor.block().position(); if(!index) return false; static const QRegExp mask("[^-A-Za-z0-9]([-A-Za-z0-9]+)$"); const QString textPara = cursor.block().text(); //Juste pour se souvenir des pseudos possibles const QString localName = RzxComputer::localhost()->name(); const QString remoteName = chat->computer()->name(); const QString localLower = localName.toLower(); const QString remoteLower = remoteName.toLower(); for(int i = 1 ; i <= index && (localName.length() > i || remoteName.length() > i) ; i++) { //Chaine de caractère qui précède le curseur de taille i QString nick = textPara.mid(index-i, i).toLower(); if(mask.indexIn(nick) != -1 || i == index) { if(mask.indexIn(nick) != -1) nick = mask.cap(1); if(!remoteLower.indexOf(nick, false) && localLower.indexOf(nick, false)) { for(int i = 0; i< nick.length();i++) { cursor.deletePreviousChar (); } cursor.insertText(remoteName + " "); return true; } else if(remoteLower.indexOf(nick, false) && !localLower.indexOf(nick, false)) { for(int i = 0; i< nick.length();i++) { cursor.deletePreviousChar (); } cursor.insertText(localName + " "); return true; } return false; } } return false; }
void highlightMatches(const QString &pattern) { QTextEdit *ed = qobject_cast<QTextEdit *>(m_widget); if (!ed) return; QTextCursor cur = ed->textCursor(); QTextEdit::ExtraSelection selection; selection.format.setBackground(Qt::yellow); selection.format.setForeground(Qt::black); // Highlight matches. QTextDocument *doc = ed->document(); QRegExp re(pattern); cur = doc->find(re); m_searchSelection.clear(); int a = cur.position(); while ( !cur.isNull() ) { if ( cur.hasSelection() ) { selection.cursor = cur; m_searchSelection.append(selection); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = doc->find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = doc->find(re, cur); b = cur.position(); if (a == b) break; } a = b; } updateExtraSelections(); }
void ItemText::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { m_searchTextDocument.clear(); if ( re.isEmpty() ) { setDocument(&m_textDocument); } else { bool plain = m_textFormat == Qt::PlainText; const QString &text = plain ? m_textDocument.toPlainText() : m_textDocument.toHtml(); if (plain) m_searchTextDocument.setPlainText(text); else m_searchTextDocument.setHtml(text); QTextCursor cur = m_searchTextDocument.find(re); int a = cur.position(); while ( !cur.isNull() ) { QTextCharFormat fmt = cur.charFormat(); if ( cur.hasSelection() ) { fmt.setBackground( highlightPalette.base() ); fmt.setForeground( highlightPalette.text() ); fmt.setFont(highlightFont); cur.setCharFormat(fmt); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = m_searchTextDocument.find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = m_searchTextDocument.find(re, cur); b = cur.position(); if (a == b) break; } a = b; } setDocument(&m_searchTextDocument); } update(); }
int AutoCompleter::paragraphSeparatorAboutToBeInserted(QTextCursor &cursor) { QTextBlock block = cursor.block(); const QString text = block.text().trimmed(); if (text == "end" || text == "else" || text.startsWith("elsif") || text.startsWith("rescue") || text == "ensure") { Indenter indenter(const_cast<QTextDocument*>(block.document())); indenter.indentBlock(block, QChar(), tabSettings()); } return 0; // This implementation is buggy #if 0 const QString textFromCursor = text.mid(cursor.positionInBlock()).trimmed(); if (!textFromCursor.isEmpty()) return 0; if (Language::symbolDefinition.indexIn(text) == -1 && Language::startOfBlock.indexIn(text) == -1) { return 0; } int spaces = 0; for (const QChar c : text) { if (!c.isSpace()) break; spaces++; } QString indent = text.left(spaces); QString line; QTextBlock nextBlock = block.next(); while (nextBlock.isValid()) { line = nextBlock.text(); if (Language::endKeyword.indexIn(line) != -1 && line.startsWith(indent)) return 0; if (!line.trimmed().isEmpty()) break; nextBlock = nextBlock.next(); } int pos = cursor.position(); cursor.insertBlock(); cursor.insertText("end"); cursor.setPosition(pos); return 1; #endif }
int QUimTextUtil::acquireSelectionTextInQTextEdit( enum UTextOrigin origin, int former_req_len, int latter_req_len, char **former, char **latter ) { QTextEdit *edit = static_cast<QTextEdit *>( mWidget ); QTextCursor cursor = edit->textCursor(); if ( ! cursor.hasSelection() ) return -1; bool cursor_at_beginning = false; int current = cursor.position(); int start = cursor.selectionStart(); if ( current == start ) cursor_at_beginning = true; QString text = cursor.selectedText(); int len = text.length(); int offset; if ( origin == UTextOrigin_Beginning || ( origin == UTextOrigin_Cursor && cursor_at_beginning ) ) { *former = 0; offset = 0; if ( latter_req_len >= 0 ) { if ( len > latter_req_len ) offset = len - latter_req_len; } else { if (! ( ~latter_req_len & ( ~UTextExtent_Line | ~UTextExtent_Full ) ) ) return -1; } *latter = strdup( text.left( len - offset ).toUtf8().data() ); } else if ( origin == UTextOrigin_End || ( origin == UTextOrigin_Cursor && !cursor_at_beginning ) ) { offset = 0; if ( former_req_len >= 0 ) { if ( len > former_req_len ) offset = len - former_req_len; } else { if (! ( ~former_req_len & ( ~UTextExtent_Line | ~UTextExtent_Full ) ) ) return -1; } *former = strdup( text.mid( offset, len - offset ).toUtf8().data() ); *latter = 0; } else { return -1; } return 0; }
QTextLine TabTerminal::_currentTextLine(const QTextCursor & cursor) { const QTextBlock block = cursor.block(); if (!block.isValid()) return QTextLine(); const QTextLayout *layout = block.layout(); if (!layout) return QTextLine(); const int relativePos = cursor.position() - block.position(); return layout->lineForTextPosition(relativePos); }
void EmacsKeysPlugin::killLine() { if (!m_currentEditorWidget) return; m_currentState->beginOwnAction(); QTextCursor cursor = m_currentEditorWidget->textCursor(); int position = cursor.position(); cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor); if (cursor.position() == position) { // empty line cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor); } if (m_currentState->lastAction() == KeysActionKillLine) { QApplication::clipboard()->setText( QApplication::clipboard()->text() + cursor.selectedText()); } else { QApplication::clipboard()->setText(cursor.selectedText()); } cursor.removeSelectedText(); m_currentState->endOwnAction(KeysActionKillLine); }
bool CppLocalRenaming::handleSelectAll() { if (!isActive()) return false; QTextCursor cursor = m_editorWidget->textCursor(); if (!isWithinRenameSelection(cursor.position())) return false; modifyCursorSelection(cursor, renameSelectionBegin(), renameSelectionEnd()); m_editorWidget->setTextCursor(cursor); return true; }
void ItemNotes::highlight(const QRegExp &re, const QFont &highlightFont, const QPalette &highlightPalette) { m_childItem->setHighlight(re, highlightFont, highlightPalette); if (m_notes != NULL) { QList<QTextEdit::ExtraSelection> selections; if ( !re.isEmpty() ) { QTextEdit::ExtraSelection selection; selection.format.setBackground( highlightPalette.base() ); selection.format.setForeground( highlightPalette.text() ); selection.format.setFont(highlightFont); QTextCursor cur = m_notes->document()->find(re); int a = cur.position(); while ( !cur.isNull() ) { if ( cur.hasSelection() ) { selection.cursor = cur; selections.append(selection); } else { cur.movePosition(QTextCursor::NextCharacter); } cur = m_notes->document()->find(re, cur); int b = cur.position(); if (a == b) { cur.movePosition(QTextCursor::NextCharacter); cur = m_notes->document()->find(re, cur); b = cur.position(); if (a == b) break; } a = b; } } m_notes->setExtraSelections(selections); } update(); }
void TerminalEdit::append(const QString &text, QTextCharFormat *fmt) { setUndoRedoEnabled(false); QTextCursor cur = this->textCursor(); cur.movePosition(QTextCursor::End); if (fmt) { cur.setCharFormat(*fmt); } cur.insertText(text); this->setTextCursor(cur); setUndoRedoEnabled(true); m_endPostion = cur.position(); }
void ExpressionField::insertCompletion(const QModelIndex &index) { if (index.isValid()) { QString item = m_completerPopup->model()->data(index, Qt::EditRole).toString(); QTextCursor tc = textCursor(); int pos = tc.position(); if (pos - m_completerStartPos >= 1) tc.movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, pos - m_completerStartPos); tc.insertText(item); } m_completerPopup->hide(); }