enhancement: force fixed width

This commit is contained in:
Roy Qu 2024-02-28 11:51:02 +08:00
parent f763cec8f4
commit 0bab75cfd6
15 changed files with 375 additions and 236 deletions

View File

@ -5258,8 +5258,6 @@ void Editor::applySettings()
options.setFlag(QSynedit::eoAutoIndent,pSettings->editor().autoIndent());
options.setFlag(QSynedit::eoTabsToSpaces,pSettings->editor().tabToSpaces());
options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport());
options.setFlag(QSynedit::eoKeepCaretX,pSettings->editor().keepCaretX());
options.setFlag(QSynedit::eoEnhanceHomeKey,pSettings->editor().enhanceHomeKey());
options.setFlag(QSynedit::eoEnhanceEndKey,pSettings->editor().enhanceEndKey());
@ -5273,6 +5271,10 @@ void Editor::applySettings()
options.setFlag(QSynedit::eoShowRainbowColor,
pSettings->editor().rainbowParenthesis()
&& syntaxer() && syntaxer()->supportBraceLevel());
options.setFlag(QSynedit::eoForceMonospace,
pSettings->editor().forceFixedFontWidth());
options.setFlag(QSynedit::eoLigatureSupport,
pSettings->editor().enableLigaturesSupport());
setOptions(options);
setTabSize(pSettings->editor().tabWidth());

View File

@ -857,6 +857,16 @@ void Settings::Editor::setTipsDelay(int newTipsDelay)
mTipsDelay = newTipsDelay;
}
bool Settings::Editor::forceFixedFontWidth() const
{
return mForceFixedFontWidth;
}
void Settings::Editor::setForceFixedFontWidth(bool newForceFixedWidth)
{
mForceFixedFontWidth = newForceFixedWidth;
}
bool Settings::Editor::showTrailingSpaces() const
{
return mShowTrailingSpaces;
@ -1408,6 +1418,7 @@ void Settings::Editor::doSave()
saveValue("font_only_monospaced", mFontOnlyMonospaced);
saveValue("line_spacing",mLineSpacing);
saveValue("enable_ligatures_support", mEnableLigaturesSupport);
saveValue("force_fixed_font_width", mForceFixedFontWidth);
saveValue("show_leading_spaces", mShowLeadingSpaces);
saveValue("show_trailing_spaces", mShowTrailingSpaces);
@ -1538,6 +1549,12 @@ void Settings::Editor::doLoad()
mFontName = stringValue("font_name",DEFAULT_MONO_FONT);
QString defaultCjkFontName = DEFAULT_MONO_FONT;
QString defaultLocaleName = QLocale::system().name();
bool isZhJa =
defaultLocaleName.startsWith("zh_")
|| defaultLocaleName.startsWith("ja_")
|| defaultLocaleName==("zh")
|| defaultLocaleName == ("ja");
if (defaultLocaleName == "zh_TW")
defaultCjkFontName = CJK_MONO_FONT_TC;
else if (defaultLocaleName == "ja_JP")
@ -1554,7 +1571,13 @@ void Settings::Editor::doLoad()
mFontSize = intValue("font_size",12);
mFontOnlyMonospaced = boolValue("font_only_monospaced",true);
mLineSpacing = doubleValue("line_spacing",1.1);
mEnableLigaturesSupport = boolValue("enable_ligatures_support", true);
mForceFixedFontWidth = boolValue("force_fixed_font_width", isZhJa);
// if (mForceFixedFontWidth)
// mEnableLigaturesSupport = false;
// else
// mEnableLigaturesSupport = boolValue("enable_ligatures_support", !isZhJa);
mEnableLigaturesSupport = boolValue("enable_ligatures_support", !isZhJa);
mShowLeadingSpaces = boolValue("show_leading_spaces", false);
mShowTrailingSpaces = boolValue("show_trailing_spaces", false);

View File

@ -420,6 +420,9 @@ public:
int tipsDelay() const;
void setTipsDelay(int newTipsDelay);
bool forceFixedFontWidth() const;
void setForceFixedFontWidth(bool newForceFixedWidth);
private:
//General
// indents
@ -456,7 +459,6 @@ public:
bool mShowRightEdgeLine;
int mRightEdgeWidth;
QColor mRightEdgeLineColor;
bool mEnableLigaturesSupport;
//Font
//font
@ -469,6 +471,8 @@ public:
int mFontSize;
bool mFontOnlyMonospaced;
double mLineSpacing;
bool mEnableLigaturesSupport;
bool mForceFixedFontWidth;
bool mShowLeadingSpaces;
bool mShowTrailingSpaces;

View File

@ -71,6 +71,7 @@ void EditorFontWidget::doLoad()
ui->spinFontSize->setValue(pSettings->editor().fontSize());
ui->spinLineSpacing->setValue(pSettings->editor().lineSpacing());
ui->chkLigature->setChecked(pSettings->editor().enableLigaturesSupport());
ui->chkForceFixedFontWidth->setChecked(pSettings->editor().forceFixedFontWidth());
ui->chkLeadingSpaces->setChecked(pSettings->editor().showLeadingSpaces());
ui->chkInnerSpaces->setChecked(pSettings->editor().showInnerSpaces());
ui->chkTrailingSpaces->setChecked(pSettings->editor().showTrailingSpaces());
@ -104,6 +105,7 @@ void EditorFontWidget::doSave()
pSettings->editor().setLineSpacing(ui->spinLineSpacing->value());
pSettings->editor().setEnableLigaturesSupport(ui->chkLigature->isChecked());
pSettings->editor().setForceFixedFontWidth(ui->chkForceFixedFontWidth->isChecked());
pSettings->editor().setShowLeadingSpaces(ui->chkLeadingSpaces->isChecked());
pSettings->editor().setShowInnerSpaces(ui->chkInnerSpaces->isChecked());
pSettings->editor().setShowTrailingSpaces(ui->chkTrailingSpaces->isChecked());
@ -132,3 +134,17 @@ void EditorFontWidget::onFallbackFontsCheckStateChanged()
ui->cbFallbackFont3->setEnabled(ui->chkFallbackFont3->isChecked());
}
// void EditorFontWidget::on_chkLigature_toggled(bool checked)
// {
// if (ui->chkLigature->isChecked())
// ui->chkForceFixedFontWidth->setChecked(false);
// }
// void EditorFontWidget::on_chkForceFixedFontWidth_toggled(bool checked)
// {
// if (ui->chkForceFixedFontWidth->isChecked())
// ui->chkLigature->setChecked(false);
// }

View File

@ -37,6 +37,10 @@ private slots:
void on_chkOnlyMonospacedFonts_stateChanged(int arg1);
void on_chkGutterOnlyMonospacedFonts_stateChanged(int arg1);
// void on_chkLigature_toggled(bool checked);
// void on_chkForceFixedFontWidth_toggled(bool checked);
private:
Ui::EditorFontWidget *ui;

View File

@ -23,125 +23,6 @@
<property name="rightMargin">
<number>11</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QCheckBox" name="chkLigature">
<property name="text">
<string>Enable ligatures support</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFont">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="fontFilters">
<set>QFontComboBox::AllFonts</set>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkOnlyMonospacedFonts">
<property name="text">
<string>Show only monospaced fonts</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="5" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="spinLineSpacing">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>563</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
@ -149,16 +30,9 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Fallback Font:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<item row="3" column="1">
<widget class="QWidget" name="panelFallbackFont3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<property name="leftMargin">
<number>0</number>
</property>
@ -172,24 +46,21 @@
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont">
<widget class="QFontComboBox" name="cbFallbackFont3">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<widget class="QLabel" name="label_14">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<spacer name="horizontalSpacer_10">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -287,9 +158,44 @@
</layout>
</widget>
</item>
<item row="3" column="1">
<widget class="QWidget" name="panelFallbackFont3" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_11">
<item row="3" column="0">
<widget class="QCheckBox" name="chkFallbackFont3">
<property name="text">
<string>Fallback Font 3:</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Fallback Font:</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkFallbackFont2">
<property name="text">
<string>Fallback Font 2:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Size:</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Font:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QWidget" name="widget_2" native="true">
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
@ -303,21 +209,27 @@
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont3">
<widget class="QFontComboBox" name="cbFont">
<property name="editable">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_14">
<property name="text">
<string>*Needs restart</string>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
<property name="fontFilters">
<set>QFontComboBox::AllFonts</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_10">
<widget class="QCheckBox" name="chkOnlyMonospacedFonts">
<property name="text">
<string>Show only monospaced fonts</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@ -332,18 +244,144 @@
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QCheckBox" name="chkFallbackFont2">
<property name="text">
<string>Fallback Font 2:</string>
</property>
<item row="1" column="1">
<widget class="QWidget" name="widget_9" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QFontComboBox" name="cbFallbackFont">
<property name="editable">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QComboBox::AdjustToContents</enum>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="label_10">
<property name="text">
<string>*Needs restart</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_7">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="3" column="0">
<widget class="QCheckBox" name="chkFallbackFont3">
<property name="text">
<string>Fallback Font 3:</string>
</property>
<item row="5" column="1">
<widget class="QWidget" name="widget_10" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_8">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QDoubleSpinBox" name="spinLineSpacing">
<property name="decimals">
<number>1</number>
</property>
<property name="minimum">
<double>1.000000000000000</double>
</property>
<property name="maximum">
<double>3.000000000000000</double>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_8">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>563</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="6" column="0" colspan="2">
<widget class="QWidget" name="widget_11" native="true">
<layout class="QHBoxLayout" name="horizontalLayout_12">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="chkLigature">
<property name="text">
<string>Enable ligatures support</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkForceFixedFontWidth">
<property name="text">
<string>Force fixed width</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_11">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
</layout>

View File

@ -1569,6 +1569,10 @@
<source>Fallback Font 3:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Force fixed width</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorGeneralWidget</name>

View File

@ -1653,7 +1653,7 @@ p, li { white-space: pre-wrap; }
<translation>:</translation>
</message>
<message>
<location filename="../editor.cpp" line="5479"/>
<location filename="../editor.cpp" line="5472"/>
<source>Readonly</source>
<translation></translation>
</message>
@ -2059,27 +2059,27 @@ p, li { white-space: pre-wrap; }
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="194"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="280"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="321"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="58"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="141"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="275"/>
<source>*Needs restart</source>
<translation>*</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="94"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="604"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="185"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="650"/>
<source>Size:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="29"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="597"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="192"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="643"/>
<source>Font:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="71"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="692"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="227"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="738"/>
<source>Show only monospaced fonts</source>
<translation></translation>
</message>
@ -2096,102 +2096,107 @@ p, li { white-space: pre-wrap; }
<translation type="vanished"></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="36"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="360"/>
<source>Enable ligatures support</source>
<translation>(ligratures)</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="148"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="29"/>
<source>Line Spacing:</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="155"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="171"/>
<source>Fallback Font:</source>
<translation>:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="162"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="178"/>
<source>Fallback Font 2:</source>
<translation>2:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="255"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="164"/>
<source>Fallback Font 3:</source>
<translation>3:</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="347"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="367"/>
<source>Force fixed width</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="393"/>
<source>Show whitespaces</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="353"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="399"/>
<source>Leading</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="360"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="406"/>
<source>Inner</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="367"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="413"/>
<source>Trailing</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="374"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="420"/>
<source>Line break</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="384"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="430"/>
<source>Gutter</source>
<translation>线</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="405"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="451"/>
<source>Gutter is visible</source>
<translation>线</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="427"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="473"/>
<source>Left Offset</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="444"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="490"/>
<source>Right Offset</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="477"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="523"/>
<source>Show Line Numbers</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="501"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="547"/>
<source>Add leading zeros to line numbers</source>
<translation>0</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="508"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="554"/>
<source>Line numbers starts at zero</source>
<translation>0</translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="515"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="561"/>
<source>Auto calculate the digit count of line number</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="537"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="583"/>
<source>Digit count</source>
<translation></translation>
</message>
<message>
<location filename="../settingsdialog/editorfontwidget.ui" line="573"/>
<location filename="../settingsdialog/editorfontwidget.ui" line="619"/>
<source>Use Custom Font</source>
<translation>使</translation>
</message>
@ -8855,7 +8860,7 @@ p, li { white-space: pre-wrap; }
<context>
<name>QApplication</name>
<message>
<location filename="../main.cpp" line="453"/>
<location filename="../main.cpp" line="456"/>
<source>Error</source>
<translation></translation>
</message>
@ -8947,23 +8952,23 @@ p, li { white-space: pre-wrap; }
</message>
<message>
<location filename="../colorscheme.cpp" line="582"/>
<location filename="../main.cpp" line="221"/>
<location filename="../main.cpp" line="228"/>
<location filename="../main.cpp" line="222"/>
<location filename="../main.cpp" line="229"/>
<source>Error</source>
<translation></translation>
</message>
<message>
<location filename="../main.cpp" line="222"/>
<location filename="../main.cpp" line="223"/>
<source>Can&apos;t create configuration folder %1</source>
<translation>&quot;%1&quot;</translation>
</message>
<message>
<location filename="../main.cpp" line="229"/>
<location filename="../main.cpp" line="230"/>
<source>Can&apos;t write to configuration file %1</source>
<translation>&quot;%1&quot;</translation>
</message>
<message>
<location filename="../main.cpp" line="403"/>
<location filename="../main.cpp" line="404"/>
<source>Can&apos;t load autolink settings</source>
<translation></translation>
</message>
@ -9071,7 +9076,7 @@ p, li { white-space: pre-wrap; }
<translation>(-g3)</translation>
</message>
<message>
<location filename="../settings.cpp" line="3466"/>
<location filename="../settings.cpp" line="3522"/>
<source>Would you like Red Panda C++ to search for compilers in PATH?</source>
<translation>C++PATH路径中寻找gcc编译器吗</translation>
</message>
@ -9282,7 +9287,7 @@ p, li { white-space: pre-wrap; }
<translation type="vanished">(-S)</translation>
</message>
<message>
<location filename="../settings.cpp" line="3468"/>
<location filename="../settings.cpp" line="3524"/>
<source>Confirm</source>
<translation></translation>
</message>
@ -9303,13 +9308,13 @@ p, li { white-space: pre-wrap; }
<translation type="vanished">&lt;br /&gt;&lt;br /&gt;</translation>
</message>
<message>
<location filename="../settings.cpp" line="3458"/>
<location filename="../settings.cpp" line="3464"/>
<location filename="../settings.cpp" line="3514"/>
<location filename="../settings.cpp" line="3520"/>
<source>Compiler set not configuared.</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="3460"/>
<location filename="../settings.cpp" line="3516"/>
<source>Would you like Red Panda C++ to search for compilers in the following locations: &lt;BR /&gt;&apos;%1&apos;&lt;BR /&gt;&apos;%2&apos;? </source>
<translation>C++&lt;br /&gt;%1&lt;br /&gt;%2</translation>
</message>
@ -9665,12 +9670,12 @@ p, li { white-space: pre-wrap; }
<translation type="vanished"></translation>
</message>
<message>
<location filename="../parser/cppparser.cpp" line="1211"/>
<location filename="../parser/cppparser.cpp" line="1210"/>
<source>constructor</source>
<translation></translation>
</message>
<message>
<location filename="../parser/cppparser.cpp" line="1218"/>
<location filename="../parser/cppparser.cpp" line="1217"/>
<source>destructor</source>
<translation></translation>
</message>
@ -9678,7 +9683,7 @@ p, li { white-space: pre-wrap; }
<location filename="../autolinkmanager.cpp" line="54"/>
<location filename="../autolinkmanager.cpp" line="70"/>
<location filename="../autolinkmanager.cpp" line="89"/>
<location filename="../settings.cpp" line="4081"/>
<location filename="../settings.cpp" line="4137"/>
<location filename="../widgets/ojproblemsetmodel.cpp" line="168"/>
<location filename="../widgets/ojproblemsetmodel.cpp" line="229"/>
<source>Can&apos;t open file &apos;%1&apos; for read.</source>
@ -9733,7 +9738,7 @@ p, li { white-space: pre-wrap; }
<translation> %1 </translation>
</message>
<message>
<location filename="../settings.cpp" line="3326"/>
<location filename="../settings.cpp" line="3382"/>
<source>Error executing platform compiler hint add-on</source>
<translation></translation>
</message>
@ -10697,12 +10702,12 @@ p, li { white-space: pre-wrap; }
<context>
<name>Settings</name>
<message>
<location filename="../settings.cpp" line="4068"/>
<location filename="../settings.cpp" line="4124"/>
<source>Error</source>
<translation></translation>
</message>
<message>
<location filename="../settings.cpp" line="4069"/>
<location filename="../settings.cpp" line="4125"/>
<source>Can&apos;t find terminal program!</source>
<translation></translation>
</message>

