ConfigurationDialog::ConfigurationDialog(QWidget *parent) : QDialog(parent), ui(new Ui::ConfigurationDialog), m_settings(0) { ui->setupUi(this); // Filter out characters which are not allowed in a file name QRegExpValidator *fileNameValidator = new QRegExpValidator(ui->name); fileNameValidator->setRegExp(QRegExp(QLatin1String("^[^\\/\\\\\\?\\>\\<\\*\\%\\:\\\"\\']*$"))); ui->name->setValidator(fileNameValidator); updateDocumentation(); connect(ui->name, SIGNAL(textChanged(QString)), this, SLOT(updateOkButton())); updateOkButton(); // force initial test. connect(ui->editor, SIGNAL(documentationChanged(QString,QString)), this, SLOT(updateDocumentation(QString,QString))); // Set palette and font according to settings const TextEditor::FontSettings fs = TextEditor::TextEditorSettings::instance()->fontSettings(); const QTextCharFormat tf = fs.toTextCharFormat(TextEditor::C_TEXT); const QTextCharFormat selectionFormat = fs.toTextCharFormat(TextEditor::C_SELECTION); QPalette pal; pal.setColor(QPalette::Base, tf.background().color()); pal.setColor(QPalette::Text, tf.foreground().color()); pal.setColor(QPalette::Foreground, tf.foreground().color()); if (selectionFormat.background().style() != Qt::NoBrush) pal.setColor(QPalette::Highlight, selectionFormat.background().color()); pal.setBrush(QPalette::HighlightedText, selectionFormat.foreground()); ui->documentation->setPalette(pal); ui->editor->setPalette(pal); ui->documentation->setFont(tf.font()); ui->editor->setFont(tf.font()); // Set style sheet for documentation browser const QTextCharFormat tfOption = fs.toTextCharFormat(TextEditor::C_FIELD); const QTextCharFormat tfParam = fs.toTextCharFormat(TextEditor::C_STRING); const QString css = QString::fromLatin1("span.param {color: %1; background-color: %2;} " "span.option {color: %3; background-color: %4;} " "p { text-align: justify; } ") .arg(tfParam.foreground().color().name()) .arg(tfParam.background().style() == Qt::NoBrush ? QString() : tfParam.background().color().name()) .arg(tfOption.foreground().color().name()) .arg(tfOption.background().style() == Qt::NoBrush ? QString() : tfOption.background().color().name()) ; ui->documentation->document()->setDefaultStyleSheet(css); }
void JuliaEditorWidget::setFontSettings(const TextEditor::FontSettings &fs) { using namespace TextEditor; using namespace TextEditor::Internal; BaseTextEditorWidget::setFontSettings(fs); if (baseTextDocument()->syntaxHighlighter()) { Highlighter *highlighter = static_cast<Highlighter *>(baseTextDocument()->syntaxHighlighter()); highlighter->configureFormat(Highlighter::VisualWhitespace, fs.toTextCharFormat(C_VISUAL_WHITESPACE)); highlighter->configureFormat(Highlighter::Keyword, fs.toTextCharFormat(C_KEYWORD)); highlighter->configureFormat(Highlighter::DataType, fs.toTextCharFormat(C_TYPE)); highlighter->configureFormat(Highlighter::Comment, fs.toTextCharFormat(C_COMMENT)); // Using C_NUMBER for all kinds of numbers. highlighter->configureFormat(Highlighter::Decimal, fs.toTextCharFormat(C_NUMBER)); highlighter->configureFormat(Highlighter::BaseN, fs.toTextCharFormat(C_NUMBER)); highlighter->configureFormat(Highlighter::Float, fs.toTextCharFormat(C_NUMBER)); // Using C_STRING for strings and chars. highlighter->configureFormat(Highlighter::Char, fs.toTextCharFormat(C_STRING)); highlighter->configureFormat(Highlighter::String, fs.toTextCharFormat(C_STRING)); highlighter->rehighlight(); } }
void SemanticHighlighter::updateFontSettings(const TextEditor::FontSettings &fontSettings) { m_formats[LocalIdType] = fontSettings.toTextCharFormat(TextEditor::C_QML_LOCAL_ID); m_formats[ExternalIdType] = fontSettings.toTextCharFormat(TextEditor::C_QML_EXTERNAL_ID); m_formats[QmlTypeType] = fontSettings.toTextCharFormat(TextEditor::C_QML_TYPE_ID); m_formats[RootObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_ROOT_OBJECT_PROPERTY); m_formats[ScopeObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_SCOPE_OBJECT_PROPERTY); m_formats[ExternalObjectPropertyType] = fontSettings.toTextCharFormat(TextEditor::C_QML_EXTERNAL_OBJECT_PROPERTY); m_formats[JsScopeType] = fontSettings.toTextCharFormat(TextEditor::C_JS_SCOPE_VAR); m_formats[JsImportType] = fontSettings.toTextCharFormat(TextEditor::C_JS_IMPORT_VAR); m_formats[JsGlobalType] = fontSettings.toTextCharFormat(TextEditor::C_JS_GLOBAL_VAR); m_formats[LocalStateNameType] = fontSettings.toTextCharFormat(TextEditor::C_QML_STATE_NAME); m_formats[BindingNameType] = fontSettings.toTextCharFormat(TextEditor::C_BINDING); m_formats[FieldType] = fontSettings.toTextCharFormat(TextEditor::C_FIELD); }
// Retrieve the comment char format from the text editor. static QTextCharFormat commentFormat() { const TextEditor::FontSettings settings = TextEditor::TextEditorSettings::instance()->fontSettings(); return settings.toTextCharFormat(TextEditor::C_COMMENT); }