void CodeEditor::highlightCurrentLine() { QList<QTextEdit::ExtraSelection> extraSelections; QTextCursor cursor = textCursor(); if (!isReadOnly()) { QTextEdit::ExtraSelection selection; QColor lineColor = QColor(Qt::yellow).lighter(160); selection.format.setBackground(lineColor); selection.format.setProperty(QTextFormat::FullWidthSelection, true); selection.cursor = cursor; selection.cursor.clearSelection(); extraSelections.append(selection); } setExtraSelections(extraSelections); matchParentheses(cursor); }
ScriptEdit::ScriptEdit(ScriptingEnv *env, QWidget *parent, const char *name) : QTextEdit(parent, name), scripted(env), d_error(false), d_completer(0), d_highlighter(0), d_file_name(QString::null), d_search_string(QString::null), d_output_widget(NULL) { myScript = scriptEnv->newScript("", this, name); connect(myScript, SIGNAL(error(const QString&, const QString&, int)), this, SLOT(insertErrorMsg(const QString&))); connect(myScript, SIGNAL(print(const QString&)), this, SLOT(scriptPrint(const QString&))); connect(myScript, SIGNAL(error(const QString&, const QString&, int)), this, SIGNAL(error(const QString&, const QString&, int))); setLineWrapMode(NoWrap); setUndoRedoEnabled(true); setTextFormat(Qt::PlainText); setAcceptRichText (false); setFocusPolicy(Qt::StrongFocus); rehighlight(); d_fmt_default.setBackground(palette().brush(QPalette::Base)); //Init completer based on parser built-in functions QStringList functions = MyParser::functionNamesList(); functions.sort(); QCompleter *completer = new QCompleter(this); completer->setModelSorting(QCompleter::CaseSensitivelySortedModel); completer->setCompletionMode(QCompleter::PopupCompletion); completer->setModel(new QStringListModel(functions, completer)); setCompleter(completer); printCursor = textCursor(); scriptsDirPath = qApp->applicationDirPath(); actionExecute = new QAction(tr("E&xecute"), this); actionExecute->setShortcut( tr("Ctrl+J") ); connect(actionExecute, SIGNAL(activated()), this, SLOT(execute())); actionExecuteAll = new QAction(QIcon(":/play.png"), tr("Execute &All"), this); actionExecuteAll->setShortcut( tr("Ctrl+Shift+J") ); connect(actionExecuteAll, SIGNAL(activated()), this, SLOT(executeAll())); actionEval = new QAction(tr("&Evaluate Expression"), this); actionEval->setShortcut( tr("Ctrl+Return") ); connect(actionEval, SIGNAL(activated()), this, SLOT(evaluate())); actionPrint = new QAction(QIcon(":/fileprint.png"), tr("&Print"), this); connect(actionPrint, SIGNAL(activated()), this, SLOT(print())); actionImport = new QAction(QIcon(":/fileopen.png"), tr("&Import..."), this); actionImport->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_O)); connect(actionImport, SIGNAL(activated()), this, SLOT(importASCII())); actionSave = new QAction(QIcon(":/filesave.png"), tr("&Save"), this); actionSave->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_S)); connect(actionSave, SIGNAL(activated()), this, SLOT(save())); actionExport = new QAction(QIcon(":/filesaveas.png"), tr("Sa&ve as..."), this); connect(actionExport, SIGNAL(activated()), this, SLOT(exportASCII())); actionFind = new QAction(QIcon(":/find.png"), tr("&Find..."), this); actionFind->setShortcut(QKeySequence(Qt::CTRL+Qt::ALT+Qt::Key_F)); connect(actionFind, SIGNAL(activated()), this, SLOT(showFindDialog())); actionReplace = new QAction(QIcon(":/replace.png"), tr("&Replace..."), this); actionReplace->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_R)); connect(actionReplace, SIGNAL(activated()), this, SLOT(replace())); actionFindNext = new QAction(QIcon(":/find_next.png"), tr("&Find next"), this); actionFindNext->setShortcut(QKeySequence(Qt::Key_F3)); connect(actionFindNext, SIGNAL(activated()), this, SLOT(findNext())); actionFindPrevious = new QAction(QIcon(":/find_previous.png"), tr("&Find previous"), this); actionFindPrevious->setShortcut(QKeySequence(Qt::Key_F4)); connect(actionFindPrevious, SIGNAL(activated()), this, SLOT(findPrevious())); functionsMenu = new QMenu(this); Q_CHECK_PTR(functionsMenu); connect(functionsMenu, SIGNAL(triggered(QAction *)), this, SLOT(insertFunction(QAction *))); connect(this, SIGNAL(cursorPositionChanged()), this, SLOT(matchParentheses())); }