void ScriptingWidget::appendPrompt() { QString prompt; InterpreterManager* pInterMgr = dynamic_cast<InterpreterManager*>(mInterpreter.get()); if (pInterMgr != NULL) { Interpreter* pInterpreter = pInterMgr->getInterpreter(); if (pInterMgr->isStarted() && pInterpreter != NULL && mInteractive) { prompt = QString::fromStdString(pInterpreter->getPrompt()); } } mPrompt = prompt; setCurrentFont(font()); setTextColor(Qt::black); if (!prompt.isEmpty()) { QTextCursor cursorPosition = textCursor(); cursorPosition.movePosition(QTextCursor::End); int endPos = cursorPosition.position(); cursorPosition.movePosition(QTextCursor::StartOfLine); int startLinePos = cursorPosition.position(); cursorPosition.movePosition(QTextCursor::End); if (startLinePos != endPos) { cursorPosition.insertText("\n", currentCharFormat()); } cursorPosition.insertText(mPrompt, currentCharFormat()); setTextCursor(cursorPosition); } mCommandStartPos = toPlainText().size(); setCurrentFont(mCommandFont); }
TextInputWidget::TextInputWidget(QWidget *parent) : QPlainTextEdit(parent) { QPalette p = palette(); p.setColor(QPalette::Base,QColor(245, 245, 245, 200)); p.setColor(QPalette::Text, Qt::black); setPalette(p); QFont f=font(); f.setPointSize(12); setFont(f); setContextMenuPolicy(Qt::CustomContextMenu); connect(this,SIGNAL(customContextMenuRequested(const QPoint&)), this,SLOT(showContextMenu(const QPoint &))); lastredcharpos=0; defaultformat=currentCharFormat(); defaultformat.setForeground(Qt::black); redformat=currentCharFormat(); redformat.setForeground(QColor("#990000")); textinputdevice = new TextInputDevice(this); timer = new QTimer(this); connect(timer, SIGNAL(timeout()), this, SLOT(redupdate())); timer->start(500); }
TextEditor::TextEditor(QWidget *parent): QPlainTextEdit(parent) { connect(this, SIGNAL(textChanged()), this, SLOT(UpdateDocumentStatus())); LineCountArea = new LineNumberArea(this); connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(UpdateLineNumberAreaWidth(int))); connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(UpdateLineNumberArea(QRect,int))); UpdateLineNumberAreaWidth(0); // connect(this, SIGNAL(cursorPositionChanged()), // this, SLOT(Highlight_Current_Line())); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(bracketValidate())); setFont(QFont("Monaco", 12)); setTabSize(4); Size = 0; Counter = 0; Start = 0; End = 0; // Setup autocomplete minCompleterLength = 1; c = new QCompleter(this); // c->setModelSorting(QCompleter::CaseInsensitivelySortedModel); c->setCompletionMode(QCompleter::PopupCompletion); c->setCaseSensitivity(Qt::CaseInsensitive); c->setWrapAround(false); c->setWidget(this); c->popup()->setObjectName("autocomplete"); completerModel = new QStringListModel(getWords(), c); c->setModel(completerModel); connect(this, SIGNAL(textChanged()), this, SLOT(updateCompleterModel())); QTextOption option = document()->defaultTextOption(); bool on = false; if (on) { option.setFlags(option.flags() | QTextOption::ShowTabsAndSpaces); } else { option.setFlags(option.flags() & ~QTextOption::ShowTabsAndSpaces); } option.setFlags(option.flags() | QTextOption::AddSpaceForLineAndParagraphSeparators); document()->setDefaultTextOption(option); setTabsAsSpaces(true); bracketMismatchFormat = currentCharFormat(); bracketMismatchFormat.setBackground(QColor(255, 223, 223)); bracketMatchFormat = currentCharFormat(); bracketMatchFormat.setBackground(QColor(158, 209, 255)); }
bool SourceWindow::loadFile() { QFile f(m_fileName); if (!f.open(QIODevice::ReadOnly)) { return false; } QTextStream t(&f); setPlainText(t.readAll()); f.close(); int n = blockCount(); m_sourceCode.resize(n); m_rowToLine.resize(n); for (int i = 0; i < n; i++) { m_rowToLine[i] = i; } m_lineItems.resize(n, 0); // set a font for line numbers m_lineNoFont = currentCharFormat().font(); m_lineNoFont.setPixelSize(11); return true; }
void RichTextLineEdit::applyTextEffect() { if (QAction *action = qobject_cast<QAction*>(sender())) { Style style = static_cast<Style>(action->data().toInt()); QTextCharFormat format = currentCharFormat(); switch (style) { case Bold: toggleBold(); return; case Italic: toggleItalic(); return; case StrikeOut: format.setFontStrikeOut(!format.fontStrikeOut()); break; case NoSuperOrSubscript: format.setVerticalAlignment( QTextCharFormat::AlignNormal); break; case Superscript: format.setVerticalAlignment( QTextCharFormat::AlignSuperScript); break; case Subscript: format.setVerticalAlignment( QTextCharFormat::AlignSubScript); break; } mergeCurrentCharFormat(format); } }
milxQtPythonConsole::milxQtPythonConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags windowFlags) : QTextEdit(parent) { setWindowFlags(windowFlags); _defaultTextCharacterFormat = currentCharFormat(); _context = context; _historyPosition = 0; _hadError = false; _completer = new QCompleter(this); _completer->setWidget(this); QObject::connect(_completer, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&))); QTextEdit::clear(); consoleMessage("milxQt Python Console\nMain window is 'MainWindow' and displayed windows are 'rnd_<name>', 'img_<name>' and 'mdl_<name>'\nFile IO can be done using 'milxQtFile'."); appendCommandPrompt(); createActions(); createConnections(); readSettings(); }
void SparqlTextEdit::paintLineNumbers(QPaintEvent *e) { QFontMetrics metrics(currentCharFormat().font()); int digits = 0; int blocks = blockCount(); do { blocks /= 10; ++digits; } while (blocks); int maxCharWidth = 0; for (char c = '0'; c <= '9'; c++) { maxCharWidth = qMax(maxCharWidth, metrics.width(c)); } int newLeftMargin = frameWidth() + maxCharWidth * digits; if (leftMargin != newLeftMargin) { leftMargin = newLeftMargin; setViewportMargins(leftMargin, 0, 0, 0); } QPainter painter(this); painter.setClipRect(lineNumbersRect(), Qt::IntersectClip); painter.fillRect(e->rect(), palette().window()); painter.setPen(palette().windowText().color()); painter.setFont(currentCharFormat().font()); QTextBlock block = firstVisibleBlock(); int blockNumber = block.blockNumber(); int top = (int) blockBoundingGeometry(block) .translated(contentOffset()).top() + lineNumbersRect().top(); int bottom = top + (int) blockBoundingRect(block).height(); while (block.isValid() && top <= e->rect().bottom()) { if (block.isVisible() && bottom >= e->rect().top()) { QString number = QString::number(blockNumber + 1); painter.drawText(0, top, leftMargin, metrics.height(), Qt::AlignRight, number); } block = block.next(); top = bottom; bottom = top + (int) blockBoundingRect(block).height(); ++blockNumber; } }
void ConsoleWidget::handleColor(const QColor &color) { QTextCharFormat tf = currentCharFormat(); if (color!=tf.foreground().color()) { tf.setForeground(color); setCurrentCharFormat(tf); } }
void ConsoleWidget::handleColor(const QColor &color) { if (color!=m_color) { QTextCharFormat tf = currentCharFormat(); tf.setForeground(color); setCurrentCharFormat(tf); m_color = color; } }
void RichTextLineEdit::updateContextMenuActions() { boldAction->setChecked(fontWeight() > QFont::Normal); italicAction->setChecked(fontItalic()); const QTextCharFormat &format = currentCharFormat(); strikeOutAction->setChecked(format.fontStrikeOut()); noSubOrSuperScriptAction->setChecked(format.verticalAlignment() == QTextCharFormat::AlignNormal); superScriptAction->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSuperScript); subScriptAction->setChecked(format.verticalAlignment() == QTextCharFormat::AlignSubScript); }
void ScriptingWidget::executeCommand() { QString strCommand = getCommandText(); if (strCommand.isEmpty() == false) { // Add the command to the stack and reset the current stack command // Current stack command should be one past end of stack. mCommandStack.append(strCommand); mCommandIndex = mCommandStack.count(); } QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n", currentCharFormat()); executeCommand(strCommand); }
OutputWindowPlainTextEdit::OutputWindowPlainTextEdit(QWidget *parent) : QPlainTextEdit(parent), m_defaultFormat(currentCharFormat()), m_errorFormat(m_defaultFormat), m_warningFormat(m_defaultFormat), m_commandFormat(m_defaultFormat), m_messageFormat(m_defaultFormat) { setReadOnly(true); setUndoRedoEnabled(false); setFrameStyle(QFrame::NoFrame); m_errorFormat.setForeground(Qt::red); m_warningFormat.setForeground(Qt::darkYellow); m_commandFormat.setFontWeight(QFont::Bold); m_messageFormat.setForeground(Qt::blue); m_formatter = new Utils::OutputFormatter; m_formatter->setPlainTextEdit(this); }
PythonQtScriptingConsole::PythonQtScriptingConsole(QWidget* parent, const PythonQtObjectPtr& context, Qt::WindowFlags windowFlags) : QTextEdit(parent) { setWindowFlags(windowFlags); _defaultTextCharacterFormat = currentCharFormat(); _context = context; _historyPosition = 0; _hadError = false; _completer = new QCompleter(this); _completer->setWidget(this); QObject::connect(_completer, SIGNAL(activated(const QString&)), this, SLOT(insertCompletion(const QString&))); clear(); connect(PythonQt::self(), SIGNAL(pythonStdOut(const QString&)), this, SLOT(stdOut(const QString&))); connect(PythonQt::self(), SIGNAL(pythonStdErr(const QString&)), this, SLOT(stdErr(const QString&))); }
void OutputWindowPlainTextEdit::appendLines(QString const& s, const QString &repository) { if (s.isEmpty()) return; const int previousLineCount = document()->lineCount(); const QChar newLine(QLatin1Char('\n')); const QChar lastChar = s.at(s.size() - 1); const bool appendNewline = (lastChar != QLatin1Char('\r') && lastChar != newLine); m_formatter->appendMessage(appendNewline ? s + newLine : s, currentCharFormat()); // Scroll down moveCursor(QTextCursor::End); ensureCursorVisible(); if (!repository.isEmpty()) { // Associate repository with new data. QTextBlock block = document()->findBlockByLineNumber(previousLineCount); for ( ; block.isValid(); block = block.next()) block.setUserData(new RepositoryUserData(repository)); } }
void ScriptingWidget::addOutputText(const QString& strMessage, bool error, bool processEvents) { if (strMessage.isEmpty() == false) { QTextCharFormat newTextFormat = currentCharFormat(); if (error) { newTextFormat.setFont(mErrorFont); newTextFormat.setForeground(QBrush(mErrorColor)); } else { newTextFormat.setFont(mOutputFont); newTextFormat.setForeground(QBrush(mOutputColor)); } QTextCursor cursor = textCursor(); cursor.clearSelection(); if (mExecutingCommand) { cursor.movePosition(QTextCursor::End); } else { int pos = std::max(mCommandStartPos - mPrompt.size(), 0); cursor.setPosition(pos); mCommandStartPos += strMessage.size(); } cursor.insertText(strMessage, newTextFormat); if (mExecutingCommand) { setTextCursor(cursor); } if (processEvents) { QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents); } } }
void ScriptingWidget::insertFromMimeData(const QMimeData* pSource) { QString filePath; QString text; if (mDropOccurring && pSource->hasUrls()) { QList<QUrl> urls = pSource->urls(); if (!urls.empty()) { filePath = urls.front().toLocalFile(); } } if (pSource->hasText()) { text = pSource->text(); int numNewlines = text.count("\n"); QString trimmedText = text.trimmed(); bool haveFile = false; if (mDropOccurring && numNewlines <= 1 && QFile::exists(trimmedText)) { filePath = trimmedText; } } if (!filePath.isEmpty()) { //don't get here if mDropOccurring == false InterpreterManager* pInterMgr = dynamic_cast<InterpreterManager*>(mInterpreter.get()); bool bMatch = false; if (pInterMgr != NULL) { QString strInterpreterExtensions = QString::fromStdString(pInterMgr->getFileExtensions()); if (!strInterpreterExtensions.isEmpty()) { QStringList filterListCandidates = strInterpreterExtensions.split(";;", QString::SkipEmptyParts); QStringList filterList; for (int i = 0; i < filterListCandidates.count(); i++) { QString strExtensions = filterListCandidates[i]; if (strExtensions.isEmpty() == false) { int iOpenPos = strExtensions.indexOf("("); int iClosePos = strExtensions.lastIndexOf(")"); strExtensions = strExtensions.mid(iOpenPos + 1, iClosePos - iOpenPos - 1); QStringList globPatterns = strExtensions.split(QString(" "), QString::SkipEmptyParts); QString catchAll = QString::fromStdString("*"); QString catchAll2 = QString::fromStdString("*.*"); for (int globCount = 0; globCount < globPatterns.count(); ++globCount) { QString pattern = globPatterns[globCount]; if ((pattern != catchAll) && (pattern != catchAll2)) { filterList << pattern; } } } } bMatch = QDir::match(filterList, filePath); } } QFile file(filePath); if (bMatch && file.open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream reader(&file); QString fileContent = reader.readAll(); QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n"); executeCommand(fileContent); return; } } if (!text.isEmpty()) { bool insertText = true; if (mDropOccurring) { if (getCommandText().isEmpty()) { insertText = false; QTextCursor cursor = textCursor(); cursor.movePosition(QTextCursor::End); cursor.insertText("\n"); executeCommand(text); } } if (insertText) { QTextCursor cursor = textCursor(); cursor.insertText(text, currentCharFormat()); } } }
void SparqlTextEdit::paintEvent(QPaintEvent *e) { setTabStopWidth(4 * QFontMetrics(currentCharFormat().font()).width(' ')); QPlainTextEdit::paintEvent(e); }
bool CompletableTextEdit::complete(QAbstractItemModel* _model, const QString& _completionPrefix) { bool success = false; if (m_useCompleter && canComplete()) { if (_model != 0) { // // Настроим завершателя, если необходимо // bool settedNewModel = m_completer->model() != _model; bool oldModelWasChanged = false; if (!settedNewModel && _model != 0) { oldModelWasChanged = m_completer->model()->rowCount() == _model->rowCount(); } if (settedNewModel || oldModelWasChanged) { m_completer->setModel(_model); m_completer->setModelSorting(QCompleter::UnsortedModel); m_completer->setCaseSensitivity(Qt::CaseInsensitive); } m_completer->setCompletionPrefix(_completionPrefix); // // Если в модели для дополнения есть элементы // bool hasCompletions = m_completer->completionModel()->rowCount() > 0; bool alreadyComplete = _completionPrefix.toLower().endsWith(m_completer->currentCompletion().toLower()); if (hasCompletions && !alreadyComplete) { m_completer->popup()->setCurrentIndex( m_completer->completionModel()->index(0, 0)); // // ... отобразим завершателя // QRect rect = cursorRect(); rect.moveTo(mapToGlobal(viewport()->mapToParent(rect.topLeft()))); rect.moveLeft(rect.left() + verticalScrollBar()->width()); rect.moveTop(rect.top() + QFontMetricsF(currentCharFormat().font()).height()); rect.setWidth( m_completer->popup()->sizeHintForColumn(0) + m_completer->popup()->verticalScrollBar()->sizeHint().width()); MyCompleter* myCompleter = static_cast<MyCompleter*>(m_completer); myCompleter->completeReimpl(rect); success = true; } } if (!success) { // // ... скроем, если был отображён // closeCompleter(); } } return success; }
KNoteEdit::KNoteEdit( KActionCollection *actions, QWidget *parent ) : KTextEdit( parent ), m_note( 0 ) { setAcceptDrops( true ); setWordWrapMode( QTextOption::WordWrap ); setLineWrapMode( WidgetWidth ); if ( acceptRichText() ) { setAutoFormatting( AutoAll ); } else { setAutoFormatting( AutoNone ); } setCheckSpellingEnabled( true ); // create the actions modifying the text format m_textBold = new KToggleAction( KIcon( "format-text-bold" ), i18n( "Bold" ), this ); actions->addAction( "format_bold", m_textBold ); m_textBold->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_B ) ); m_textItalic = new KToggleAction( KIcon( "format-text-italic" ), i18n( "Italic" ), this ); actions->addAction( "format_italic", m_textItalic ); m_textItalic->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_I ) ); m_textUnderline = new KToggleAction( KIcon( "format-text-underline" ), i18n( "Underline" ), this ); actions->addAction( "format_underline", m_textUnderline ); m_textUnderline->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_U ) ); m_textStrikeOut = new KToggleAction( KIcon( "format-text-strikethrough" ), i18n( "Strike Out" ), this ); actions->addAction( "format_strikeout", m_textStrikeOut ); m_textStrikeOut->setShortcut( QKeySequence( Qt::CTRL + Qt::Key_S ) ); connect( m_textBold, SIGNAL(toggled(bool)), SLOT(textBold(bool)) ); connect( m_textItalic, SIGNAL(toggled(bool)), SLOT(setFontItalic(bool)) ); connect( m_textUnderline, SIGNAL(toggled(bool)), SLOT(setFontUnderline(bool)) ); connect( m_textStrikeOut, SIGNAL(toggled(bool)), SLOT(textStrikeOut(bool)) ); m_textAlignLeft = new KToggleAction( KIcon( "format-justify-left" ), i18n( "Align Left" ), this ); actions->addAction( "format_alignleft", m_textAlignLeft ); connect( m_textAlignLeft, SIGNAL(triggered(bool)), SLOT(textAlignLeft()) ); m_textAlignLeft->setShortcut( QKeySequence( Qt::ALT + Qt::Key_L ) ); m_textAlignLeft->setChecked( true ); // just a dummy, will be updated later m_textAlignCenter = new KToggleAction( KIcon( "format-justify-center" ), i18n( "Align Center" ), this ); actions->addAction( "format_aligncenter", m_textAlignCenter ); connect( m_textAlignCenter, SIGNAL(triggered(bool)), SLOT(textAlignCenter()) ); m_textAlignCenter->setShortcut( QKeySequence( Qt::ALT + Qt::Key_C ) ); m_textAlignRight = new KToggleAction( KIcon( "format-justify-right" ), i18n( "Align Right" ), this ); actions->addAction( "format_alignright", m_textAlignRight ); connect( m_textAlignRight, SIGNAL(triggered(bool)), SLOT(textAlignRight()) ); m_textAlignRight->setShortcut( QKeySequence( Qt::ALT + Qt::Key_R ) ); m_textAlignBlock = new KToggleAction( KIcon( "format-justify-fill" ), i18n( "Align Block" ), this ); actions->addAction( "format_alignblock", m_textAlignBlock ); connect( m_textAlignBlock, SIGNAL(triggered(bool)), SLOT(textAlignBlock()) ); m_textAlignBlock->setShortcut( QKeySequence( Qt::ALT + Qt::Key_B ) ); QActionGroup *group = new QActionGroup( this ); group->addAction( m_textAlignLeft ); group->addAction( m_textAlignCenter ); group->addAction( m_textAlignRight ); group->addAction( m_textAlignBlock ); m_textList = new KToggleAction( KIcon( "format-list-ordered" ), i18n( "List" ), this ); actions->addAction( "format_list", m_textList ); connect( m_textList, SIGNAL(triggered(bool)), SLOT(textList()) ); m_textSuper = new KToggleAction( KIcon( "format-text-superscript" ), i18n( "Superscript" ), this ); actions->addAction( "format_super", m_textSuper ); connect( m_textSuper, SIGNAL(triggered(bool)), SLOT(textSuperScript()) ); m_textSub = new KToggleAction( KIcon( "format-text-subscript" ), i18n( "Subscript" ), this ); actions->addAction( "format_sub", m_textSub ); connect( m_textSub, SIGNAL(triggered(bool)), SLOT(textSubScript()) ); m_textIncreaseIndent = new KAction( KIcon( "format-indent-more" ), i18n( "Increase Indent" ), this ); actions->addAction( "format_increaseindent", m_textIncreaseIndent ); m_textIncreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_I ) ); connect( m_textIncreaseIndent, SIGNAL(triggered(bool)), SLOT(textIncreaseIndent()) ); m_textDecreaseIndent = new KAction( KIcon( "format-indent-less" ), i18n( "Decrease Indent" ), this ); actions->addAction( "format_decreaseindent", m_textDecreaseIndent ); m_textDecreaseIndent->setShortcut( QKeySequence( Qt::CTRL + Qt::ALT + Qt::Key_D ) ); connect( m_textDecreaseIndent, SIGNAL(triggered(bool)), SLOT( textDecreaseIndent() ) ); group = new QActionGroup( this ); group->addAction( m_textIncreaseIndent ); group->addAction( m_textDecreaseIndent ); QPixmap pix( ICON_SIZE, ICON_SIZE ); pix.fill( Qt::black ); // just a dummy, gets updated before widget is shown m_textColor = new KAction( i18n( "Text Color..." ), this ); actions->addAction( "format_color", m_textColor ); m_textColor->setIcon( pix ); connect( m_textColor, SIGNAL(triggered(bool)), SLOT(slotTextColor()) ); KAction *act = new KAction(KIcon( "format-fill-color" ), i18n( "Text Background Color..." ), this ); actions->addAction( "text_background_color", act ); connect( act, SIGNAL(triggered(bool)), SLOT(slotTextBackgroundColor()) ); m_textFont = new KFontAction( i18n( "Text Font" ), this ); actions->addAction( "format_font", m_textFont ); connect( m_textFont, SIGNAL(triggered(QString)), this, SLOT(setFontFamily(QString)) ); m_textSize = new KFontSizeAction( i18n( "Text Size" ), this ); actions->addAction( "format_size", m_textSize ); connect( m_textSize, SIGNAL(fontSizeChanged(int)), this, SLOT(setTextFontSize(int)) ); // QTextEdit connections connect( this, SIGNAL(currentCharFormatChanged(QTextCharFormat)), SLOT(slotCurrentCharFormatChanged(QTextCharFormat)) ); connect( this, SIGNAL(cursorPositionChanged()), SLOT(slotCursorPositionChanged()) ); slotCurrentCharFormatChanged( currentCharFormat() ); slotCursorPositionChanged(); }
void HaiQTextEdit::process_key(QKeyEvent event) { if ((event.text()!="")&&(textCursor().selectedText().count()<=1)) { ///this is to avoid spreading of marker highlighting bool holdmodified=document()->isModified(); QTextCharFormat format=currentCharFormat(); format.clearBackground(); setCurrentCharFormat(format); document()->setModified(holdmodified); } if ((event.key()==Qt::Key_Tab)||(event.key()==Qt::Key_Backtab)||(event.text()=="\t")) { process_tab(event); } else if (event.key()==Qt::Key_Insert && QApplication::keyboardModifiers() == Qt::NoModifier) { setOverwriteMode(!overwriteMode()); } else if ((event.key()==Qt::Key_Home)&&((event.modifiers()==Qt::NoModifier)||(event.modifiers()==Qt::ShiftModifier))) { bool shift_key=(event.modifiers()==Qt::ShiftModifier); QTextCursor cursor=textCursor(); int col=cursor.columnNumber(); QString txt=cursor.block().text(); if (shift_key) cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::StartOfLine); int ct=0; while ((ct<txt.count())&&((txt[ct]==' ')||(txt[ct]=='\t'))) { if (shift_key) cursor.movePosition(QTextCursor::Right,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::Right); ct++; } int col2=cursor.columnNumber(); if (col2==col) { //moved nowhere if (shift_key) cursor.movePosition(QTextCursor::StartOfLine,QTextCursor::KeepAnchor); else cursor.movePosition(QTextCursor::StartOfLine); } setTextCursor(cursor); } else if (event.key()==Qt::Key_Backspace) { process_backspace(); return; } else if ((event.key()==Qt::Key_Space)&&(event.modifiers()==Qt::ControlModifier)) { return; // don't process a space, because Ctrl+Space is for completion } else { QTextEdit::keyPressEvent(&event); } if ((event.key()==Qt::Key_Enter)||(event.key()==Qt::Key_Return)) { indent_to_previous_line(); QTextCursor cursor=textCursor(); do_marker_highlighting(cursor); QString line=cursor.block().previous().text(); QStringList symbols=split_into_symbols(line); if ((symbols.count()>0)&& ( (symbols[symbols.count()-1]=="{") || (((symbols[symbols.count()-1]!=";"))&&((symbols[0]=="if") || (symbols[0]=="else") || (symbols[0]=="while") || (symbols[0]=="do") || (symbols[0]=="for"))) ) ) { QString line2=cursor.block().text(); QStringList symbols2=split_into_symbols(line2); if ((symbols2.count()==0)||(symbols2[0]!="}")) //only indent if there is not a "{" starting the line cursor.insertText(tab_text(cursor)); } //kind of a hack if (!blocks_highlighted_for_braces.isEmpty()) { blocks_highlighted_for_braces << textCursor().block(); } } if (event.text()=="}") { QTextCursor cursor=textCursor(); QString line=cursor.block().text(); QStringList symbols=split_into_symbols(line); if (symbols.count()==1) { //unindent to last brace QTextBlock block=cursor.block(); bool found=false; int braces_level=1; while ((!found)&&(block.isValid())) { block=block.previous(); QString line2=block.text(); QStringList symbols=split_into_symbols(line2); for (int j=symbols.count()-1; j>=0; j--) { if (symbols[j]=="{") braces_level--; if (symbols[j]=="}") braces_level++; if (braces_level==0) found=true; } } if (found) { QString line2=block.text(); for (int j=0; j<line.count(); j++) cursor.deletePreviousChar(); int j=0; while ((j<line2.count())&&((line2[j]==' ')||(line2[j]=='\t'))) { cursor.insertText(QString(line2[j])); j++; } cursor.insertText("}"); } } } if ((event.text()==")")||(event.text()=="}")/*||(event.text()==">")*/) { highlight_braces(event.text(),true); } if ((event.text()=="(")||(event.text()=="{")/*||(event.text()=="<")*/) { highlight_braces(event.text(),false); } }