void ChatView::doTrackBar() { // save position, because our manipulations could change it int scrollbarValue = verticalScrollBar()->value(); QTextCursor cursor = textCursor(); cursor.beginEditBlock(); PsiRichText::Selection selection = PsiRichText::saveSelection(this, cursor); //removeTrackBar(cursor); if (oldTrackBarPosition) { cursor.setPosition(oldTrackBarPosition, QTextCursor::KeepAnchor); QTextBlockFormat blockFormat = cursor.blockFormat(); blockFormat.clearProperty(QTextFormat::BlockTrailingHorizontalRulerWidth); cursor.clearSelection(); cursor.setBlockFormat(blockFormat); } //addTrackBar(cursor); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); oldTrackBarPosition = cursor.position(); QTextBlockFormat blockFormat = cursor.blockFormat(); blockFormat.setProperty(QTextFormat::BlockTrailingHorizontalRulerWidth, QVariant(true)); cursor.clearSelection(); cursor.setBlockFormat(blockFormat); PsiRichText::restoreSelection(this, cursor, selection); cursor.endEditBlock(); setTextCursor(cursor); verticalScrollBar()->setValue(scrollbarValue); }
/** * Duplicates the current line and inserts the copy below the line */ void HaiQTextEdit::duplicate_line() { QTextCursor cursor = textCursor(); int pos(cursor.position()); cursor.beginEditBlock(); cursor.clearSelection(); cursor.movePosition(QTextCursor::EndOfLine); cursor.select(QTextCursor::LineUnderCursor); QTextDocumentFragment text( cursor.selection() ); cursor.clearSelection(); cursor.insertText( QString(QChar::LineSeparator) ); cursor.insertFragment( text ); cursor.setPosition(pos); cursor.endEditBlock(); }
void Label::setTextInteraction(bool on, bool selectAll) { if(on && textInteractionFlags() == Qt::NoTextInteraction) { // switch on editor mode: qDebug() << textInteractionFlags(); setTextInteractionFlags(Qt::TextEditorInteraction); qDebug() << textInteractionFlags(); // manually do what a mouse click would do else: setFocus(Qt::MouseFocusReason); // this gives the item keyboard focus setSelected(true); // this ensures that itemChange() gets called when we click out of the item if(selectAll) // option to select the whole text (e.g. after creation of the TextItem) { QTextCursor c = textCursor(); c.select(QTextCursor::Document); setTextCursor(c); } } else if(!on && textInteractionFlags() == Qt::TextEditorInteraction) { // turn off editor mode: setTextInteractionFlags(Qt::NoTextInteraction); // deselect text (else it keeps gray shade): QTextCursor c = this->textCursor(); c.clearSelection(); this->setTextCursor(c); clearFocus(); } }
/** * Returns HTML markup for selected text. If no text is selected, returns * HTML markup for all text. */ QString PsiTextView::getHtml() const { PsiTextView *ptv = (PsiTextView *)this; QTextCursor cursor = ptv->textCursor(); int position = ptv->verticalScrollBar()->value(); bool unselectAll = false; if (!hasSelectedText()) { ptv->selectAll(); unselectAll = true; } QMimeData *mime = createMimeDataFromSelection(); QString result = mime->html(); delete mime; // we need to restore original position if selectAll() // was called, because setTextCursor() (which is necessary // to clear selection) will move vertical scroll bar if (unselectAll) { cursor.clearSelection(); ptv->setTextCursor(cursor); ptv->verticalScrollBar()->setValue(position); } return result; }
void FormText::clearSelection() { QTextCursor c = textCursor(); c.clearSelection(); setTextCursor( c ); }
/* * Helper method to position the text cursor always in the end of doc */ void OutputDialog::positionTextEditCursorAtEnd() { QTextCursor tc = m_textBrowser->textCursor(); tc.clearSelection(); tc.movePosition(QTextCursor::End); m_textBrowser->setTextCursor(tc); }
void ElementTitle::focusOutEvent(QFocusEvent *event) { QGraphicsTextItem::focusOutEvent(event); QString htmlNormalizedText = toHtml().remove("\n", Qt::CaseInsensitive); setTextInteractionFlags(Qt::NoTextInteraction); parentItem()->setSelected(true); // Clear selection QTextCursor cursor = textCursor(); cursor.clearSelection(); setTextCursor(cursor); unsetCursor(); if (mReadOnly) return; if (mOldText != toPlainText()) { QString value = toPlainText(); if (mBinding == "name") static_cast<NodeElement*>(parentItem())->setName(value); else static_cast<NodeElement*>(parentItem())->setLogicalProperty(mBinding, value); } setHtml(htmlNormalizedText); }
int QScriptDebuggerCodeView::find(const QString &exp, int options) { Q_D(QScriptDebuggerCodeView); QPlainTextEdit *ed = (QPlainTextEdit*)d->editor; QTextCursor cursor = ed->textCursor(); if (options & 0x100) { // start searching from the beginning of selection if (cursor.hasSelection()) { int len = cursor.selectedText().length(); cursor.clearSelection(); cursor.setPosition(cursor.position() - len); ed->setTextCursor(cursor); } options &= ~0x100; } int ret = 0; if (ed->find(exp, QTextDocument::FindFlags(options))) { ret |= 0x1; } else { QTextCursor curse = cursor; curse.movePosition(QTextCursor::Start); ed->setTextCursor(curse); if (ed->find(exp, QTextDocument::FindFlags(options))) ret |= 0x1 | 0x2; else ed->setTextCursor(cursor); } return ret; }
void TextEditEx::clearSelection() { QTextCursor cur = textCursor(); cur.clearSelection(); setTextCursor(cur); prev_pos_ = -1; }
QString ChatEdit::textEditToPlainText() { QTextDocument *doc = document(); QString result; result.reserve(doc->characterCount()); QTextCursor begin(doc); QTextCursor end; QString specialChar = QChar(QChar::ObjectReplacementCharacter); bool first = true; while (!begin.atEnd()) { end = doc->find(specialChar, begin, QTextDocument::FindCaseSensitively); QString postValue; bool atEnd = end.isNull(); if (atEnd) { end = QTextCursor(doc); QTextBlock block = doc->lastBlock(); end.setPosition(block.position() + block.length() - 1); } else { postValue = end.charFormat().toolTip(); } begin.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, end.position() - begin.position() - (atEnd ? 0 : 1)); QString selectionText = begin.selection().toPlainText(); if (!first) result += selectionText.midRef(1); else result += selectionText; result += postValue; begin = end; end.clearSelection(); first = false; } return result; }
void QConsoleWidget::dragEnterEvent(QDragEnterEvent *e){ TP::dragEnterEvent(e); if(e->isAccepted()){/*调整选区为可编辑区域*/ QTextCursor tc = this->textCursor(); if (tc.hasSelection()) { if (tc.selectionStart()>= this->promptEndPos_) { return; } else { if (tc.selectionEnd()<= this->promptEndPos_) { tc.clearSelection(); this->setTextCursor(tc); } else { auto se_ = tc.selectionEnd(); tc.setPosition(this->promptEndPos_); tc.setPosition(se_,QTextCursor::KeepAnchor); this->setTextCursor(tc); } } } } }
void GenericCodeEditor::handleKeyBackspace(QKeyEvent * event, QTextCursor & textCursor, bool & updateCursor) { if (event->modifiers() & Qt::META) { textCursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::KeepAnchor); textCursor.removeSelectedText(); } else { if ( !overwriteMode() || (textCursor.positionInBlock() == 0) || textCursor.hasSelection() ) { QPlainTextEdit::keyPressEvent(event); } else { // in overwrite mode, backspace should insert a space textCursor.beginEditBlock(); textCursor.movePosition(QTextCursor::PreviousCharacter, QTextCursor::KeepAnchor); QString selectedText = textCursor.selectedText(); if (selectedText == QStringLiteral(" ") || selectedText == QStringLiteral("\t") ) { textCursor.clearSelection(); } else { textCursor.insertText(QString(QChar(' '))); textCursor.movePosition(QTextCursor::PreviousCharacter); } textCursor.endEditBlock(); } updateCursor = true; } }
//! [5] void GraphicsScene::editorLostFocus(GraphicsTextItem *item) { #if 0 QTextCursor cursor = item->textCursor(); cursor.clearSelection(); item->setTextCursor(cursor); #endif //QMessageBox::information(NULL, "info", QString(tr("GraphicsScene::editorLostFocus"))); // 失去焦点则马上生成带文字的视频 // // 1, 判断是否修改过 umcomplete // // 2, 如果修改过内容则生成文字视频 if(item->getChanged()) { //QMessageBox::information(NULL, "info", QString(tr("GraphicsScene::editorLostFocus item: %1")).arg((int)item)); //emit updatedTextSignal(item->textAttr(), item->toPlainText()); #if 1 QString qsAss = createTotalAssInfo(); emit updatedElementsTextSignal(qsAss, item->toPlainText()); #endif } #if 0 if (item->toPlainText().isEmpty()) { removeItem(item); item->deleteLater(); } #endif curtextItem = 0; }
QString ScriptEditorWidget::textUnderCursor() const { QString szWord; QTextCursor tc = textCursor(); if(tc.atBlockStart()) return QString(); tc.clearSelection(); tc.movePosition(QTextCursor::StartOfWord,QTextCursor::KeepAnchor); if(tc.atBlockStart()) { szWord.append(tc.selectedText()); tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor); szWord.append(tc.selectedText()); if(tc.atBlockEnd()){ return szWord; } tc.movePosition(QTextCursor::NextCharacter,QTextCursor::KeepAnchor); szWord.append(tc.selectedText()); if(szWord.right(1)!=".") szWord.chop(1); return szWord; } tc.movePosition(QTextCursor::PreviousCharacter,QTextCursor::KeepAnchor); szWord=tc.selectedText(); if(szWord.left(1)==".") { tc.movePosition(QTextCursor::StartOfWord); tc.movePosition(QTextCursor::PreviousCharacter); tc.movePosition(QTextCursor::PreviousWord); tc.movePosition(QTextCursor::EndOfWord,QTextCursor::KeepAnchor,1); szWord.prepend(tc.selectedText()); } else szWord.remove(0,1); return szWord; }
void MenuMainScreen::setCurrentOption(QGraphicsSimpleTextItem *option) { QBrush whiteBrush(Qt::white); QBrush yellowBrush(Qt::yellow); if (!!_currentOption) _currentOption->setBrush(whiteBrush); _currentOption = option; _currentOption->setBrush(yellowBrush); if (option->text() == QString("Character")) _textField->setPlainText("View more information about the selected character."); else if (option->text() == QString("Equipment")) _textField->setPlainText("View or change the equipment the selected character is wearing."); else if (option->text() == QString("Abilities")) _textField->setPlainText("View the abilities of the selected character."); else if (option->text() == QString("Inventory")) _textField->setPlainText("View the items collected by the party."); else if (option->text() == QString("Exit")) _textField->setPlainText("Exit the menu."); QFont font("Times", 12, QFont::Bold); _textField->setFont(font); QTextBlockFormat format; format.setAlignment(Qt::AlignLeft); QTextCursor cursor = _textField->textCursor(); cursor.select(QTextCursor::Document); cursor.mergeBlockFormat(format); cursor.clearSelection(); _textField->setTextCursor(cursor); }
void GenericWindow::copySelected() { this->copy(); QTextCursor textCursor = this->textCursor(); textCursor.clearSelection(); this->setTextCursor(textCursor); }
QVariant UBGraphicsTextItem::itemChange(GraphicsItemChange change, const QVariant &value) { if (QGraphicsItem::ItemSelectedChange == change) { bool selected = value.toBool(); if (selected) { setTextInteractionFlags(Qt::TextEditorInteraction); } else { QTextCursor tc = textCursor(); tc.clearSelection(); setTextCursor(tc); setTextInteractionFlags(Qt::NoTextInteraction); } } QVariant newValue = value; if(mDelegate) newValue = mDelegate->itemChange(change, value); return QGraphicsTextItem::itemChange(change, newValue); }
/*! * \author Anders Fernström * \date 2006-04-21 * * \brief Set the output style */ void InputCell::setOutputStyle() { // Set the correct style for the QTextEdit output_ output_->selectAll(); Stylesheet *sheet = Stylesheet::instance( "stylesheet.xml" ); CellStyle style = sheet->getStyle( "Output" ); if( style.name() != "null" ) { output_->setAlignment( (Qt::AlignmentFlag)style.alignment() ); output_->mergeCurrentCharFormat( (*style.textCharFormat()) ); output_->document()->rootFrame()->setFrameFormat( (*style.textFrameFormat()) ); } else { // 2006-01-30 AF, add message box QString msg = "No Output style defened, please define a Output style in stylesheet.xml"; QMessageBox::warning( 0, "Warning", msg, "OK" ); } QTextCursor cursor = output_->textCursor(); cursor.clearSelection(); output_->setTextCursor( cursor ); }
void Setting::setFontColorPer() { QFont pFont; QColor pColor; if(radioButtonProgFC->isChecked()) { pFont =fontprog; pColor =Qt::black; } else if(radioButtonQuranFC->isChecked()) { pFont =fontchapter; pColor =colorQ.currentColor(); } else if(radioButtonTrFC->isChecked()) { pFont =fontchapterTr; pColor =colorTr.currentColor(); } else if(radioButtonBooksFC) { pFont =fontBook; pColor =colorBook.currentColor(); } QTextCharFormat fmt; fmt.setForeground(pColor); fmt.setFont(pFont); textEditFontPerviwe->selectAll(); QTextCursor cursor = textEditFontPerviwe->textCursor(); cursor.mergeCharFormat(fmt); textEditFontPerviwe->mergeCurrentCharFormat(fmt); cursor.clearSelection(); textEditFontPerviwe->setTextCursor(cursor); }
/** * Delete all chars from current cursor position to end of word */ void HaiQTextEdit::delete_end_of_word() { QTextCursor cursor = textCursor(); cursor.beginEditBlock(); cursor.clearSelection(); cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor); cursor.removeSelectedText(); cursor.endEditBlock(); }
void MainWindow::copySelection() { QTextCursor cursor = editor->textCursor(); if (cursor.hasSelection()) { selection = cursor.selection(); cursor.clearSelection(); } }
void GenericCodeEditor::moveLineUpDown(bool up) { // directly taken from qtcreator // Copyright (c) 2012 Nokia Corporation and/or its subsidiary(-ies). // GNU Lesser General Public License QTextCursor cursor = textCursor(); QTextCursor move = cursor; move.setVisualNavigation(false); // this opens folded items instead of destroying them move.beginEditBlock(); bool hasSelection = cursor.hasSelection(); if (cursor.hasSelection()) { move.setPosition(cursor.selectionStart()); move.movePosition(QTextCursor::StartOfBlock); move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor); move.movePosition(move.atBlockStart() ? QTextCursor::Left: QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); } else { move.movePosition(QTextCursor::StartOfBlock); move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); } QString text = move.selectedText(); move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); move.removeSelectedText(); if (up) { move.movePosition(QTextCursor::PreviousBlock); move.insertBlock(); move.movePosition(QTextCursor::Left); } else { move.movePosition(QTextCursor::EndOfBlock); if (move.atBlockStart()) { // empty block move.movePosition(QTextCursor::NextBlock); move.insertBlock(); move.movePosition(QTextCursor::Left); } else { move.insertBlock(); } } int start = move.position(); move.clearSelection(); move.insertText(text); int end = move.position(); if (hasSelection) { move.setPosition(start); move.setPosition(end, QTextCursor::KeepAnchor); } move.endEditBlock(); setTextCursor(move); }
void FormText::focusOutEvent( QFocusEvent * event ) { QTextCursor c = textCursor(); c.clearSelection(); setTextCursor( c ); QGraphicsTextItem::focusOutEvent( event ); }
static QChar charFromCursor(QTextCursor cursor, QTextCursor::MoveOperation op) { cursor.clearSelection(); if (!cursor.movePosition(op, QTextCursor::KeepAnchor)) return QChar(); if (!cursor.hasSelection()) return QChar(); return cursor.selectedText().at(0); }
// @Override virtual void focusOutEvent ( QFocusEvent * event ) { // qDebug() << "focusOutEvent"; // clear the current selection // See also http://qt-project.org/forums/viewthread/7322 QTextCursor t = textCursor(); t.clearSelection(); setTextCursor(t); QGraphicsTextItem::focusOutEvent(event); }
QString LuaConsole::getCurrentCommand() { QTextCursor cursor = ui->plainTextEdit->textCursor(); cursor.setPosition(currentCommandStartPosition, QTextCursor::MoveAnchor); cursor.movePosition(QTextCursor::End, QTextCursor::KeepAnchor); QString command = cursor.selectedText(); cursor.clearSelection(); return command; }
void ExprShortTextEdit::focusOutEvent(QFocusEvent* e) { // setTextCursor(QTextCursor()); finishEdit(); QTextCursor newCursor = textCursor(); newCursor.clearSelection(); setTextCursor(newCursor); setColor(false); hideTip(); QTextEdit::focusOutEvent(e); }
void CommentBlockView::focusOut() { m_textItem->setTextInteractionFlags(Qt::NoTextInteraction); QTextCursor c = m_textItem->textCursor(); c.clearSelection(); m_textItem->setTextCursor(c); clearFocus(); emit m_presenter.editFinished(m_textItem->toHtml()); }
void BaseEditor::findFirstOccurrance(const QString &text, QTextDocument::FindFlags qff, bool isRE, bool init, bool isSetTextCusor) { if (!finded) return; QRegExp re(text); QTextDocument *doc = document(); QTextCursor currentCursor = textCursor(); QTextCursor firstCursor; QTextEdit::ExtraSelection es; if(!init || prevFindCursor.isNull()) { QTextCursor startCursor; if(qff&QTextDocument::FindBackward && !prevFindCursor.isNull()) { prevFindCursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, abs(prevFindCursor.selectionStart()-prevFindCursor.selectionEnd())); } if(prevFindCursor.isNull()) startCursor = currentCursor; else startCursor = prevFindCursor; firstCursor = isRE ? doc->find(re, startCursor, qff): doc->find(text, startCursor, qff); } else { firstCursor = isRE ? doc->find(re, prevFindCursor.selectionStart(), qff): doc->find(text, prevFindCursor.selectionStart(), qff); } if(firstCursor.isNull()) { QTextCursor wholeCursor(doc); if(qff & QTextDocument::FindBackward) wholeCursor.movePosition(QTextCursor::End); firstCursor = isRE ? doc->find(re, wholeCursor, qff): doc->find(text, wholeCursor, qff); } if(firstCursor.isNull()) { prevFindCursor = firstCursor; return; } es.cursor = firstCursor; QTextCharFormat f; f.setBackground(Qt::blue); f.setForeground(Qt::white); es.format = f; currentFindSelection.clear(); currentFindSelection.append(es); prevFindCursor = firstCursor; firstCursor.clearSelection(); if(isSetTextCusor) setTextCursor(firstCursor); ensureCursorVisible(); updateExtraSelection(); }
//! [5] void DiagramScene::editorLostFocus(DiagramTextItem *item) { QTextCursor cursor = item->textCursor(); cursor.clearSelection(); item->setTextCursor(cursor); if (item->toPlainText().isEmpty()) { removeItem(item); item->deleteLater(); } }