Added user setting options.

test
cc9cii 10 years ago
parent 28048c0bf3
commit 8e49ccc2f4

@ -143,6 +143,10 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
minWidth->setDefaultValue (325);
minWidth->setRange (50, 10000);
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");

@ -12,6 +12,7 @@
#include "../../model/world/universalid.hpp"
#include "../../model/world/tablemimedata.hpp"
#include "../../model/settings/usersettings.hpp"
CSVWorld::ScriptEdit::ChangeLock::ChangeLock (ScriptEdit& edit) : mEdit (edit)
@ -30,7 +31,9 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli
: QPlainTextEdit (parent),
mDocument (document),
mWhiteListQoutes("^[a-z|_]{1}[a-z|0-9|_]{0,}$", Qt::CaseInsensitive),
mChangeLocked (0)
mChangeLocked (0),
mLineNumberArea(0),
mShowLineNum(false)
{
// setAcceptRichText (false);
setLineWrapMode (QPlainTextEdit::NoWrap);
@ -75,20 +78,36 @@ CSVWorld::ScriptEdit::ScriptEdit (const CSMDoc::Document& document, ScriptHighli
mUpdateTimer.setSingleShot (true);
// FIXME: make this configurable or provide a font selector dialogue
// FIXME: save QFontInfo somewhere before switching to a new one
// TODO: provide a font selector dialogue
std::string useMonoFont =
CSMSettings::UserSettings::instance().setting("window/mono-font", "true").toStdString();
if (useMonoFont == "true")
{
QFont font("Monospace");
font.setStyleHint(QFont::TypeWriter);
setFont(font);
}
// FIXME: make this configurable
lineNumberArea = new LineNumberArea(this);
mLineNumberArea = new LineNumberArea(this);
updateLineNumberAreaWidth(0);
connect(this, SIGNAL(blockCountChanged(int)), this, SLOT(updateLineNumberAreaWidth(int)));
connect(this, SIGNAL(updateRequest(QRect,int)), this, SLOT(updateLineNumberArea(QRect,int)));
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
{
@ -176,6 +195,9 @@ void CSVWorld::ScriptEdit::updateHighlighting()
int CSVWorld::ScriptEdit::lineNumberAreaWidth()
{
if(!mShowLineNum)
return 0;
int digits = 1;
int max = qMax(1, blockCount());
while (max >= 10)
@ -197,9 +219,9 @@ void CSVWorld::ScriptEdit::updateLineNumberAreaWidth(int /* newBlockCount */)
void CSVWorld::ScriptEdit::updateLineNumberArea(const QRect &rect, int dy)
{
if (dy)
lineNumberArea->scroll(0, dy);
mLineNumberArea->scroll(0, dy);
else
lineNumberArea->update(0, rect.y(), lineNumberArea->width(), rect.height());
mLineNumberArea->update(0, rect.y(), mLineNumberArea->width(), rect.height());
if (rect.contains(viewport()->rect()))
updateLineNumberAreaWidth(0);
@ -210,12 +232,12 @@ void CSVWorld::ScriptEdit::resizeEvent(QResizeEvent *e)
QPlainTextEdit::resizeEvent(e);
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)
{
QPainter painter(lineNumberArea);
QPainter painter(mLineNumberArea);
QTextBlock block = firstVisibleBlock();
int blockNumber = block.blockNumber();
@ -255,7 +277,7 @@ void CSVWorld::ScriptEdit::lineNumberAreaPaintEvent(QPaintEvent *event)
painter.setPen(Qt::black);
}
painter.setFont(newFont);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
painter.drawText(0, top, mLineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
painter.setFont(font);
}

@ -5,6 +5,7 @@
#include <QWidget>
#include <QVector>
#include <QTimer>
#include <QFont>
#include "../../model/world/universalid.hpp"
@ -47,7 +48,8 @@ namespace CSVWorld
int mChangeLocked;
ScriptHighlighter *mHighlighter;
QTimer mUpdateTimer;
QWidget *lineNumberArea;
bool mShowLineNum;
LineNumberArea *mLineNumberArea;
public:
@ -61,6 +63,7 @@ namespace CSVWorld
void lineNumberAreaPaintEvent(QPaintEvent *event);
int lineNumberAreaWidth();
void showLineNum(bool show);
protected:

@ -1,8 +1,11 @@
#include "scriptsubview.hpp"
#include <stdexcept>
#include <QStatusBar>
#include <QStackedLayout>
#include <QLabel>
#include "../../model/doc/document.hpp"
#include "../../model/world/universalid.hpp"
#include "../../model/world/data.hpp"
@ -13,9 +16,26 @@
#include "scriptedit.hpp"
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&> (
*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)),
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)

@ -4,6 +4,7 @@
#include "../doc/subview.hpp"
class QModelIndex;
class QLabel;
namespace CSMDoc
{
@ -27,6 +28,8 @@ namespace CSVWorld
CSMDoc::Document& mDocument;
CSMWorld::IdTable *mModel;
int mColumn;
QWidget *mBottom;
QLabel *mStatus;
public:
@ -36,6 +39,8 @@ namespace CSVWorld
virtual void useHint (const std::string& hint);
virtual void setStatusBar (bool show);
public slots:
void textChanged();
@ -43,6 +48,10 @@ namespace CSVWorld
void dataChanged (const QModelIndex& topLeft, const QModelIndex& bottomRight);
void rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end);
private slots:
void updateStatusBar();
};
}

Loading…
Cancel
Save