mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-02-06 13:15:33 +00:00
Added user setting options.
This commit is contained in:
parent
28048c0bf3
commit
8e49ccc2f4
5 changed files with 96 additions and 19 deletions
|
@ -143,6 +143,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
|
||||||
minWidth->setDefaultValue (325);
|
minWidth->setDefaultValue (325);
|
||||||
minWidth->setRange (50, 10000);
|
minWidth->setRange (50, 10000);
|
||||||
minWidth->setToolTip ("Minimum width of subviews.");
|
minWidth->setToolTip ("Minimum width of subviews.");
|
||||||
|
|
||||||
|
Setting *monoFont = createSetting (Type_CheckBox, "mono-font", "Use monospace font");
|
||||||
|
monoFont->setDefaultValue ("true");
|
||||||
|
monoFont->setToolTip ("Whether to use monospaced fonts on script edit subview.");
|
||||||
}
|
}
|
||||||
|
|
||||||
declareSection ("records", "Records");
|
declareSection ("records", "Records");
|
||||||
|
@ -225,7 +229,7 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
|
||||||
Setting *autoDelete = createSetting (Type_CheckBox, "auto-delete", "Delete row from result table after a successful replace");
|
Setting *autoDelete = createSetting (Type_CheckBox, "auto-delete", "Delete row from result table after a successful replace");
|
||||||
autoDelete->setDefaultValue ("true");
|
autoDelete->setDefaultValue ("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
/******************************************************************
|
/******************************************************************
|
||||||
* There are three types of values:
|
* There are three types of values:
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
#include "../../model/world/tablemimedata.hpp"
|
#include "../../model/world/tablemimedata.hpp"
|
||||||
|
#include "../../model/settings/usersettings.hpp"
|
||||||
|
|
||||||
|
|
||||||
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
|
||||||
|
@ -30,7 +31,9 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli
|
||||||
: QPlainTextEdit (parent),
|
: QPlainTextEdit (parent),
|
||||||
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),
|
||||||
mChangeLocked (0)
|
mChangeLocked (0),
|
||||||
|
mLineNumberArea(0),
|
||||||
|
mShowLineNum(false)
|
||||||
{
|
{
|
||||||
// setAcceptRichText (false);
|
// setAcceptRichText (false);
|
||||||
setLineWrapMode (QPlainTextEdit::NoWrap);
|
setLineWrapMode (QPlainTextEdit::NoWrap);
|
||||||
|
@ -75,19 +78,35 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli
|
||||||
|
|
||||||
mUpdateTimer.setSingleShot (true);
|
mUpdateTimer.setSingleShot (true);
|
||||||
|
|
||||||
// FIXME: make this configurable or provide a font selector dialogue
|
// TODO: provide a font selector dialogue
|
||||||
// FIXME: save QFontInfo somewhere before switching to a new one
|
std::string useMonoFont =
|
||||||
QFont font("Monospace");
|
CSMSettings::UserSettings::instance().setting("window/mono-font", "true").toStdString();
|
||||||
font.setStyleHint(QFont::TypeWriter);
|
if (useMonoFont == "true")
|
||||||
setFont(font);
|
{
|
||||||
|
QFont font("Monospace");
|
||||||
|
font.setStyleHint(QFont::TypeWriter);
|
||||||
|
setFont(font);
|
||||||
|
}
|
||||||
|
|
||||||
// FIXME: make this configurable
|
mLineNumberArea = new LineNumberArea(this);
|
||||||
lineNumberArea = new LineNumberArea(this);
|
updateLineNumberAreaWidth(0);
|
||||||
|
|
||||||
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
|
||||||
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
|
||||||
|
|
||||||
updateLineNumberAreaWidth(0);
|
std::string showStatusBar =
|
||||||
|
CSMSettings::UserSettings::instance().settingValue("window/show-statusbar").toStdString();
|
||||||
|
|
||||||
|
showLineNum(showStatusBar == "true");
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptEdit::showLineNum(bool show)
|
||||||
|
{
|
||||||
|
if(show!=mShowLineNum)
|
||||||
|
{
|
||||||
|
mShowLineNum = show;
|
||||||
|
updateLineNumberAreaWidth(0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CSVWorld::ScriptEdit::isChangeLocked() const
|
bool CSVWorld::ScriptEdit::isChangeLocked() const
|
||||||
|
@ -176,6 +195,9 @@ void CSVWorld::ScriptEdit::updateHighlighting()
|
||||||
|
|
||||||
int CSVWorld::ScriptEdit::lineNumberAreaWidth()
|
int CSVWorld::ScriptEdit::lineNumberAreaWidth()
|
||||||
{
|
{
|
||||||
|
if(!mShowLineNum)
|
||||||
|
return 0;
|
||||||
|
|
||||||
int digits = 1;
|
int digits = 1;
|
||||||
int max = qMax(1, blockCount());
|
int max = qMax(1, blockCount());
|
||||||
while (max >= 10)
|
while (max >= 10)
|
||||||
|
@ -197,9 +219,9 @@ void CSVWorld::ScriptEdit::updateLineNumberAreaWidth(int /* newBlockCount */)
|
||||||
void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
|
void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
|
||||||
{
|
{
|
||||||
if (dy)
|
if (dy)
|
||||||
lineNumberArea->scroll(0, dy);
|
mLineNumberArea->scroll(0, dy);
|
||||||
else
|
else
|
||||||
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
|
mLineNumberArea->update(0, rect.y(), mLineNumberArea->width(), rect.height());
|
||||||
|
|
||||||
if (rect.contains(viewport()->rect()))
|
if (rect.contains(viewport()->rect()))
|
||||||
updateLineNumberAreaWidth(0);
|
updateLineNumberAreaWidth(0);
|
||||||
|
@ -210,12 +232,12 @@ void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
|
||||||
QPlainTextEdit::resizeEvent(e);
|
QPlainTextEdit::resizeEvent(e);
|
||||||
|
|
||||||
QRect cr = contentsRect();
|
QRect cr = contentsRect();
|
||||||
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
|
mLineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
|
void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||||
{
|
{
|
||||||
QPainter painter(lineNumberArea);
|
QPainter painter(mLineNumberArea);
|
||||||
|
|
||||||
QTextBlock block = firstVisibleBlock();
|
QTextBlock block = firstVisibleBlock();
|
||||||
int blockNumber = block.blockNumber();
|
int blockNumber = block.blockNumber();
|
||||||
|
@ -255,7 +277,7 @@ void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
|
||||||
painter.setPen(Qt::black);
|
painter.setPen(Qt::black);
|
||||||
}
|
}
|
||||||
painter.setFont(newFont);
|
painter.setFont(newFont);
|
||||||
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
|
painter.drawText(0, top, mLineNumberArea->width(), fontMetrics().height(),
|
||||||
Qt::AlignRight, number);
|
Qt::AlignRight, number);
|
||||||
painter.setFont(font);
|
painter.setFont(font);
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QFont>
|
||||||
|
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
|
|
||||||
|
@ -47,7 +48,8 @@ namespace CSVWorld
|
||||||
int mChangeLocked;
|
int mChangeLocked;
|
||||||
ScriptHighlighter *mHighlighter;
|
ScriptHighlighter *mHighlighter;
|
||||||
QTimer mUpdateTimer;
|
QTimer mUpdateTimer;
|
||||||
QWidget *lineNumberArea;
|
bool mShowLineNum;
|
||||||
|
LineNumberArea *mLineNumberArea;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -61,6 +63,7 @@ namespace CSVWorld
|
||||||
|
|
||||||
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
void lineNumberAreaPaintEvent(QPaintEvent *event);
|
||||||
int lineNumberAreaWidth();
|
int lineNumberAreaWidth();
|
||||||
|
void showLineNum(bool show);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
|
|
||||||
#include "scriptsubview.hpp"
|
#include "scriptsubview.hpp"
|
||||||
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#include <QStatusBar>
|
||||||
|
#include <QStackedLayout>
|
||||||
|
#include <QLabel>
|
||||||
|
|
||||||
#include "../../model/doc/document.hpp"
|
#include "../../model/doc/document.hpp"
|
||||||
#include "../../model/world/universalid.hpp"
|
#include "../../model/world/universalid.hpp"
|
||||||
#include "../../model/world/data.hpp"
|
#include "../../model/world/data.hpp"
|
||||||
|
@ -13,9 +16,26 @@
|
||||||
#include "scriptedit.hpp"
|
#include "scriptedit.hpp"
|
||||||
|
|
||||||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
: SubView (id), mDocument (document), mColumn (-1)
|
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mStatus(0)
|
||||||
{
|
{
|
||||||
setWidget (mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this));
|
QVBoxLayout *layout = new QVBoxLayout;
|
||||||
|
layout->setContentsMargins (QMargins (0, 0, 0, 0));
|
||||||
|
|
||||||
|
mBottom = new QWidget(this);
|
||||||
|
QStackedLayout *bottmLayout = new QStackedLayout(mBottom);
|
||||||
|
bottmLayout->setContentsMargins (0, 0, 0, 0);
|
||||||
|
QStatusBar *statusBar = new QStatusBar(mBottom);
|
||||||
|
mStatus = new QLabel(mBottom);
|
||||||
|
statusBar->addWidget (mStatus);
|
||||||
|
bottmLayout->addWidget (statusBar);
|
||||||
|
mBottom->setLayout (bottmLayout);
|
||||||
|
|
||||||
|
layout->addWidget (mBottom, 0);
|
||||||
|
layout->insertWidget (0, mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this), 2);
|
||||||
|
|
||||||
|
QWidget *widget = new QWidget;
|
||||||
|
widget->setLayout (layout);
|
||||||
|
setWidget (widget);
|
||||||
|
|
||||||
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
||||||
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
||||||
|
@ -40,6 +60,25 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
|
|
||||||
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
|
||||||
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
|
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
|
||||||
|
|
||||||
|
updateStatusBar();
|
||||||
|
connect(mEditor, SIGNAL(cursorPositionChanged()), this, SLOT(updateStatusBar()));
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptSubView::setStatusBar (bool show)
|
||||||
|
{
|
||||||
|
mEditor->showLineNum(show);
|
||||||
|
mBottom->setVisible(show);
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptSubView::updateStatusBar ()
|
||||||
|
{
|
||||||
|
std::ostringstream stream;
|
||||||
|
|
||||||
|
stream << "(" << mEditor->textCursor().blockNumber() + 1 << ", "
|
||||||
|
<< mEditor->textCursor().columnNumber() + 1 << ")";
|
||||||
|
|
||||||
|
mStatus->setText (QString::fromUtf8 (stream.str().c_str()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::setEditLock (bool locked)
|
void CSVWorld::ScriptSubView::setEditLock (bool locked)
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include "../doc/subview.hpp"
|
#include "../doc/subview.hpp"
|
||||||
|
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
|
class QLabel;
|
||||||
|
|
||||||
namespace CSMDoc
|
namespace CSMDoc
|
||||||
{
|
{
|
||||||
|
@ -27,6 +28,8 @@ namespace CSVWorld
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
CSMWorld::IdTable *mModel;
|
CSMWorld::IdTable *mModel;
|
||||||
int mColumn;
|
int mColumn;
|
||||||
|
QWidget *mBottom;
|
||||||
|
QLabel *mStatus;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -36,6 +39,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
virtual void useHint (const std::string& hint);
|
virtual void useHint (const std::string& hint);
|
||||||
|
|
||||||
|
virtual void setStatusBar (bool show);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
void textChanged();
|
void textChanged();
|
||||||
|
@ -43,6 +48,10 @@ namespace CSVWorld
|
||||||
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
|
||||||
|
|
||||||
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void updateStatusBar();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue