Gui: Add functionality to enable/disable block shape cursor in text editor and console

This commit is contained in:
marioalexis
2022-01-26 00:07:47 -03:00
committed by wwmayer
parent 4b2e707018
commit ec167207bf
6 changed files with 88 additions and 16 deletions

View File

@@ -187,7 +187,7 @@
<property name="bottomMargin">
<number>9</number>
</property>
<item>
<item row="0" column="0">
<widget class="Gui::PrefCheckBox" name="EnableLineNumber">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
@@ -209,6 +209,28 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="Gui::PrefCheckBox" name="EnableBlockCursor">
<property name="focusPolicy">
<enum>Qt::TabFocus</enum>
</property>
<property name="toolTip">
<string>The cursor shape will be a block</string>
</property>
<property name="text">
<string>Enable block cursor</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>EnableBlockCursor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>Editor</cstring>
</property>
</widget>
</item>
<item>
<widget class="Gui::PrefCheckBox" name="EnableFolding">
<property name="text">
@@ -377,6 +399,7 @@
<tabstops>
<tabstop>fontFamily</tabstop>
<tabstop>EnableLineNumber</tabstop>
<tabstop>EnableBlockCursor</tabstop>
<tabstop>EnableFolding</tabstop>
<tabstop>tabSize</tabstop>
<tabstop>indentSize</tabstop>

View File

@@ -174,6 +174,7 @@ void DlgSettingsEditorImp::on_colorButton_changed()
void DlgSettingsEditorImp::saveSettings()
{
ui->EnableLineNumber->onSave();
ui->EnableBlockCursor->onSave();
ui->EnableFolding->onSave();
ui->tabSize->onSave();
ui->indentSize->onSave();
@@ -194,6 +195,7 @@ void DlgSettingsEditorImp::saveSettings()
void DlgSettingsEditorImp::loadSettings()
{
ui->EnableLineNumber->onRestore();
ui->EnableBlockCursor->onRestore();
ui->EnableFolding->onRestore();
ui->tabSize->onRestore();
ui->indentSize->onRestore();

View File

@@ -582,6 +582,25 @@ horizontal space in Python console</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="Gui::PrefCheckBox" name="PythonBlockCursor">
<property name="toolTip">
<string>The cursor shape will be a block</string>
</property>
<property name="text">
<string>Enable block cursor</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<property name="prefEntry" stdset="0">
<cstring>PythonBlockCursor</cstring>
</property>
<property name="prefPath" stdset="0">
<cstring>General</cstring>
</property>
</widget>
</item>
</layout>
</widget>
</item>
@@ -608,6 +627,7 @@ horizontal space in Python console</string>
<tabstop>RecentFiles</tabstop>
<tabstop>SplashScreen</tabstop>
<tabstop>PythonWordWrap</tabstop>
<tabstop>PythonBlockCursor</tabstop>
</tabstops>
<resources/>
<connections/>

View File

@@ -144,6 +144,7 @@ void DlgGeneralImp::saveSettings()
ui->RecentFiles->onSave();
ui->SplashScreen->onSave();
ui->PythonWordWrap->onSave();
ui->PythonBlockCursor->onSave();
QWidget* pc = DockWindowManager::instance()->getDockWindow("Python console");
PythonConsole *pcPython = qobject_cast<PythonConsole*>(pc);
@@ -209,6 +210,7 @@ void DlgGeneralImp::loadSettings()
ui->RecentFiles->onRestore();
ui->SplashScreen->onRestore();
ui->PythonWordWrap->onRestore();
ui->PythonBlockCursor->onRestore();
// search for the language files
ParameterGrp::handle hGrp = WindowParameter::getDefaultParameter()->GetGroup("General");

View File

@@ -488,14 +488,15 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
{
Q_UNUSED(rCaller);
ParameterGrp::handle hPrefGrp = getWindowParameter();
ParameterGrp::handle hPrefGen = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("General");
bool pythonWordWrap = App::GetApplication().GetUserParameter().
GetGroup("BaseApp")->GetGroup("Preferences")->GetGroup("General")->GetBool("PythonWordWrap", true);
if (pythonWordWrap) {
this->setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
} else {
this->setWordWrapMode(QTextOption::NoWrap);
if (strcmp(sReason, "PythonWordWrap") == 0) {
bool pythonWordWrap = hPrefGen->GetBool("PythonWordWrap", true);
if (pythonWordWrap)
setWordWrapMode(QTextOption::WrapAtWordBoundaryOrAnywhere);
else
setWordWrapMode(QTextOption::NoWrap);
}
if (strcmp(sReason, "FontSize") == 0 || strcmp(sReason, "Font") == 0) {
@@ -511,7 +512,8 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
#else
setTabStopDistance(width);
#endif
} else {
}
else {
QMap<QString, QColor>::ConstIterator it = d->colormap.find(QString::fromLatin1(sReason));
if (it != d->colormap.end()) {
QColor color = it.value();
@@ -523,6 +525,16 @@ void PythonConsole::OnChange( Base::Subject<const char*> &rCaller,const char* sR
pythonSyntax->setColor(QString::fromLatin1(sReason), color);
}
}
if (strcmp(sReason, "PythonBlockCursor") == 0 ||
strcmp(sReason, "FontSize") == 0 ||
strcmp(sReason, "Font") == 0) {
bool block = hPrefGen->GetBool("PythonBlockCursor", false);
if (block)
setCursorWidth(QFontMetrics(font()).averageCharWidth());
else
setCursorWidth(1);
}
}
/**

View File

@@ -449,7 +449,9 @@ void TextEditor::OnChange(Base::Subject<const char*> &rCaller,const char* sReaso
QFont font(fontFamily, fontSize);
setFont(font);
} else {
lineNumberArea->setFont(font);
}
else {
QMap<QString, QColor>::ConstIterator it = d->colormap.find(QString::fromLatin1(sReason));
if (it != d->colormap.end()) {
QColor color = it.value();
@@ -475,12 +477,23 @@ void TextEditor::OnChange(Base::Subject<const char*> &rCaller,const char* sReaso
}
// Enables/Disables Line number in the Macro Editor from Edit->Preferences->Editor menu.
QRect cr = contentsRect();
bool show = hPrefGrp->GetBool( "EnableLineNumber", true );
if(show) {
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
} else {
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), 0, cr.height()));
if (strcmp(sReason, "EnableLineNumber") == 0) {
QRect cr = contentsRect();
bool show = hPrefGrp->GetBool("EnableLineNumber", true);
if(show)
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
else
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), 0, cr.height()));
}
if (strcmp(sReason, "EnableBlockCursor") == 0 ||
strcmp(sReason, "FontSize") == 0 ||
strcmp(sReason, "Font") == 0) {
bool block = hPrefGrp->GetBool("EnableBlockCursor", false);
if (block)
setCursorWidth(QFontMetrics(font()).averageCharWidth());
else
setCursorWidth(1);
}
}