Esempio n. 1
0
 void QHTMLSourceEditorCodeEditor::highlightCurrentLine()
 {
     QList<QTextEdit::ExtraSelection> extraSelections;

     if (!isReadOnly()) {
         QTextEdit::ExtraSelection selection;

         QColor lineColor = QColor(Qt::yellow).lighter(160);

         selection.format.setBackground(lineColor);
         selection.format.setProperty(QTextFormat::FullWidthSelection, true);
         selection.cursor = textCursor();
         selection.cursor.clearSelection();
         extraSelections.append(selection);
     }

     setExtraSelections(extraSelections);
 }
Esempio n. 2
0
void CodeEditor::createParenthesisSelection(int pos)
{
    QList<QTextEdit::ExtraSelection> selections = extraSelections();

    QTextEdit::ExtraSelection selection;
    QTextCharFormat format = selection.format;
    format.setBackground(Qt::green);
    selection.format = format;

    QTextCursor cursor = textCursor();
    cursor.setPosition(pos);
    cursor.movePosition(QTextCursor::NextCharacter, QTextCursor::KeepAnchor);
    selection.cursor = cursor;

    selections.append(selection);

    setExtraSelections(selections);
}
Esempio n. 3
0
void TextEditor::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    if (!isReadOnly()) {
        QTextEdit::ExtraSelection selection;

        QColor lineColor = QColor(Qt::darkGray).darker(300);

        selection.format.setBackground(lineColor);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        extraSelections.append(selection);
    }

    setExtraSelections(extraSelections);
}
Esempio n. 4
0
void DataWidget::highlightCurrentLine() {
    if (moveable) {
        if (!highlights.isEmpty()) {
            highlights.removeLast();
        }
        addHighlight(QColor(Qt::yellow).lighter(160));
        setExtraSelections(highlights);
        if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier)) {
            bool ok = true;

            QTextCursor cursor = textCursor();
            cursor.select(QTextCursor::WordUnderCursor);
            if (cursor.selectedText().isEmpty()) {
                return;
            }

            QString weird(QStringLiteral("[]()\",./\\-="));

            if (weird.contains(cursor.selectedText().at(0))) {
                cursor.movePosition(QTextCursor::WordLeft);
                cursor.movePosition(QTextCursor::WordLeft);
                cursor.select(QTextCursor::WordUnderCursor);
            }
            setTextCursor(cursor);

            QString equ = getAddressOfEquate(cursor.selectedText().toUpper().toStdString());
            uint32_t address;

            if (!equ.isEmpty()) {
                address = hex2int(equ);
            } else {
                address = textCursor().selectedText().toUInt(&ok, 16);
            }

            if (ok) {
                if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier)) {
                    emit gotoMemoryAddress(address);
                } else {
                    emit gotoDisasmAddress(address);
                }
            }
        }
    }
}
Esempio n. 5
0
void GlslTextEdit::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    if(!isReadOnly() && isEnabled()) 
    {
        QTextEdit::ExtraSelection selection;

        selection.format.setBackground(QColor("#f8f8f8"));

        selection.format.setProperty(QTextFormat::FullWidthSelection, true);

        selection.cursor = textCursor();
        selection.cursor.clearSelection();

        extraSelections.append(selection);
    }
    setExtraSelections(extraSelections);
}
Esempio n. 6
0
void SourceViewerWidget::updateSelection()
{
	QList<QTextEdit::ExtraSelection> extraSelections;

	if (!m_findText.isEmpty())
	{
		QTextEdit::ExtraSelection selection;
		selection.format.setBackground(QColor(255, 150, 50));
		selection.format.setProperty(QTextFormat::FullWidthSelection, true);
		selection.cursor = m_findTextSelection;

		extraSelections.append(selection);

		QTextCursor textCursor(this->textCursor());
		textCursor.setPosition(0);

		if (m_findFlags.testFlag(WebWidget::HighlightAllFind))
		{
			QTextDocument::FindFlags nativeFlags;

			if (m_findFlags.testFlag(WebWidget::CaseSensitiveFind))
			{
				nativeFlags |= QTextDocument::FindCaseSensitively;
			}

			while (!textCursor.isNull())
			{
				textCursor = document()->find(m_findText, textCursor, nativeFlags);

				if (!textCursor.isNull() && textCursor != m_findTextSelection)
				{
					QTextEdit::ExtraSelection selection;
					selection.format.setBackground(QColor(255, 255, 0));
					selection.cursor = textCursor;

					extraSelections.append(selection);
				}
			}
		}
	}

	setExtraSelections(extraSelections);
}
Esempio n. 7
0
void CCodeEditor::HighlightWrongLine(const int lineNumber)
{
	QTextBlock wrongBlock = this->document()->findBlockByLineNumber(lineNumber);
	QTextCursor wrongCursor(wrongBlock);

	m_extraSelections.clear();
	if (!isReadOnly())
	{
		m_wrongSelection.format.setBackground(COLOR_WRONG);
		m_wrongSelection.format.setProperty(QTextFormat::FullWidthSelection, true);
		m_wrongSelection.cursor = wrongCursor;
		m_wrongSelection.cursor.clearSelection();

		m_extraSelections.append(m_selectSelection);
		m_extraSelections.append(m_pcSelection);
		m_extraSelections.append(m_wrongSelection);
	}
	setExtraSelections(m_extraSelections);
}
Esempio n. 8
0
void SparqlTextEdit::highlightLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    if (!isReadOnly() && textCursor().selection().isEmpty()) {
        QTextEdit::ExtraSelection selection;

        QColor lineColor = palette().color(QPalette::Highlight);
        lineColor.setAlphaF(0.25);

        selection.format.setBackground(lineColor);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        extraSelections.append(selection);
    }

    setExtraSelections(extraSelections);
}
Esempio n. 9
0
/*!
 *  Highlight background of the current line.
 */
