mirror of
https://github.com/OpenMW/openmw.git
synced 2025-04-02 03:06:41 +00:00
Update script editor tab width on font change
This commit is contained in:
parent
25d9b77d10
commit
30493545f1
2 changed files with 10 additions and 7 deletions
|
@ -48,11 +48,12 @@ CSVWorld::ScriptEdit::ScriptEdit(
|
||||||
mLineNumberArea(0),
|
mLineNumberArea(0),
|
||||||
mDefaultFont(font()),
|
mDefaultFont(font()),
|
||||||
mMonoFont(QFont("Monospace")),
|
mMonoFont(QFont("Monospace")),
|
||||||
|
mTabCharCount(4),
|
||||||
mDocument(document),
|
mDocument(document),
|
||||||
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive)
|
||||||
{
|
{
|
||||||
wrapLines(false);
|
wrapLines(false);
|
||||||
setTabWidth(4);
|
setTabWidth();
|
||||||
setUndoRedoEnabled (false); // we use OpenCS-wide undo/redo instead
|
setUndoRedoEnabled (false); // we use OpenCS-wide undo/redo instead
|
||||||
|
|
||||||
mAllowedTypes <<CSMWorld::UniversalId::Type_Journal
|
mAllowedTypes <<CSMWorld::UniversalId::Type_Journal
|
||||||
|
@ -194,10 +195,10 @@ bool CSVWorld::ScriptEdit::stringNeedsQuote (const std::string& id) const
|
||||||
return !(string.contains(mWhiteListQoutes));
|
return !(string.contains(mWhiteListQoutes));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::setTabWidth(const int numCharacters)
|
void CSVWorld::ScriptEdit::setTabWidth()
|
||||||
{
|
{
|
||||||
QFontMetrics metrics(mMonoFont);
|
// Set tab width to specified number of characters using current font.
|
||||||
setTabStopWidth(numCharacters * metrics.width(' '));
|
setTabStopWidth(mTabCharCount * fontMetrics().width(' '));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::wrapLines(bool wrap)
|
void CSVWorld::ScriptEdit::wrapLines(bool wrap)
|
||||||
|
@ -222,6 +223,7 @@ void CSVWorld::ScriptEdit::settingChanged(const CSMPrefs::Setting *setting)
|
||||||
else if (*setting == "Scripts/mono-font")
|
else if (*setting == "Scripts/mono-font")
|
||||||
{
|
{
|
||||||
setFont(setting->isTrue() ? mMonoFont : mDefaultFont);
|
setFont(setting->isTrue() ? mMonoFont : mDefaultFont);
|
||||||
|
setTabWidth();
|
||||||
}
|
}
|
||||||
else if (*setting == "Scripts/show-linenum")
|
else if (*setting == "Scripts/show-linenum")
|
||||||
{
|
{
|
||||||
|
@ -233,7 +235,8 @@ void CSVWorld::ScriptEdit::settingChanged(const CSMPrefs::Setting *setting)
|
||||||
}
|
}
|
||||||
else if (*setting == "Scripts/tab-width")
|
else if (*setting == "Scripts/tab-width")
|
||||||
{
|
{
|
||||||
setTabWidth(setting->toInt());
|
mTabCharCount = setting->toInt();
|
||||||
|
setTabWidth();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,6 +53,7 @@ namespace CSVWorld
|
||||||
LineNumberArea *mLineNumberArea;
|
LineNumberArea *mLineNumberArea;
|
||||||
QFont mDefaultFont;
|
QFont mDefaultFont;
|
||||||
QFont mMonoFont;
|
QFont mMonoFont;
|
||||||
|
int mTabCharCount;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
@ -92,8 +93,7 @@ namespace CSVWorld
|
||||||
bool stringNeedsQuote(const std::string& id) const;
|
bool stringNeedsQuote(const std::string& id) const;
|
||||||
|
|
||||||
/// \brief Set tab width for script editor.
|
/// \brief Set tab width for script editor.
|
||||||
/// \param numCharacters Number of characters for tab width.
|
void setTabWidth();
|
||||||
void setTabWidth(const int numCharacters);
|
|
||||||
|
|
||||||
/// \brief Turn line wrapping in script editor on or off.
|
/// \brief Turn line wrapping in script editor on or off.
|
||||||
/// \param wrap Whether or not to wrap lines.
|
/// \param wrap Whether or not to wrap lines.
|
||||||
|
|
Loading…
Reference in a new issue