void QgsMessageLogViewer::logMessage( const QString &message, const QString &tag, QgsMessageLog::MessageLevel level ) { QString cleanedTag = tag; if ( cleanedTag.isNull() ) cleanedTag = tr( "General" ); int i; for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != cleanedTag; i++ ) ; QPlainTextEdit *w = nullptr; if ( i < tabWidget->count() ) { w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) ); tabWidget->setCurrentIndex( i ); } else { w = new QPlainTextEdit( this ); w->setReadOnly( true ); tabWidget->addTab( w, cleanedTag ); tabWidget->setCurrentIndex( tabWidget->count() - 1 ); tabWidget->setTabsClosable( true ); } QString levelString; switch ( level ) { case QgsMessageLog::INFO: levelString = "INFO"; break; case QgsMessageLog::WARNING: levelString = "WARNING"; break; case QgsMessageLog::CRITICAL: levelString = "CRITICAL"; break; case QgsMessageLog::NONE: levelString = "NONE"; break; } QString prefix = QStringLiteral( "%1\t%2\t" ) .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) ) .arg( levelString ); QString cleanedMessage = message; cleanedMessage = cleanedMessage.prepend( prefix ).replace( '\n', QLatin1String( "\n\t\t\t" ) ); w->appendPlainText( cleanedMessage ); w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() ); }
void CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const { QVariant variant = index.data(Qt::EditRole); if (tryDisplay) { if (!variant.isValid()) { variant = index.data(Qt::DisplayRole); if (!variant.isValid()) { return; } } QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor); if(plainTextEdit) //for some reason it is easier to brake the loop here { if (plainTextEdit->toPlainText() == variant.toString()) { return; } } } // Color columns use a custom editor, so we need explicitly set a data for it CSVWidget::ColorEditor *colorEditor = qobject_cast<CSVWidget::ColorEditor *>(editor); if (colorEditor != nullptr) { colorEditor->setColor(variant.toInt()); return; } QByteArray n = editor->metaObject()->userProperty().name(); if (n == "dateTime") { if (editor->inherits("QTimeEdit")) n = "time"; else if (editor->inherits("QDateEdit")) n = "date"; } if (!n.isEmpty()) { if (!variant.isValid()) variant = QVariant(editor->property(n).userType(), (const void *)0); editor->setProperty(n, variant); } }
HexDumpWindow::HexDumpWindow(QString romFilePath, QWidget * parent) : QWidget(parent, Qt::Window) { this->setWindowTitle(tr("Hex Dump")); QString dump = QString::fromStdString(disassembler::RomParser::hexDump(romFilePath.toStdString())); QPlainTextEdit* editor = new QPlainTextEdit(dump); editor->setFont(QFont ("Courier", 11)); editor->setReadOnly(true); QHBoxLayout* layout = new QHBoxLayout; layout->addWidget(editor); this->setLayout(layout); this->setFixedSize(600, 600); }
DebugWidget::DebugWidget() { this->setWindowTitle("Debug Log"); this->setAttribute( Qt::WA_QuitOnClose, false ); //quit only when main window is closed QBoxLayout* layout = new QVBoxLayout(); this->setLayout(layout); QPlainTextEdit *textEdit = new QPlainTextEdit(this); QFont font = QFont("Monospace"); font.setStyleHint(QFont::TypeWriter); textEdit->setFont(font); textEdit->setReadOnly(true); layout->addWidget(textEdit); this->show(); DEBUG_DISPLAY = textEdit; }
void BudgetEntityDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { BudgetEntity entity = qvariant_cast<BudgetEntity>(index.data()); QDateEdit *dateEdit = qobject_cast<QDateEdit *>( editor->layout()->itemAt(0)->widget() ); QPlainTextEdit *textEdit = qobject_cast<QPlainTextEdit *>( editor->layout()->itemAt(1)->widget() ); QDoubleSpinBox *spinBox = qobject_cast<QDoubleSpinBox *>( editor->layout()->itemAt(2)->widget() ); entity.setDate(dateEdit->date()); entity.setDescription(textEdit->toPlainText()); entity.setAmount(spinBox->value()); QVariant val; val.setValue<BudgetEntity>(entity); model->setData(index, val, Qt::EditRole); }
//! [45] QScriptValue myPrintFunction(QScriptContext *context, QScriptEngine *engine) { QString result; for (int i = 0; i < context->argumentCount(); ++i) { if (i > 0) result.append(" "); result.append(context->argument(i).toString()); } QScriptValue calleeData = context->callee().data(); QPlainTextEdit *edit = qobject_cast<QPlainTextEdit*>(calleeData.toQObject()); edit->appendPlainText(result); return engine->undefinedValue(); }
void QtSupportPlugin::testQtOutputFormatter_appendMessage() { QPlainTextEdit edit; TestQtOutputFormatter formatter; formatter.setPlainTextEdit(&edit); QFETCH(QString, inputText); QFETCH(QString, outputText); QFETCH(QTextCharFormat, inputFormat); QFETCH(QTextCharFormat, outputFormat); formatter.appendMessage(inputText, inputFormat); QCOMPARE(edit.toPlainText(), outputText); QCOMPARE(edit.currentCharFormat(), outputFormat); }
//! [46] int main(int argc, char **argv) { QApplication app(argc, argv); QScriptEngine eng; QPlainTextEdit edit; QScriptValue fun = eng.newFunction(myPrintFunction); fun.setData(eng.newQObject(&edit)); eng.globalObject().setProperty("print", fun); eng.evaluate("print('hello', 'world')"); edit.show(); return app.exec(); }
void PlainTextViewWidget::searchDocument(const QString &text, Qt::CaseSensitivity caseSensitive) { m_currentSearchResult = QTextCursor(); m_searchResults.clear(); QTextDocument::FindFlags findFlags; if (caseSensitive == Qt::CaseSensitive) { findFlags |= QTextDocument::FindCaseSensitively; } QPlainTextEdit *textEdit = ui->plainTextEdit; QTextDocument *textDocument = textEdit->document(); QTextCursor currentCursor = textEdit->textCursor(); currentCursor.clearSelection(); // To get QTextDocument::find to work properly // Find all results forwards beginning from current cursor QTextCursor findCursor = textDocument->find(text, currentCursor, findFlags); if (!findCursor.isNull()) { // Set to first result after current cursor pos m_currentSearchResult = findCursor; } while (!findCursor.isNull()) { m_searchResults.append(findCursor); findCursor = textDocument->find(text, findCursor, findFlags); } // Find all results backwards beginning from current cursor findFlags |= QTextDocument::FindBackward; findCursor = textDocument->find(text, currentCursor, findFlags); while (!findCursor.isNull()) { m_searchResults.prepend(findCursor); findCursor = textDocument->find(text, findCursor, findFlags); } if (m_searchResults.isEmpty()) { ui->searchBar->setResultNumberAndCount(0, 0); return; } if (m_currentSearchResult.isNull()) { // Set to first result because after current cursor pos wasn't a search match m_currentSearchResult = m_searchResults.at(0); } jumpToHighlightResult(m_currentSearchResult); }
// TODO: Can this be improved? This code is ripped from CppEditor, especially CppElementEvaluater // We cannot depend on this since CppEditor plugin code is internal and requires building the implementation files ourselves CPlusPlus::Symbol *AnalyzerUtils::findSymbolUnderCursor() { EditorManager *editorManager = EditorManager::instance(); if (!editorManager) return 0; IEditor *editor = editorManager->currentEditor(); if (!editor) return 0; TextEditor::ITextEditor *textEditor = qobject_cast<TextEditor::ITextEditor *>(editor); if (!textEditor) return 0; TextEditor::BaseTextEditorWidget *editorWidget = qobject_cast<TextEditor::BaseTextEditorWidget *>(editor->widget()); if (!editorWidget) return 0; QPlainTextEdit *ptEdit = qobject_cast<QPlainTextEdit *>(editor->widget()); if (!ptEdit) return 0; QTextCursor tc; tc = ptEdit->textCursor(); int line = 0; int column = 0; const int pos = tc.position(); editorWidget->convertPosition(pos, &line, &column); const CPlusPlus::Snapshot &snapshot = CPlusPlus::CppModelManagerInterface::instance()->snapshot(); CPlusPlus::Document::Ptr doc = snapshot.document(editor->document()->fileName()); QTC_ASSERT(doc, return 0) // fetch the expression's code CPlusPlus::ExpressionUnderCursor expressionUnderCursor; moveCursorToEndOfName(&tc); const QString &expression = expressionUnderCursor(tc); CPlusPlus::Scope *scope = doc->scopeAt(line, column); CPlusPlus::TypeOfExpression typeOfExpression; typeOfExpression.init(doc, snapshot); const QList<CPlusPlus::LookupItem> &lookupItems = typeOfExpression(expression.toUtf8(), scope); if (lookupItems.isEmpty()) return 0; const CPlusPlus::LookupItem &lookupItem = lookupItems.first(); // ### TODO: select best candidate. return lookupItem.declaration(); }
void FakeVimProxy::indentRegion(int beginBlock, int endBlock, QChar typedChar) { QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget); if (!ed) return; const auto indentSize = theFakeVimSetting(FakeVim::Internal::ConfigShiftWidth) ->value().toInt(); QTextDocument *doc = ed->document(); QTextBlock startBlock = doc->findBlockByNumber(beginBlock); // Record line lengths for mark adjustments QVector<int> lineLengths(endBlock - beginBlock + 1); QTextBlock block = startBlock; for (int i = beginBlock; i <= endBlock; ++i) { const auto line = block.text(); lineLengths[i - beginBlock] = line.length(); if (typedChar.unicode() == 0 && line.simplified().isEmpty()) { // clear empty lines QTextCursor cursor(block); while (!cursor.atBlockEnd()) cursor.deleteChar(); } else { const auto previousBlock = block.previous(); const auto previousLine = previousBlock.isValid() ? previousBlock.text() : QString(); int indent = firstNonSpace(previousLine); if (typedChar == '}') indent = std::max(0, indent - indentSize); else if ( previousLine.endsWith("{") ) indent += indentSize; const auto indentString = QString(" ").repeated(indent); QTextCursor cursor(block); cursor.beginEditBlock(); cursor.movePosition(QTextCursor::StartOfBlock); cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor, firstNonSpace(line)); cursor.removeSelectedText(); cursor.insertText(indentString); cursor.endEditBlock(); } block = block.next(); } }
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 Authorization::test_answer(QNetworkReply *reply) { QStringList html; while (!reply->atEnd()) html << QString(reply->readLine()); QPlainTextEdit *text = new QPlainTextEdit(); text->appendPlainText(html.join('\n')); QStringList headers; QList<QByteArray> headerList = reply->request().rawHeaderList(); foreach (QByteArray header, headerList) headers << QString(header+"\t"+reply->request().rawHeader(header)); text->appendPlainText(headers.join('\n')); headerList = reply->rawHeaderList(); foreach (QByteArray header, headerList) headers << QString(header+"\t"+reply->rawHeader(header)); text->appendPlainText(headers.join('\n')); text->appendPlainText(reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toString()); text->appendPlainText(reply->errorString()); text->show(); if (reply->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt() == 302) { QNetworkAccessManager *manager = new QNetworkAccessManager(this); QNetworkRequest request(QUrl(reply->rawHeader("Location"))); request.setHeader(QNetworkRequest::CookieHeader, reply->header(QNetworkRequest::SetCookieHeader)); manager->get(request); connect(manager, SIGNAL(finished(QNetworkReply*)), SLOT(test_answer(QNetworkReply*))); connect(manager, SIGNAL(finished(QNetworkReply*)), manager, SLOT(deleteLater())); } }
void FakeVimProxy::requestDisableBlockSelection() { QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget); if (!ed) return; QPalette pal = ed->parentWidget() != NULL ? ed->parentWidget()->palette() : QApplication::palette(); m_blockSelection.clear(); m_clearSelection.clear(); ed->setPalette(pal); disconnect( ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection ); updateExtraSelections(); }
void LogWindow::onTimeout() { QMap<QPlainTextEdit*, QStringList> updates; QStringList buffer; { // lock scope QMutexLocker lock(&sMutex); buffer = mBuffer; mBuffer = QStringList(); mAllBuffer = QString(); QMutableMapIterator<int, LogTypeStruct> messages(mLogTypes); while(messages.hasNext()) { LogTypeStruct& logType = messages.next().value(); if(logType.buffer.isEmpty()) continue; updates.insert(logType.edit, logType.buffer); logType.buffer = QStringList(); } } int maxBlocks = ui->plainTextEdit->maximumBlockCount(); int startElement = qMax(0, buffer.size()-maxBlocks); for(int i=startElement; i<buffer.size(); i++) { ui->plainTextEdit->appendPlainText(buffer[i]); } QApplication::processEvents(); QMapIterator<QPlainTextEdit*, QStringList> iter(updates); while(iter.hasNext()) { iter.next(); QPlainTextEdit* edit = iter.key(); const QStringList& dataBuffer = iter.value(); maxBlocks = edit->maximumBlockCount(); startElement = qMax(0, dataBuffer.size()-maxBlocks); for(int i=startElement; i<dataBuffer.size(); i++) { edit->appendPlainText(dataBuffer[i]); } QApplication::processEvents(); } mTimer.start(300); }
void LiveDataWidget::updateContent() { QPlainTextEdit *edit = qobject_cast<QPlainTextEdit*>(sender()); if (edit == NULL) return; if (!edit->hasFocus()) return; if (_shortNameListView->hasFocus()) return; if (_isAddNew) return; QSqlQuery query(_db); //if (!query.prepare(QString("UPDATE [LiveData") + // edit->objectName() + // QString("] Set Content='") + // edit->toPlainText() + // QString("'") + // QString("'") + // QString(" WHERE ShortName='") + // _shortNameListView->currentIndex().data().toString() + // QString("' AND Catalog='") + // _currentCatalog + // QString("'"))) //{ // QString err = query.lastError().databaseText(); // return; //} if (!query.prepare(QString("UPDATE [LiveData") + edit->objectName() + QString("] Set Content=:content WHERE ShortName=:shortName AND Catalog=:catalog"))) { QString err = query.lastError().databaseText(); return; } query.bindValue(":content", edit->toPlainText()); query.bindValue(":shortName", _shortNameListView->currentIndex().data()); query.bindValue(":catalog", _currentCatalog); query.exec(); }
ScriptLogWindow::ScriptLogWindow() : QWidget(nullptr) { const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); QPlainTextEdit *edit = new QPlainTextEdit(); edit->setReadOnly(true); edit->setFont(fixedFont); edit->setWordWrapMode(QTextOption::NoWrap); QHBoxLayout *buttonLayout = new QHBoxLayout(); QPushButton *clearButton = new QPushButton(tr("Clear")); connect(clearButton, &QPushButton::clicked, this, &ScriptLogWindow::ClearWindow); QPushButton *closeButton = new QPushButton(tr("Close")); connect(closeButton, &QPushButton::clicked, this, &QDialog::hide); buttonLayout->addStretch(); buttonLayout->addWidget(clearButton); buttonLayout->addWidget(closeButton); QVBoxLayout *layout = new QVBoxLayout(); layout->addWidget(edit); layout->addLayout(buttonLayout); setLayout(layout); scriptLogWidget = edit; resize(600, 400); config_t *global_config = obs_frontend_get_global_config(); const char *geom = config_get_string(global_config, "ScriptLogWindow", "geometry"); if (geom != nullptr) { QByteArray ba = QByteArray::fromBase64(QByteArray(geom)); restoreGeometry(ba); } setWindowTitle(obs_module_text("ScriptLogWindow")); connect(edit->verticalScrollBar(), &QAbstractSlider::sliderMoved, this, &ScriptLogWindow::ScrollChanged); }
void GoplayBrowser::newPlay() { /* if (m_editor->isModified()) { int r = QMessageBox::question(m_widget,tr("Goplay"),tr("File is Modified, save or cancel?"),QMessageBox::Save,QMessageBox::No,QMessageBox::Cancel); if (r == QMessageBox::Cancel) { return; } if (r == QMessageBox::Save) { savePlay(); } } */ m_editFile.clear(); QPlainTextEdit *edit = LiteApi::findExtensionObject<QPlainTextEdit*>(m_editor,"LiteApi.QPlainTextEdit"); if (edit) { edit->setPlainText(data); } m_editLabel->setText(""); }
void FindEditor::setVisible(bool b) { this->m_widget->setVisible(b); if (b) { LiteApi::IEditor *editor = m_liteApp->editorManager()->currentEditor(); if (editor) { QString text; QPlainTextEdit *ed = LiteApi::findExtensionObject<QPlainTextEdit*>(editor,"LiteApi.QPlainTextEdit"); if (ed) { text = ed->textCursor().selectedText(); } if (!text.isEmpty()) { this->m_findEdit->setText(text); } this->m_findEdit->setFocus(); this->m_findEdit->selectAll(); } } updateCurrentEditor(m_liteApp->editorManager()->currentEditor()); }
void ItemEditorWidget::initMenuItems() { Q_ASSERT(m_editor); foreach (QAction *action, m_toolBar->actions()) delete action; QAction *act; act = new QAction( iconSave(), tr("Save"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Save Item (<strong>F2</strong>)") ); act->setShortcut( QKeySequence(tr("F2", "Shortcut to save item editor changes")) ); connect( act, SIGNAL(triggered()), this, SLOT(saveAndExit()) ); act = new QAction( iconCancel(), tr("Cancel"), m_editor ); m_toolBar->addAction(act); act->setToolTip( tr("Cancel Editing and Revert Changes") ); act->setShortcut( QKeySequence(tr("Escape", "Shortcut to revert item editor changes")) ); connect( act, SIGNAL(triggered()), this, SIGNAL(cancel()) ); QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit*>(m_editor); if (plainTextEdit != NULL) { plainTextEdit->setFrameShape(QFrame::NoFrame); act = new QAction( iconUndo(), tr("Undo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Undo); act->setEnabled(false); connect( act, SIGNAL(triggered()), plainTextEdit, SLOT(undo()) ); connect( plainTextEdit, SIGNAL(undoAvailable(bool)), act, SLOT(setEnabled(bool)) ); act = new QAction( iconRedo(), tr("Redo"), m_editor ); m_toolBar->addAction(act); act->setShortcut(QKeySequence::Redo); act->setEnabled(false); connect( act, SIGNAL(triggered()), plainTextEdit, SLOT(redo()) ); connect( plainTextEdit, SIGNAL(redoAvailable(bool)), act, SLOT(setEnabled(bool)) ); } }
//------------------------------------------------------------------------- QPlainTextEdit* MainWindow::addNewTab(const QString& fileName) { QFileInfo file(fileName); QString base = file.fileName(); int tabIndex = 0; if (ui.tabWidget->count() == 1 && ui.tabWidget->tabToolTip(0).isEmpty()) { ui.tabWidget->setTabText(0, base); } else { tabIndex = ui.tabWidget->addTab(createSourceTextEdit(), base); } ui.tabWidget->setCurrentIndex(tabIndex); ui.tabWidget->setTabToolTip(tabIndex, fileName); QPlainTextEdit *result = getCurrentSourceCode(); new CPPHighlighter(result->document()); return result; }
void QgsMessageLogViewer::logMessage( QString message, QString tag, QgsMessageLog::MessageLevel level ) { #ifdef ANDROID mButton->setToolTip( tr( "Message(s) logged." ) ); #endif if ( !isVisible() && level > QgsMessageLog::INFO ) { mButton->show(); if ( mShowToolTips ) QToolTip::showText( mButton->mapToGlobal( QPoint( 0, 0 ) ), mButton->toolTip() ); } if ( tag.isNull() ) tag = tr( "General" ); int i; for ( i = 0; i < tabWidget->count() && tabWidget->tabText( i ) != tag; i++ ) ; QPlainTextEdit *w; if ( i < tabWidget->count() ) { w = qobject_cast<QPlainTextEdit *>( tabWidget->widget( i ) ); tabWidget->setCurrentIndex( i ); } else { w = new QPlainTextEdit( this ); w->setReadOnly( true ); tabWidget->addTab( w, tag ); tabWidget->setCurrentIndex( tabWidget->count() - 1 ); } QString prefix = QString( "%1\t%2\t") .arg( QDateTime::currentDateTime().toString( Qt::ISODate ) ) .arg( level ); w->appendPlainText( message.prepend( prefix ).replace( "\n", "\n\t\t\t" ) ); w->verticalScrollBar()->setValue( w->verticalScrollBar()->maximum() ); }
void FakeVimProxy::highlightMatches(const QString &pattern) { QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(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 CSVWorld::CommandDelegate::setEditorData (QWidget *editor, const QModelIndex& index, bool tryDisplay) const { QVariant v = index.data(Qt::EditRole); if (tryDisplay) { if (!v.isValid()) { v = index.data(Qt::DisplayRole); if (!v.isValid()) { return; } } QPlainTextEdit* plainTextEdit = qobject_cast<QPlainTextEdit*>(editor); if(plainTextEdit) //for some reason it is easier to brake the loop here { if(plainTextEdit->toPlainText() == v.toString()) { return; } } } QByteArray n = editor->metaObject()->userProperty().name(); if (n == "dateTime") { if (editor->inherits("QTimeEdit")) n = "time"; else if (editor->inherits("QDateEdit")) n = "date"; } if (!n.isEmpty()) { if (!v.isValid()) v = QVariant(editor->property(n).userType(), (const void *)0); editor->setProperty(n, v); } }
void DesignDocumentControllerView::fromText(QString text) { QScopedPointer<Model> inputModel(Model::create("QtQuick.Rectangle", 1, 0, model())); inputModel->setFileUrl(model()->fileUrl()); QPlainTextEdit textEdit; QString imports; foreach (const Import &import, model()->imports()) imports += import.toString(true, true) + "\n"; textEdit.setPlainText(imports + text); NotIndentingTextEditModifier modifier(&textEdit); QScopedPointer<RewriterView> rewriterView(new RewriterView(RewriterView::Amend, 0)); rewriterView->setCheckSemanticErrors(false); rewriterView->setTextModifier(&modifier); inputModel->attachView(rewriterView.data()); if (rewriterView->errors().isEmpty() && rewriterView->rootModelNode().isValid()) { ModelMerger merger(this); merger.replaceModel(rewriterView->rootModelNode()); } }
void FindEditor::findHelper(FindOption *opt) { bool bFocus = m_findEdit->hasFocus(); LiteApi::IEditor *editor = m_liteApp->editorManager()->currentEditor(); if (!editor) { return; } LiteApi::ITextEditor *textEditor = LiteApi::getTextEditor(editor); QTextCursor find; if (textEditor) { QPlainTextEdit *ed = LiteApi::getPlainTextEdit(editor); if (ed) { find = findEditor(ed->document(),ed->textCursor(),opt); if (!find.isNull()) { ed->setTextCursor(find); } } } else { QTextBrowser *ed = LiteApi::findExtensionObject<QTextBrowser*>(editor,"LiteApi.QTextBrowser"); if (ed) { find = findEditor(ed->document(),ed->textCursor(),opt); if (!find.isNull()) { ed->setTextCursor(find); } } } if (find.isNull()) { m_status->setText(tr("Not find")); } else { m_status->setText(QString("Ln:%1 Col:%2"). arg(find.blockNumber()+1). arg(find.columnNumber()+1)); } if (bFocus) { m_findEdit->setFocus(); } else if (textEditor) { textEditor->onActive(); } }
QsvTextOperationsWidget::QsvTextOperationsWidget( QWidget *parent ) : QObject(parent) { setObjectName("QsvTextOperationWidget"); m_gotoLine = NULL; m_search = NULL; m_replace = NULL; m_document = NULL; searchFormUi = NULL; replaceFormUi = NULL; searchFoundColor = QColor( "#DDDDFF" ); //QColor::fromRgb( 220, 220, 255) searchNotFoundColor = QColor( "#FFAAAA" ); //QColor::fromRgb( 255, 102, 102) "#FF6666" m_replaceTimer.setInterval(100); m_replaceTimer.setSingleShot(true); connect(&m_replaceTimer,SIGNAL(timeout()),this,SLOT(updateReplaceInput())); // this one is slower, to let the user think about his action // this is a modifying command, unlike a passive search m_searchTimer.setInterval(250); m_searchTimer.setSingleShot(true); connect(&m_searchTimer,SIGNAL(timeout()),this,SLOT(updateSearchInput())); // TODO clean this up, this is too ugly to be in a constructor QTextEdit *t = qobject_cast<QTextEdit*>(parent); if (t) { m_document = t->document(); } else { QPlainTextEdit *pt = qobject_cast<QPlainTextEdit*>(parent); if (pt) { m_document = pt->document(); } } connect(parent,SIGNAL(widgetResized()),this,SLOT(adjustBottomWidget())); parent->installEventFilter(this); }
//------------------------------------------------------------------------- void MainWindow::insertTextAtLine(int lineNr, const char* pText) { QPlainTextEdit *sourceCode = getCurrentSourceCode(); if (lineNr >= 0) { QTextCursor sourceCursor = sourceCode->textCursor(); sourceCursor.setPosition(sourceCode->document()->findBlockByLineNumber(lineNr).position()); sourceCode->setTextCursor(sourceCursor); } else { sourceCode->moveCursor(QTextCursor::StartOfLine); } sourceCode->insertPlainText(QString::fromUtf8(pText)); }
void FakeVimProxy::requestSetBlockSelection(const QTextCursor &tc) { QPlainTextEdit *ed = qobject_cast<QPlainTextEdit *>(m_widget); if (!ed) return; QPalette pal = ed->parentWidget() != NULL ? ed->parentWidget()->palette() : QApplication::palette(); m_blockSelection.clear(); m_clearSelection.clear(); QTextCursor cur = tc; QTextEdit::ExtraSelection selection; selection.format.setBackground( pal.color(QPalette::Base) ); selection.format.setForeground( pal.color(QPalette::Text) ); selection.cursor = cur; m_clearSelection.append(selection); selection.format.setBackground( pal.color(QPalette::Highlight) ); selection.format.setForeground( pal.color(QPalette::HighlightedText) ); int from = cur.positionInBlock(); int to = cur.anchor() - cur.document()->findBlock(cur.anchor()).position(); const int min = qMin(cur.position(), cur.anchor()); const int max = qMax(cur.position(), cur.anchor()); for ( QTextBlock block = cur.document()->findBlock(min); block.isValid() && block.position() < max; block = block.next() ) { cur.setPosition( block.position() + qMin(from, block.length()) ); cur.setPosition( block.position() + qMin(to, block.length()), QTextCursor::KeepAnchor ); selection.cursor = cur; m_blockSelection.append(selection); } disconnect( ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection ); ed->setTextCursor(tc); connect( ed, &QPlainTextEdit::selectionChanged, this, &FakeVimProxy::updateBlockSelection ); QPalette pal2 = ed->palette(); pal2.setColor(QPalette::Highlight, Qt::transparent); pal2.setColor(QPalette::HighlightedText, Qt::transparent); ed->setPalette(pal2); updateExtraSelections(); }
void MessagesDialog::filterMessages() { QMutexLocker locker( &messageLocker ); QPlainTextEdit *messages = ui.messages; QTextBlock block = messages->document()->firstBlock(); while( block.isValid() ) { block.setVisible( matchFilter( block.text().toLower() ) ); block = block.next(); } /* Consider the whole QTextDocument as dirty now */ messages->document()->markContentsDirty( 0, messages->document()->characterCount() ); /* FIXME This solves a bug (Qt?) with the viewport not resizing the vertical scroll bar when one or more QTextBlock are hidden */ QSize vsize = messages->viewport()->size(); messages->viewport()->resize( vsize + QSize( 1, 1 ) ); messages->viewport()->resize( vsize ); }