void TextEdit::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    if (!isReadOnly()) {
        QTextEdit::ExtraSelection selection;
        QPalette a;

        selection.format.setBackground(a.brush(QPalette::Window));
        //selection.format.setProperty(QTextFormat::BlockNonBreakableLines, false);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        selection.cursor.movePosition(QTextCursor::StartOfBlock, QTextCursor::MoveAnchor);
        selection.cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor);
        extraSelections.append(selection);
    }

    setExtraSelections(extraSelections);
}
Esempio n. 10
0
void CodeView::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    QTextEdit::ExtraSelection selection;
    QTextCursor cursor = textCursor();

    QString text = cursor.selectedText();

    QString string = cursor.block().text();

    QColor lineColor = QApplication::palette().highlight().color();

    selection.format.setBackground(lineColor);
    selection.format.setProperty(QTextFormat::FullWidthSelection, true);
    selection.cursor = cursor;
    selection.cursor.clearSelection();
    extraSelections.append(selection);

    setExtraSelections(extraSelections);
}
Esempio n. 11
0
void CodeEditor::highlightCurrentLine()
{
    QList<QTextEdit::ExtraSelection> extraSelections;
    if (!isReadOnly()) {
        QTextEdit::ExtraSelection selection;

        QColor lineColor = QColor(Qt::blue).lighter(190);

        selection.format.setBackground(lineColor);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        if (errorLines.indexOf(selection.cursor.blockNumber()+1)!=-1) {
            QToolTip::showText(QCursor::pos(),errorMsgs.at(errorLines.indexOf(selection.cursor.blockNumber()+1)));
        } else {
            QToolTip::hideText();
        }
        extraSelections.append(selection);
    }
    setExtraSelections(extraSelections);
}
Esempio n. 12
0
void CodeEditor::highlightErrors(const QList<int> &errorLines)
{
    QList<QTextEdit::ExtraSelection> extraSelections;

    for (int i = 0; i < errorLines.size(); ++i)
    {
        QTextEdit::ExtraSelection selection;

        QColor lineColor = QColor(Qt::red).lighter(160);

        selection.format.setBackground(lineColor);
        selection.format.setProperty(QTextFormat::FullWidthSelection, true);
        selection.cursor = textCursor();
        selection.cursor.clearSelection();
        selection.cursor.movePosition(QTextCursor::Start);
        selection.cursor.movePosition(QTextCursor::Down, QTextCursor::MoveAnchor, errorLines[i] - 1);
        extraSelections.append(selection);
    }

    setExtraSelections(extraSelections);

}
Esempio n. 13
0
void CodeEditor::highlightDebugLine(int lineNumber)
{
    if (debugMode) {
        QList<QTextEdit::ExtraSelection> extraSelections;

        if (!isReadOnly() && lineNumber > 0) {
            QTextEdit::ExtraSelection selection;

            QColor lineColor = settings.value("debuglinecolor", QColor(235, 200, 40)).value<QColor>();

            selection.format.setBackground(lineColor);
            selection.format.setProperty(QTextFormat::FullWidthSelection, true);
            selection.cursor = QTextCursor(document());
            selection.cursor.movePosition(QTextCursor::NextBlock, QTextCursor::MoveAnchor, lineNumber - 1);
            selection.cursor.clearSelection();
            setTextCursor(selection.cursor); //scroll to debugging line
            extraSelections.append(selection);
        }

        setExtraSelections(extraSelections);
    }
}
Esempio n. 14
0
void CodeEdit::onCursorPositionChanged()
{
  QTextCursor cursor = textCursor();

  if (cursor.position() < 0 || cursor.position() >= toPlainText().length())
  {
    return;
  }

  if (toPlainText().at(cursor.position()) == '(')
  {
    int index = indexOfMatchingClosingParenthesis(toPlainText(), cursor.position());
    if (index == -1)
    {
      highlightIndices(QList<int>() << cursor.position(), HighlightingType::MismachtingParenthesis);
    }
    else
    {
      highlightIndices(QList<int>() << cursor.position() << index, HighlightingType::MachtingParenthesis);
    }
  }
  else if (toPlainText().at(cursor.position()) == ')')
  {
    int index = indexOfMatchingOpeningParenthesis(toPlainText(), cursor.position());
    if (index == -1)
    {
      highlightIndices(QList<int>() << cursor.position(), HighlightingType::MismachtingParenthesis);
    }
    else
    {
      highlightIndices(QList<int>() << cursor.position() << index, HighlightingType::MachtingParenthesis);
    }
  }
  else
  {
    setExtraSelections(QList<QTextEdit::ExtraSelection>());
  }
}
Esempio n. 15
0
void CodeEditor::highlightLine( int line ){

    flushExtraSels();

    QTextBlock block=document()->findBlockByLineNumber( line );

    if( block.isValid() ){

        QTextEdit::ExtraSelection selection;

        QColor lineColor=Prefs::prefs()->getColor( "highlightColor" );

        selection.format.setBackground( lineColor );
        selection.format.setProperty( QTextFormat::FullWidthSelection,true );

        selection.cursor=QTextCursor( block );
        selection.cursor.clearSelection();

        extraSels.append( selection );
    }

    setExtraSelections( extraSels );
    extraSelsEditor=this;
}
Esempio n. 16
0
//Focus out
void TextEdit::focusOutEvent(QFocusEvent*)
{
	setExtraSelections(QList<QTextEdit::ExtraSelection>()); //Clearing
}
Esempio n. 17
0
void TikzEditor::matchBrackets()
{
	// clear previous bracket highlighting
	QList<QTextEdit::ExtraSelection> extraSelections;
	if (!isReadOnly())
	{
		QTextEdit::ExtraSelection selection;
		selection.cursor = textCursor();
		selection.cursor.clearSelection();
		extraSelections.append(selection);
	}
	setExtraSelections(extraSelections);

	// find current matching brackets
	m_matchingBegin = -1;
	m_matchingEnd = -1;
	if (!m_showMatchingBrackets) return;

	m_plainText = toPlainText();
// 	QString matchText = simplifiedText(plainText);
	const QString matchText = m_plainText;
	const QTextCursor cursor = textCursor();
	int pos = cursor.position();
	if (pos == -1)
		return;
	else if (cursor.atEnd() || !QString("({[]})").contains(m_plainText.at(pos))) // if the cursor is not next to a bracket, then there is nothing to match, so return
	{
		if (pos <= 0 || !QString("({[]})").contains(m_plainText.at(--pos)))
			return;
	}

	// get corresponding opening/closing bracket and search direction
	QChar car = (!cursor.atEnd()) ? matchText.at(pos) : matchText.at(pos - 1);
	QChar matchCar;
	long inc = 1;
	if (car == '(') matchCar = ')';
	else if (car == '{') matchCar = '}';
	else if (car == '[') matchCar = ']';
	else
	{
		inc = -1;
		if (car == ')') matchCar = '(';
		else if (car == '}') matchCar = '{';
		else if (car == ']') matchCar = '[';
		else
			return;
	}

	// find location of the corresponding bracket
	m_matchingBegin = pos;
	int numOfMatchCharsToSkip = 0;
	do
	{
		if (matchText.at(pos) == car)
			numOfMatchCharsToSkip++;
		else if (matchText.at(pos) == matchCar)
		{
			numOfMatchCharsToSkip--;
			if (numOfMatchCharsToSkip == 0)
			{
				m_matchingEnd = pos;
				break;
			}
		}
		pos += inc;
	}
	while (pos >= 0 && pos < matchText.length());

	if (m_matchingBegin > m_matchingEnd)
		qSwap(m_matchingBegin, m_matchingEnd);

	// if there is a match, then show it
	if (m_matchingBegin != -1)
		showMatchingBrackets();
}
Esempio n. 18
0
void JSEdit::updateCursor()
{
    Q_D(JSEdit);

    if (isReadOnly()) {
        setExtraSelections(QList<QTextEdit::ExtraSelection>());
    } else {

        d->matchPositions.clear();
        d->errorPositions.clear();

        if (d->bracketsMatching && textCursor().block().userData()) {
            QTextCursor cursor = textCursor();
            int cursorPosition = cursor.position();

            if (document()->characterAt(cursorPosition) == '{') {
                int matchPos = findClosingMatch(document(), cursorPosition);
                if (matchPos < 0) {
                    d->errorPositions += cursorPosition;
                } else {
                    d->matchPositions += cursorPosition;
                    d->matchPositions += matchPos;
                }
            }

            if (document()->characterAt(cursorPosition - 1) == '}') {
                int matchPos = findOpeningMatch(document(), cursorPosition);
                if (matchPos < 0) {
                    d->errorPositions += cursorPosition - 1;
                } else {
                    d->matchPositions += cursorPosition - 1;
                    d->matchPositions += matchPos;
                }
            }
        }

        QTextEdit::ExtraSelection highlight;
        highlight.format.setBackground(d->cursorColor);
        highlight.format.setProperty(QTextFormat::FullWidthSelection, true);
        highlight.cursor = textCursor();
        highlight.cursor.clearSelection();

        QList<QTextEdit::ExtraSelection> extraSelections;
        extraSelections.append(highlight);

        for (int i = 0; i < d->matchPositions.count(); ++i) {
            int pos = d->matchPositions.at(i);
            QTextEdit::ExtraSelection matchHighlight;
            matchHighlight.format.setBackground(d->bracketMatchColor);
            matchHighlight.cursor = textCursor();
            matchHighlight.cursor.setPosition(pos);
            matchHighlight.cursor.setPosition(pos + 1, QTextCursor::KeepAnchor);
            extraSelections.append(matchHighlight);
        }

        for (int i = 0; i < d->errorPositions.count(); ++i) {
            int pos = d->errorPositions.at(i);
            QTextEdit::ExtraSelection errorHighlight;
            errorHighlight.format.setBackground(d->bracketErrorColor);
            errorHighlight.cursor = textCursor();
            errorHighlight.cursor.setPosition(pos);
            errorHighlight.cursor.setPosition(pos + 1, QTextCursor::KeepAnchor);
            extraSelections.append(errorHighlight);
        }

        setExtraSelections(extraSelections);
    }
}
Esempio n. 19
0
void GenericCodeEditor::updateExtraSelections()
{
    QList<QTextEdit::ExtraSelection> selections;
    selections.append(mSearchSelections);
    setExtraSelections(selections);
}
Esempio n. 20
0
void ScriptTextEdit::restoreExtraSelections()
{
	setExtraSelections(mExtraSelections);
}
Esempio n. 21
0
void ScriptTextEdit::addExtraSelection(QTextEdit::ExtraSelection e)
{
	setExtraSelections( extraSelections() << e);
}
Esempio n. 22
0
void DataWidget::updateAllHighlights() {
    setExtraSelections(highlights);
    connect(this, &DataWidget::cursorPositionChanged, this, &DataWidget::highlightCurrentLine);
}
Esempio n. 23
0
void PgxConsole::removeSearchHighlighting()
{
    QList<QTextEdit::ExtraSelection> extraSelections;
    setExtraSelections(extraSelections);
}
Esempio n. 24
0
void DisasmWidget::updateAllHighlights() {
    setExtraSelections(extraHighlights);
}
Esempio n. 25
0
void PgxEditor::removeHighlighting()
{
    QList<QTextEdit::ExtraSelection> extraSelections;
    setExtraSelections(extraSelections);
}
Esempio n. 26
0
void BaseEditor::updateExtraSelection()
{
    setExtraSelections(findTextSelection+currentLineSelection+currentFindSelection+spellCheckErrorSelection);
}