From a3903d374f8b82fb3bfe55281018828df8b8e9a6 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Thu, 7 Apr 2016 07:45:33 -0400 Subject: [PATCH 1/4] Update script editor tab width (Bug #3286) --- apps/opencs/view/world/scriptedit.cpp | 9 ++++++++- apps/opencs/view/world/scriptedit.hpp | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index d0146445a..a6689bf53 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -52,7 +52,7 @@ CSVWorld::ScriptEdit::ScriptEdit( mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive) { wrapLines(false); - setTabStopWidth (4); + setTabWidth(); setUndoRedoEnabled (false); // we use OpenCS-wide undo/redo instead mAllowedTypes < Date: Sat, 16 Apr 2016 20:43:10 -0400 Subject: [PATCH 2/4] Add setting for script editor tab width --- apps/opencs/model/prefs/state.cpp | 3 +++ apps/opencs/view/world/scriptedit.cpp | 9 ++++++--- apps/opencs/view/world/scriptedit.hpp | 3 ++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/apps/opencs/model/prefs/state.cpp b/apps/opencs/model/prefs/state.cpp index 70456ee1d..c70e71deb 100644 --- a/apps/opencs/model/prefs/state.cpp +++ b/apps/opencs/model/prefs/state.cpp @@ -136,6 +136,9 @@ void CSMPrefs::State::declare() declareBool ("wrap-lines", "Wrap Lines", false). setTooltip ("Wrap lines longer than width of script editor."); declareBool ("mono-font", "Use monospace font", true); + declareInt ("tab-width", "Tab Width", 4). + setTooltip ("Number of characters for tab width"). + setRange (1, 10); EnumValue warningsNormal ("Normal", "Report warnings as warning"); declareEnum ("warnings", "Warning Mode", warningsNormal). addValue ("Ignore", "Do not report warning"). diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index a6689bf53..39497ac1e 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -52,7 +52,7 @@ CSVWorld::ScriptEdit::ScriptEdit( mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive) { wrapLines(false); - setTabWidth(); + setTabWidth(4); setUndoRedoEnabled (false); // we use OpenCS-wide undo/redo instead mAllowedTypes <isTrue()); } + else if (*setting == "Scripts/tab-width") + { + setTabWidth(setting->toInt()); + } } void CSVWorld::ScriptEdit::idListChanged() diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 7a3f074e9..db2936a74 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -92,7 +92,8 @@ namespace CSVWorld bool stringNeedsQuote(const std::string& id) const; /// \brief Set tab width for script editor. - void setTabWidth(); + /// \param numCharacters Number of characters for tab width. + void setTabWidth(const int numCharacters); /// \brief Turn line wrapping in script editor on or off. /// \param wrap Whether or not to wrap lines. From 30493545f172334fb9b11396edaf0a69bd31a44e Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Sun, 17 Apr 2016 06:54:31 -0400 Subject: [PATCH 3/4] Update script editor tab width on font change --- apps/opencs/view/world/scriptedit.cpp | 13 ++++++++----- apps/opencs/view/world/scriptedit.hpp | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 39497ac1e..6dc0c2f0c 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -48,11 +48,12 @@ CSVWorld::ScriptEdit::ScriptEdit( mLineNumberArea(0), mDefaultFont(font()), mMonoFont(QFont("Monospace")), + mTabCharCount(4), mDocument(document), mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive) { wrapLines(false); - setTabWidth(4); + setTabWidth(); setUndoRedoEnabled (false); // we use OpenCS-wide undo/redo instead mAllowedTypes <isTrue() ? mMonoFont : mDefaultFont); + setTabWidth(); } else if (*setting == "Scripts/show-linenum") { @@ -233,7 +235,8 @@ void CSVWorld::ScriptEdit::settingChanged(const CSMPrefs::Setting *setting) } else if (*setting == "Scripts/tab-width") { - setTabWidth(setting->toInt()); + mTabCharCount = setting->toInt(); + setTabWidth(); } } diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index db2936a74..9d2062075 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -53,6 +53,7 @@ namespace CSVWorld LineNumberArea *mLineNumberArea; QFont mDefaultFont; QFont mMonoFont; + int mTabCharCount; protected: @@ -92,8 +93,7 @@ namespace CSVWorld bool stringNeedsQuote(const std::string& id) const; /// \brief Set tab width for script editor. - /// \param numCharacters Number of characters for tab width. - void setTabWidth(const int numCharacters); + void setTabWidth(); /// \brief Turn line wrapping in script editor on or off. /// \param wrap Whether or not to wrap lines. From e6ab3a4ba9038e3e3891beddee35e0f93d272776 Mon Sep 17 00:00:00 2001 From: Rob Cutmore Date: Sun, 17 Apr 2016 06:57:02 -0400 Subject: [PATCH 4/4] Remove unused CSVWorld::ScriptEdit::setMonoFont --- apps/opencs/view/world/scriptedit.cpp | 8 -------- apps/opencs/view/world/scriptedit.hpp | 1 - 2 files changed, 9 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 6dc0c2f0c..6f27d5656 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -121,14 +121,6 @@ void CSVWorld::ScriptEdit::showLineNum(bool show) } } -void CSVWorld::ScriptEdit::setMonoFont(bool show) -{ - if(show) - setFont(mMonoFont); - else - setFont(mDefaultFont); -} - bool CSVWorld::ScriptEdit::isChangeLocked() const { return mChangeLocked!=0; diff --git a/apps/opencs/view/world/scriptedit.hpp b/apps/opencs/view/world/scriptedit.hpp index 9d2062075..4977ed8e0 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -72,7 +72,6 @@ namespace CSVWorld void lineNumberAreaPaintEvent(QPaintEvent *event); int lineNumberAreaWidth(); void showLineNum(bool show); - void setMonoFont(bool show); protected: