Skip to content

Commit

Permalink
Add option for setting SQL editor font
Browse files Browse the repository at this point in the history
See issue #299.
  • Loading branch information
MKleusberg committed May 6, 2015
1 parent 9cbb4d5 commit 2715d75
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
6 changes: 6 additions & 0 deletions src/PreferencesDialog.cpp
Expand Up @@ -84,6 +84,7 @@ void PreferencesDialog::loadSettings()
ui->treeSyntaxHighlighting->topLevelItem(i)->setCheckState(5, getSettingsValue("syntaxhighlighter", name + "_underline").toBool() ? Qt::Checked : Qt::Unchecked);
}
}
ui->comboEditorFont->setCurrentText(getSettingsValue("editor", "font").toString());
ui->spinEditorFontSize->setValue(getSettingsValue("editor", "fontsize").toInt());
ui->spinTabSize->setValue(getSettingsValue("editor", "tabsize").toInt());
ui->spinLogFontSize->setValue(getSettingsValue("log", "fontsize").toInt());
Expand Down Expand Up @@ -118,6 +119,7 @@ void PreferencesDialog::saveSettings()
setSettingsValue("syntaxhighlighter", name + "_italic", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(4) == Qt::Checked);
setSettingsValue("syntaxhighlighter", name + "_underline", ui->treeSyntaxHighlighting->topLevelItem(i)->checkState(5) == Qt::Checked);
}
setSettingsValue("editor", "font", ui->comboEditorFont->currentText());
setSettingsValue("editor", "fontsize", ui->spinEditorFontSize->value());
setSettingsValue("editor", "tabsize", ui->spinTabSize->value());
setSettingsValue("log", "fontsize", ui->spinLogFontSize->value());
Expand Down Expand Up @@ -274,6 +276,10 @@ QVariant PreferencesDialog::getSettingsDefaultValue(const QString& group, const
}
}

// editor/font?
if(group == "editor" && name == "font")
return "Monospace";

