Ejemplo n.º 1
0
void highlighterClass::enableSpellChecking(const bool state)
{
    bool old = spellCheckActive;

    if(spellerError == false)
    {
        spellCheckActive = state;
    }

    if(old != spellCheckActive)
    {
        rehighlight();
    }
}
Ejemplo n.º 2
0
void Highlighter::onPrefsChanged( const QString &name ){
    QString t(name);
    if( t=="" || t.endsWith( "Color" ) ){
        Prefs *prefs=Prefs::prefs();
        _backgroundColor=prefs->getColor( "backgroundColor" );
        _defaultColor=prefs->getColor("defaultColor");
        _numbersColor=prefs->getColor("numbersColor");
        _stringsColor=prefs->getColor("stringsColor");
        _identifiersColor=prefs->getColor("identifiersColor");
        _keywordsColor=prefs->getColor("keywordsColor");
        _commentsColor=prefs->getColor("commentsColor");
        _highlightColor=prefs->getColor("highlightColor");
        rehighlight();
    }
}
void SkinHighlighter::loadSettings()
{
    QSettings settings;

    settings.beginGroup("SkinHighlighter");

    /* Loading the highlighting colors */
    tag = settings.value("tagColor", QColor(180,0,0)).value<QColor>();
    conditional = settings.value("conditionalColor",
                                 QColor(0, 0, 180)).value<QColor>();
    escaped = settings.value("escapedColor",
                             QColor(120,120,120)).value<QColor>();
    comment = settings.value("commentColor",
                             QColor(0, 180, 0)).value<QColor>();

    settings.endGroup();

    rehighlight();
}
Ejemplo n.º 4
0
bool highlighterClass::setDic(const QString newSpellDic)
{
    spellerError = false;
    spellDic = newSpellDic;

    if(spellChecker != nullptr)
    {
        delete spellChecker;
    }

    QFileInfo fileInfoForDic(QCoreApplication::applicationDirPath() + "/resources/" + spellDic + ".dic");
    if(fileInfoForDic.exists() == false || fileInfoForDic.isReadable() == false)
    {
        spellChecker = nullptr;
        spellCheckActive = false;
        spellerError = true;
        codec = QTextCodec::codecForName("UTF-8");
    }
    else
    {
        QFileInfo fileInfoForUserDic(QCoreApplication::applicationDirPath() + "/user_" + spellDic + ".dic");
        spellChecker = new Hunspell((QCoreApplication::applicationDirPath() + "/resources/" + spellDic.toLatin1() + ".aff").toStdString().c_str(),
                                    (QCoreApplication::applicationDirPath() + "/resources/" + spellDic.toLatin1() + ".dic").toStdString().c_str());

        if(fileInfoForUserDic.exists() == true && fileInfoForUserDic.isReadable() == true)
        {
            spellChecker->add_dic(fileInfoForUserDic.filePath().toLatin1());
        }
        codec = QTextCodec::codecForName(QString(spellChecker->get_dic_encoding()).toLatin1());
    }

    rehighlight();

    if(spellChecker == nullptr)
    {
        return false;
    }
    else
    {
        return true;
    }
}
Ejemplo n.º 5
0
void Highlighter::slotRehighlight()
{
    if (d->completeRehighlightRequired) {
        d->wordCount  = 0;
        d->errorCount = 0;
        rehighlight();

    } else {
        //rehighlight the current para only (undo/redo safe)
        QTextCursor cursor;
        if (d->textEdit)
            cursor = d->textEdit->textCursor();
        else
            cursor = d->plainTextEdit->textCursor();
        cursor.insertText(QString());
    }
    //if (d->checksDone == d->checksRequested)
    //d->completeRehighlightRequired = false;
    QTimer::singleShot(0, this, SLOT(slotAutoDetection()));
}
QT_BEGIN_NAMESPACE

