From 081f3ed263f5077be9e2853d6e5f1b2ec9e468aa Mon Sep 17 00:00:00 2001 From: cc9cii Date: Fri, 1 May 2015 06:08:04 +1000 Subject: [PATCH] Make font setting selection immediate. --- apps/opencs/view/world/scriptedit.cpp | 19 +++++++++++++------ apps/opencs/view/world/scriptedit.hpp | 3 +++ apps/opencs/view/world/scriptsubview.cpp | 18 ++++++++++-------- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/apps/opencs/view/world/scriptedit.cpp b/apps/opencs/view/world/scriptedit.cpp index 0909c00f9..b4f4234f1 100644 --- a/apps/opencs/view/world/scriptedit.cpp +++ b/apps/opencs/view/world/scriptedit.cpp @@ -33,7 +33,9 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive), mChangeLocked (0), mLineNumberArea(0), - mShowLineNum(false) + mShowLineNum(false), + mDefaultFont(font()), + mMonoFont(QFont("Monospace")) { // setAcceptRichText (false); setLineWrapMode (QPlainTextEdit::NoWrap); @@ -79,14 +81,11 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli mUpdateTimer.setSingleShot (true); // TODO: provide a font selector dialogue + mMonoFont.setStyleHint(QFont::TypeWriter); std::string useMonoFont = CSMSettings::UserSettings::instance().setting("script-editor/mono-font", "true").toStdString(); if (useMonoFont == "true") - { - QFont font("Monospace"); - font.setStyleHint(QFont::TypeWriter); - setFont(font); - } + setFont(mMonoFont); mLineNumberArea = new LineNumberArea(this); updateLineNumberAreaWidth(0); @@ -109,6 +108,14 @@ 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 3355d40c1..a19cee486 100644 --- a/apps/opencs/view/world/scriptedit.hpp +++ b/apps/opencs/view/world/scriptedit.hpp @@ -50,6 +50,8 @@ namespace CSVWorld QTimer mUpdateTimer; bool mShowLineNum; LineNumberArea *mLineNumberArea; + QFont mDefaultFont; + QFont mMonoFont; public: @@ -64,6 +66,7 @@ namespace CSVWorld void lineNumberAreaPaintEvent(QPaintEvent *event); int lineNumberAreaWidth(); void showLineNum(bool show); + void setMonoFont(bool show); protected: diff --git a/apps/opencs/view/world/scriptsubview.cpp b/apps/opencs/view/world/scriptsubview.cpp index c7ddcd82a..411eb3660 100644 --- a/apps/opencs/view/world/scriptsubview.cpp +++ b/apps/opencs/view/world/scriptsubview.cpp @@ -68,14 +68,16 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc: void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value) { - if (name != "script-editor/show-linenum") - return; - - std::string showLinenum = - CSMSettings::UserSettings::instance().settingValue("script-editor/show-linenum").toStdString(); - - mEditor->showLineNum(showLinenum == "true"); - mBottom->setVisible(showLinenum == "true"); + if (name == "script-editor/show-linenum") + { + std::string showLinenum = value.at(0).toStdString(); + mEditor->showLineNum(showLinenum == "true"); + mBottom->setVisible(showLinenum == "true"); + } + else if (name == "script-editor/mono-font") + { + mEditor->setMonoFont(value.at(0).toStdString() == "true"); + } } void CSVWorld::ScriptSubView::updateStatusBar ()