// editor/fontsize or log/fontsize?
if((group == "editor" || group == "log") && name == "fontsize")
return 9;
Expand Down
41 changes: 30 additions & 11 deletions src/PreferencesDialog.ui
Expand Up @@ -591,7 +591,7 @@ QGroupBox::title {
</item>
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>SQL &amp;editor font size</string>
Expand All @@ -601,14 +601,14 @@ QGroupBox::title {
</property>
</widget>
</item>
<item row="0" column="1">
<item row="1" column="1">
<widget class="QSpinBox" name="spinEditorFontSize">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="1" column="0">
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>SQL &amp;log font size</string>
Expand All @@ -618,21 +618,24 @@ QGroupBox::title {
</property>
</widget>
</item>
<item row="1" column="1">
<item row="2" column="1">
<widget class="QSpinBox" name="spinLogFontSize">
<property name="minimum">
<number>1</number>
</property>
</widget>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Tab size:</string>
</property>
<property name="buddy">
<cstring>spinTabSize</cstring>
</property>
</widget>
</item>
<item row="2" column="1">
<item row="3" column="1">
<widget class="QSpinBox" name="spinTabSize">
<property name="minimum">
<number>1</number>
Expand All @@ -645,6 +648,19 @@ QGroupBox::title {
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_14">
<property name="text">
<string>SQL editor &amp;font</string>
</property>
<property name="buddy">
<cstring>comboEditorFont</cstring>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QFontComboBox" name="comboEditorFont"/>
</item>
</layout>
</item>
</layout>
Expand Down Expand Up @@ -741,6 +757,8 @@ QGroupBox::title {
</layout>
</widget>
<tabstops>
<tabstop>tabWidget</tabstop>
<tabstop>comboDefaultLocation</tabstop>
<tabstop>locationEdit</tabstop>
<tabstop>setLocationButton</tabstop>
<tabstop>languageComboBox</tabstop>
Expand All @@ -753,13 +771,14 @@ QGroupBox::title {
<tabstop>frameNullFgColour</tabstop>
<tabstop>frameNullBgColour</tabstop>
<tabstop>treeSyntaxHighlighting</tabstop>
<tabstop>comboEditorFont</tabstop>
<tabstop>spinEditorFontSize</tabstop>
<tabstop>spinLogFontSize</tabstop>
<tabstop>spinTabSize</tabstop>
<tabstop>listExtensions</tabstop>
<tabstop>buttonAddExtension</tabstop>
<tabstop>buttonRemoveExtension</tabstop>
<tabstop>checkRegexDisabled</tabstop>
<tabstop>tabWidget</tabstop>
</tabstops>
<resources>
<include location="icons/icons.qrc"/>
Expand Down Expand Up @@ -805,7 +824,7 @@ QGroupBox::title {
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>82</y>
<y>79</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
Expand All @@ -821,7 +840,7 @@ QGroupBox::title {
<hints>
<hint type="sourcelabel">
<x>119</x>
<y>82</y>
<y>79</y>
</hint>
<hint type="destinationlabel">
<x>245</x>
Expand Down Expand Up @@ -852,8 +871,8 @@ QGroupBox::title {
<slot>chooseLocation()</slot>
<hints>
<hint type="sourcelabel">
<x>568</x>
<y>71</y>
<x>567</x>
<y>100</y>
</hint>
<hint type="destinationlabel">
<x>294</x>
Expand Down
2 changes: 1 addition & 1 deletion src/SqlExecutionArea.cpp
Expand Up @@ -20,7 +20,7 @@ SqlExecutionArea::SqlExecutionArea(QWidget* parent, DBBrowserDB* _db) :
ui->setupUi(this);

// Set font
QFont logfont("Monospace");
QFont logfont(PreferencesDialog::getSettingsValue("editor", "font").toString());
logfont.setStyleHint(QFont::TypeWriter);
logfont.setPointSize(PreferencesDialog::getSettingsValue("log", "fontsize").toInt());
ui->editErrors->setFont(logfont);
Expand Down
8 changes: 4 additions & 4 deletions src/sqltextedit.cpp
Expand Up @@ -87,7 +87,7 @@ void SqlTextEdit::setupSyntaxHighlightingFormat(const QString& settings_name, in
{
sqlLexer->setColor(QColor(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_colour").toString()), style);

QFont font("Monospace");
QFont font(PreferencesDialog::getSettingsValue("editor", "font").toString());
font.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt());
font.setBold(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_bold").toBool());
font.setItalic(PreferencesDialog::getSettingsValue("syntaxhighlighter", settings_name + "_italic").toBool());
Expand All @@ -105,7 +105,7 @@ void SqlTextEdit::reloadSettings()
{
// Set syntax highlighting settings
sqlLexer->setDefaultColor(Qt::black);
QFont defaultfont("Monospace");
QFont defaultfont(PreferencesDialog::getSettingsValue("editor", "font").toString());
defaultfont.setStyleHint(QFont::TypeWriter);
defaultfont.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt());
sqlLexer->setDefaultFont(defaultfont);
Expand All @@ -121,13 +121,13 @@ void SqlTextEdit::reloadSettings()
setupSyntaxHighlightingFormat("identifier", QsciLexerSQL::QuotedIdentifier);

// Set font
QFont font("Monospace");
QFont font(PreferencesDialog::getSettingsValue("editor", "font").toString());
font.setStyleHint(QFont::TypeWriter);
font.setPointSize(PreferencesDialog::getSettingsValue("editor", "fontsize").toInt());
setFont(font);

// Show line numbers
QFont marginsfont(QFont("Monospace"));
QFont marginsfont(QFont(PreferencesDialog::getSettingsValue("editor", "font").toString()));
marginsfont.setPointSize(font.pointSize());
setMarginsFont(marginsfont);
setMarginLineNumbers(0, true);
Expand Down

0 comments on commit 2715d75

Please sign in to comment.