MessageHighlighter::MessageHighlighter(QTextEdit *textEdit)
    : QSyntaxHighlighter(textEdit)
{
    QTextCharFormat entityFormat;
    entityFormat.setForeground(Qt::red);
    m_formats[Entity] = entityFormat;

    QTextCharFormat tagFormat;
    tagFormat.setForeground(Qt::darkMagenta);
    m_formats[Tag] = tagFormat;

    QTextCharFormat commentFormat;
    commentFormat.setForeground(Qt::gray);
    commentFormat.setFontItalic(true);
    m_formats[Comment] = commentFormat;

    QTextCharFormat attributeFormat;
    attributeFormat.setForeground(Qt::black);
    attributeFormat.setFontItalic(true);
    m_formats[Attribute] = attributeFormat;

    QTextCharFormat valueFormat;
    valueFormat.setForeground(Qt::blue);
    m_formats[Value] = valueFormat;

    QTextCharFormat acceleratorFormat;
    acceleratorFormat.setFontUnderline(true);
    m_formats[Accelerator] = acceleratorFormat;

    QTextCharFormat variableFormat;
    variableFormat.setForeground(Qt::blue);
    m_formats[Variable] = variableFormat;

    rehighlight();
}
Ejemplo n.º 7
0
bool Highlighter::setDict(const QString SpellDic)
{
	bool spell;
	if(SpellDic!=""){
		//mWords.clear();
		spell_dic=SpellDic.left(SpellDic.length()-4);
		delete pChecker;
		pChecker = new Hunspell(spell_dic.toLatin1()+".aff",spell_dic.toLatin1()+".dic");
		spell_encoding=QString(pChecker->get_dic_encoding());
		codec = QTextCodec::codecForName(spell_encoding.toLatin1());

		QFileInfo fi(SpellDic);

		if (fi.exists() && fi.isReadable()) spell=true;
		else spell=false;

		// get user config dictionary
		QSettings setting;
		QString filePath=QFileInfo(setting.fileName()).absoluteFilePath();
		filePath=filePath+"/User_"+QFileInfo(spell_dic.toLatin1()+".dic").fileName();
		/*std::cout << qPrintable(filePath) << std::endl;*/
		fi=QFileInfo(filePath);
		if (fi.exists() && fi.isReadable()){
			pChecker->add_dic(filePath.toLatin1());
		}
		else filePath="";

		spellCheckFormat.setForeground(Qt::red);//faster Cursoroperation ...
		//spellCheckFormat.setUnderlineColor(QColor(Qt::red));
		//spellCheckFormat.setUnderlineStyle(QTextCharFormat::SpellCheckUnderline);
	}
	else spell=false;
	spellerError=!spell;
	spellCheckActive=spellCheckActive && spell;
	rehighlight();
	return spell;
}
Ejemplo n.º 8
0
void QCodeJSHighlighter::setColor(ColorComponent component, const QColor &color){

    m_colors[component] = color;
    rehighlight();
}
Ejemplo n.º 9
0
void highlighterClass::styleChanged()
{
    spellCheckFormat.setUnderlineColor(QColor(styleToolClass::getColorInfo().underlineColor));
    rehighlight();
}
Ejemplo n.º 10
0
void Highlighter::update()
{
    rehighlight();
}
void SpellCheckHighlighter::setSpellChecker(SpellChecker* _checker)
{
	m_spellChecker = _checker;
	rehighlight();
}
Ejemplo n.º 12
0
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()));
}
Ejemplo n.º 13
0
// ====================================================
//  SET FILE FORMAT
// ====================================================
void Highlighter::setFileFormat(const QString& format)
{
  mHighlightingRules = config::ConfigFile::instance()->getHighlightsByFormat(format);
  rehighlight();
} // setFormat
Ejemplo n.º 14
0
	void HtmlHighlighter::SetFormatFor (Construct c, const QTextCharFormat& f)
	{
		Formats_ [c] = f;
		rehighlight ();
	}
Ejemplo n.º 15
0
void JSHighlighter::mark(const QString &str, Qt::CaseSensitivity caseSensitivity)
{
    m_markString = str;
    m_markCaseSensitivity = caseSensitivity;
    rehighlight();
}
Ejemplo n.º 16
0
void HtmlHighlighter::setFormatFor(Construct construct,
                                   const QTextCharFormat &format)
{
    m_formats[construct] = format;
    rehighlight();
}
Ejemplo n.º 17
0
void EquationHighlighter::setVariables(const QStringList& variables) {
	m_variables = variables;
	rehighlight();
}
Ejemplo n.º 18
0
void Highlighter::setMisspelledColor(const QColor& color)
{
	m_misspelled = color;
	rehighlight();
}
Ejemplo n.º 19
0
void Highlighter::setEnabled(bool enabled)
{
	m_enabled = enabled;
	rehighlight();
}
Ejemplo n.º 20
0
void FontLock::addPattern(const Pattern & p) {
    m_lines << p;

    rehighlight();
}
Ejemplo n.º 21
0
void SyntaxHighlighter::validateTextModification(int, int removed, int added)
{
	if(getMultiLineInfoCount(current_block)!=curr_blk_info_count ||
		 added > 0 || removed > 0)
		rehighlight();
}
Ejemplo n.º 22
0
void FontLock::addMultiLinePattern(const BlockPattern & p) {
    m_blocks << p;

    rehighlight();
}
Ejemplo n.º 23
0
void SpellHighlighter::restore()
{
    m_bDisable = false;
    rehighlight();
}
Ejemplo n.º 24
0
void Highlighter::enableSpellChecking(const bool state)
{
	bool old=spellCheckActive;
	if(!spellerError) spellCheckActive=state;
	if(old!=spellCheckActive) rehighlight();
}
Ejemplo n.º 25
0
/*!
 * Slot to receive any changes to the current expression
 *
 * \param   exp The new expression string
 */