View File

@ -1402,6 +1402,10 @@
<source>Fallback Font 3:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Force fixed width</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>EditorGeneralWidget</name>

View File

@ -142,7 +142,11 @@ void CPUDialog::setDisassembly(const QString& file, const QString& funcName,cons
void CPUDialog::resetEditorFont(float dpi)
{
QSynedit::EditorOptions options=ui->txtCode->getOptions();
options.setFlag(QSynedit::eoLigatureSupport, pSettings->editor().enableLigaturesSupport());
options.setFlag(QSynedit::eoForceMonospace,
pSettings->editor().forceFixedFontWidth());
ui->txtCode->setOptions(options);
QFont f=QFont();
f.setFamilies(pSettings->editor().fontFamilies());
f.setPixelSize(pointToPixel(pSettings->editor().fontSize(),dpi));

View File

@ -31,13 +31,14 @@
namespace QSynedit {
Document::Document(const QFont& font, QObject *parent):
QObject(parent),
mFontMetrics(font),
mTabSize(4),
QObject{parent},
mFontMetrics{font},
mTabSize{4},
mForceMonospace{false},
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
mMutex()
mMutex{}
#else
mMutex(QMutex::Recursive)
mMutex{QMutex::Recursive}
#endif
{
mAppendNewLineAtEOF = true;
@ -585,6 +586,19 @@ void Document::saveUTF32File(QFile &file, QTextCodec* codec)
file.write(codec->fromUnicode(text));
}
bool Document::forceMonospace() const
{
return mForceMonospace;
}
void Document::setForceMonospace(bool newForceMonospace)
{
int oldValue = mForceMonospace;
mForceMonospace = newForceMonospace;
if (oldValue != mForceMonospace)
invalidateAllLineWidth();
}
const QFontMetrics &Document::fontMetrics() const
{
return mFontMetrics;
@ -936,7 +950,7 @@ int Document::glyphWidth(int line, int glyphIdx)
int Document::glyphWidth(const QString &glyph, int left) const
{
return glyphWidth(glyph,left,mFontMetrics);
return glyphWidth(glyph,left,mFontMetrics,mForceMonospace);
}
int Document::charToGlyphIndex(int line, int charIdx)
@ -982,7 +996,7 @@ QList<int> Document::calcGlyphPositionList(const QString &lineText, const QList<
end = lineText.length();
}
QString glyph = lineText.mid(start,end-start);
int gWidth = glyphWidth(glyph, right, fontMetrics);
int gWidth = glyphWidth(glyph, right, fontMetrics, mForceMonospace);
glyphPostionList.append(right);
right += gWidth;
}
@ -1732,7 +1746,7 @@ int Document::updateGlyphStartPositionList(
end = lineText.length();
}
QString glyph = lineText.mid(start,end-start);
int gWidth = glyphWidth(glyph, right, fontMetrics);
int gWidth = glyphWidth(glyph, right, fontMetrics, mForceMonospace);
glyphStartPositionList[i] = right;
right += gWidth;
}
@ -1741,18 +1755,22 @@ int Document::updateGlyphStartPositionList(
return right-left;
}
int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics) const
int Document::glyphWidth(const QString &glyph, int left, const QFontMetrics &fontMetrics, bool forceMonospace) const
{
int glyphWidth;
if (glyph.length()==0)
return 0;
QChar ch = glyph[0];
if (ch == '\t') {
if (ch == '\t') {
glyphWidth = tabWidth() - left % tabWidth();
} else {
glyphWidth = fontMetrics.horizontalAdvance(glyph);
//qDebug()<<glyph<<glyphCols<<width<<mCharWidth;
}
if (forceMonospace) {
int cols = std::ceil(glyphWidth / (double)mCharWidth);
glyphWidth = cols * mCharWidth;
}
return glyphWidth;
}

View File

@ -548,6 +548,9 @@ public:
const QFontMetrics &fontMetrics() const;
void setFont(const QFont &newFont);
bool forceMonospace() const;
void setForceMonospace(bool newForceMonospace);
public slots:
void invalidateAllLineWidth();
@ -569,7 +572,8 @@ private:
void setLineWidth(int line, const QString& lineText, int newWidth, const QList<int> glyphStartPositionList);
int glyphWidth(const QString& glyph, int left,
const QFontMetrics &fontMetrics) const;
const QFontMetrics &fontMetrics,
bool forceMonospace) const;
int xposToGlyphIndex(int strWidth, QList<int> glyphPositionList, int xpos) const;
int charToGlyphIndex(const QString& str, QList<int> glyphStartCharList, int charPos) const;
@ -604,6 +608,7 @@ private:
bool mAppendNewLineAtEOF;
int mIndexOfLongestLine;
int mUpdateCount;
bool mForceMonospace;
#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
QRecursiveMutex mMutex;
#else

View File

@ -384,6 +384,8 @@ void QSynEditPainter::paintToken(
}
if (tryLigature) {
QString textToPaint = glyph;
int oldGlyphWidth = glyphWidth;
int oldI = i;
while(i+1<endGlyph) {
int glyphStart = glyphStartCharList[i+1];
int glyphLen = calcSegmentInterval(glyphStartCharList,lineText.length(),i+1);
@ -401,13 +403,19 @@ void QSynEditPainter::paintToken(
if (tokenWidth + glyphWidth > last )
break;
}
if (!fontInited) {
mPainter->setFont(font);
fontInited = true;
if (glyphWidth
== mPainter->fontMetrics().horizontalAdvance(textToPaint)) {
if (!fontInited) {
mPainter->setFont(font);
fontInited = true;
}
//qDebug()<<"paint 1:"<<textToPaint;
mPainter->drawText(nX,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint);
drawed = true;
} else {
glyphWidth = oldGlyphWidth;
i=oldI;
}
//qDebug()<<"paint 1:"<<textToPaint;
mPainter->drawText(nX,rcToken.bottom()-mPainter->fontMetrics().descent() , textToPaint);
drawed = true;
}
}
if (!drawed) {

View File

@ -4077,15 +4077,19 @@ void QSynEdit::setOptions(const EditorOptions &Value)
setTopLine(mTopLine);
bool bUpdateAll =
!sameEditorOption(Value,mOptions,eoShowLeadingSpaces)
|| !sameEditorOption(Value,mOptions,eoShowInnerSpaces)
|| !sameEditorOption(Value,mOptions,eoShowTrailingSpaces)
|| !sameEditorOption(Value,mOptions,eoShowLineBreaks)
|| !sameEditorOption(Value,mOptions,eoShowRainbowColor);
!sameEditorOption(Value,mOptions, eoShowLeadingSpaces)
|| !sameEditorOption(Value,mOptions, eoLigatureSupport)
|| !sameEditorOption(Value,mOptions, eoForceMonospace)
|| !sameEditorOption(Value,mOptions, eoShowInnerSpaces)
|| !sameEditorOption(Value,mOptions, eoShowTrailingSpaces)
|| !sameEditorOption(Value,mOptions, eoShowLineBreaks)
|| !sameEditorOption(Value,mOptions, eoShowRainbowColor);
//bool bUpdateScroll = (Options * ScrollOptions)<>(Value * ScrollOptions);
bool bUpdateScroll = true;
mOptions = Value;
mDocument->setForceMonospace(mOptions.testFlag(eoForceMonospace) );
// constrain caret position to MaxScrollWidth if eoScrollPastEol is enabled
internalSetCaretXY(caretXY());
if (mOptions.testFlag(eoScrollPastEol)) {

View File

@ -4288,29 +4288,29 @@
<context>
<name>QSynedit::Document</name>
<message>
<location filename="qsynedit/document.cpp" line="614"/>
<location filename="qsynedit/document.cpp" line="628"/>
<source>Can&apos;t open file &apos;%1&apos; for read!</source>
<translation>&quot;%1&quot;.</translation>
</message>
<message>
<location filename="qsynedit/document.cpp" line="654"/>
<location filename="qsynedit/document.cpp" line="777"/>
<location filename="qsynedit/document.cpp" line="668"/>
<location filename="qsynedit/document.cpp" line="791"/>
<source>Can&apos;t load codec &apos;%1&apos;!</source>
<translation>&quot;%1&quot;!</translation>
</message>
<message>
<location filename="qsynedit/document.cpp" line="673"/>
<location filename="qsynedit/document.cpp" line="687"/>
<source>&apos;%1&apos; is a binaray File!</source>
<oldsource>This is a binaray File!</oldsource>
<translation>&apos;%1&apos;</translation>
</message>
<message>
<location filename="qsynedit/document.cpp" line="780"/>
<location filename="qsynedit/document.cpp" line="794"/>
<source>Can&apos;t open file &apos;%1&apos; for save!</source>
<translation>&quot;%1&quot;!</translation>
</message>
<message>
<location filename="qsynedit/document.cpp" line="803"/>
<location filename="qsynedit/document.cpp" line="817"/>
<source>Data not correctly writed to file &apos;%1&apos;.</source>
<translation>&quot;%1&quot;</translation>
</message>