Example #1
0
/**
 * Returns the list of QTextCharFormats that corresponds to the list of
 * requested format categories.
 */
QVector<QTextCharFormat> FontSettings::toTextCharFormats(const QVector<TextStyle> &categories) const
{
    QVector<QTextCharFormat> rc;
    const int size = categories.size();
    rc.reserve(size);
    for (int i = 0; i < size; i++)
         rc.append(toTextCharFormat(categories.at(i)));
    return rc;
}
Example #2
0
QTextCharFormat FontSettings::toTextCharFormat(TextStyles textStyles) const
{
    auto textCharFormatIterator = m_textCharFormatCache.find(textStyles);
    if (textCharFormatIterator != m_textCharFormatCache.end())
        return *textCharFormatIterator;

    QTextCharFormat textCharFormat = toTextCharFormat(textStyles.mainStyle);

    addMixinStyle(textCharFormat, textStyles.mixinStyles);

    m_textCharFormatCache.insert(textStyles, textCharFormat);

    return textCharFormat;
}
Example #3
0
void FontSettings::addMixinStyle(QTextCharFormat &textCharFormat,
                                 const MixinTextStyles &mixinStyles) const
{
    for (TextStyle mixinStyle : mixinStyles) {
        const QTextCharFormat mixinTextCharFormat = toTextCharFormat(mixinStyle);
        if (!textCharFormat.hasProperty(QTextFormat::ForegroundBrush))
            textCharFormat.setForeground(mixinTextCharFormat.foreground());

        if (!textCharFormat.hasProperty(QTextFormat::BackgroundBrush))
            textCharFormat.setBackground(mixinTextCharFormat.background());

        if (!textCharFormat.fontItalic())
            textCharFormat.setFontItalic(mixinTextCharFormat.fontItalic());

        if (textCharFormat.fontWeight() == QFont::Normal)
            textCharFormat.setFontWeight(mixinTextCharFormat.fontWeight());

        if (textCharFormat.underlineStyle() == QTextCharFormat::NoUnderline) {
            textCharFormat.setUnderlineStyle(mixinTextCharFormat.underlineStyle());
            textCharFormat.setUnderlineColor(mixinTextCharFormat.underlineColor());
        }
    };
}
Example #4
0
void ExtraCompilerPrivate::updateIssues()
{
    if (!lastEditor)
        return;

    auto widget = qobject_cast<TextEditor::TextEditorWidget *>(lastEditor->widget());
    if (!widget)
        return;

    QList<QTextEdit::ExtraSelection> selections;
    const QTextDocument *document = widget->document();
    foreach (const Task &issue, issues) {
        QTextEdit::ExtraSelection selection;
        QTextCursor cursor(document->findBlockByNumber(issue.line - 1));
        cursor.movePosition(QTextCursor::StartOfLine);
        cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
        selection.cursor = cursor;

        const auto fontSettings = TextEditor::TextEditorSettings::instance()->fontSettings();
        selection.format = fontSettings.toTextCharFormat(issue.type == Task::Warning ?
                TextEditor::C_WARNING : TextEditor::C_ERROR);
        selection.format.setToolTip(issue.description);
        selections.append(selection);
    }