void BlockHighlighter::updateExpression(QString exp)
{
    _pattern = exp;
    rehighlight();
}
Ejemplo n.º 26
0
void JSHighlighter::setColor(JSEdit::ColorComponent component, const QColor &color)
{
    m_colors[component] = color;
    rehighlight();
}
Ejemplo n.º 27
0
void SpellHighlighter::slotConfigChanged()
{
    m_bDirty = true;
    rehighlight();
}
Ejemplo n.º 28
0
void JSHighlighter::setKeywords(const QStringList &keywords)
{
    m_keywords = QSet<QString>::fromList(keywords);
    rehighlight();
}
Ejemplo n.º 29
0
void *SpellHighlighter::processEvent(Event *e)
{
    if (e->type() == EventCheckState){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == m_plugin->CmdSpell){
            MsgEdit *m_edit = (MsgEdit*)(cmd->param);
            if (m_edit->m_edit != textEdit())
                return NULL;
            m_index = textEdit()->charAt(static_cast<TextEdit*>(textEdit())->m_popupPos, &m_parag);
            m_pos = 0;
            m_bError   = false;
            m_bInError = false;
            while (!m_fonts.empty())
                m_fonts.pop();
            m_bCheck = true;
            parse(textEdit()->text(m_paragraph));
            m_bCheck = false;
            if (!m_bInError)
                return NULL;
            m_sug = m_plugin->suggestions(m_word);
            CommandDef *cmds = new CommandDef[m_sug.count() + 3];
            memset(cmds, 0, sizeof(CommandDef) * (m_sug.count() + 3));
            unsigned i = 0;
            for (QStringList::Iterator it = m_sug.begin(); it != m_sug.end(); ++it, i++){
                cmds[i].id   = m_plugin->CmdSpell + i + 2;
                cmds[i].text = "_";
                cmds[i].text_wrk = strdup((*it).utf8());
                if (i >= 10){
                    i++;
                    break;
                }
            }
            cmds[i].id   = m_plugin->CmdSpell;
            cmds[i].text = "_";
            cmds[i].text_wrk = strdup(i18n("Add '%1'") .arg(m_word) .utf8());
            i++;
            cmds[i].id   = m_plugin->CmdSpell + 1;
            cmds[i].text = "_";
            cmds[i].text_wrk = strdup(i18n("Ignore '%1'") .arg(m_word) .utf8());

            cmd->param  = cmds;
            cmd->flags |= COMMAND_RECURSIVE;
            return cmd;
        }
    }
    if (e->type() == EventCommandExec){
        CommandDef *cmd = (CommandDef*)(e->param());
        if (cmd->id == CmdSend){
            if (((MsgEdit*)(cmd->param))->m_edit == textEdit()){
                m_bDisable = true;
                rehighlight();
                QTimer::singleShot(50, this, SLOT(restore()));
            }
        }
        if ((cmd->id >= m_plugin->CmdSpell) && (cmd->id < m_plugin->CmdSpell + m_sug.count() + 1)){
            MsgEdit *m_edit = (MsgEdit*)(cmd->param);
            if (m_edit->m_edit != textEdit())
                return NULL;
            if (cmd->id == m_plugin->CmdSpell){
                m_plugin->add(m_word);
				MAP_BOOL::iterator it = m_words.find(my_string(m_word.utf8()));
                if (it == m_words.end()){
					m_words.insert(MAP_BOOL::value_type(my_string(m_word.utf8()), true));
				}else{
					if ((*it).second)
						return NULL;
					(*it).second = true;
				}
                m_bDirty = true;
                QTimer::singleShot(300, this, SLOT(reformat()));
            }else  if (cmd->id == m_plugin->CmdSpell + 1){
				MAP_BOOL::iterator it = m_plugin->m_ignore.find(my_string(m_word.utf8()));
                if (it == m_plugin->m_ignore.end())
                    m_plugin->m_ignore.insert(MAP_BOOL::value_type(my_string(m_word.utf8()), true));
                it = m_words.find(my_string(m_word.utf8()));
                if (it == m_words.end()){
					m_words.insert(MAP_BOOL::value_type(my_string(m_word.utf8()), true));
				}else{
					if ((*it).second)
						return NULL;
					(*it).second = true;
				}
                m_bDirty = true;
                QTimer::singleShot(300, this, SLOT(reformat()));
            }else{
                unsigned n = cmd->id - m_plugin->CmdSpell - 2;
                QString word = m_sug[n];
                textEdit()->setSelection(m_parag, m_start_word, m_parag, m_start_word + m_word.length());
                textEdit()->insert(word, true, true);
            }
        }
    }
    return NULL;
}