added user settings option to toggle toolbars in single-record subviews

sceneinput
Marc Zinnschlag 10 years ago
parent 749eff5259
commit fc6c14614b

@ -217,6 +217,12 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
jumpToAdded->setDeclaredValues (jumpValues);
}
declareSection ("dialogues", "ID Dialogues");
{
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
toolbar->setDefaultValue ("true");
}
declareSection ("report-input", "Reports");
{
QString none ("None");
@ -310,6 +316,9 @@ void CSMSettings::UserSettings::buildSettingModelDefaults()
"<li>Strict: Promote warning to an error</li>"
"</ul>");
Setting *toolbar = createSetting (Type_CheckBox, "toolbar", "Show toolbar");
toolbar->setDefaultValue ("true");
Setting *formatInt = createSetting (Type_LineEdit, "colour-int", "Highlight Colour: Int");
formatInt->setDefaultValues (QStringList() << "Dark magenta");
formatInt->setToolTip ("(Default: Green) Use one of the following formats:" + tooltip);

@ -31,6 +31,7 @@
#include "../../model/world/idtree.hpp"
#include "../../model/world/commands.hpp"
#include "../../model/doc/document.hpp"
#include "../../model/settings/usersettings.hpp"
#include "../widget/coloreditor.hpp"
#include "../widget/droplineedit.hpp"
@ -66,7 +67,7 @@ void CSVWorld::NotEditableSubDelegate::setEditorData (QWidget* editor, const QMo
CSMWorld::Columns::ColumnId columnId = static_cast<CSMWorld::Columns::ColumnId> (
mTable->getColumnId (index.column()));
if (QVariant::String == v.type())
{
label->setText(v.toString());
@ -75,7 +76,7 @@ void CSVWorld::NotEditableSubDelegate::setEditorData (QWidget* editor, const QMo
{
int data = v.toInt();
std::vector<std::string> enumNames (CSMWorld::Columns::getEnums (columnId));
label->setText(QString::fromUtf8(enumNames.at(data).c_str()));
}
else
@ -324,11 +325,11 @@ CSVWorld::IdContextMenu::IdContextMenu(QWidget *widget, CSMWorld::ColumnBase::Di
Q_ASSERT(mWidget != NULL);
Q_ASSERT(CSMWorld::ColumnBase::isId(display));
Q_ASSERT(mIdType != CSMWorld::UniversalId::Type_None);
mWidget->setContextMenuPolicy(Qt::CustomContextMenu);
connect(mWidget,
SIGNAL(customContextMenuRequested(const QPoint &)),
this,
connect(mWidget,
SIGNAL(customContextMenuRequested(const QPoint &)),
this,
SLOT(showContextMenu(const QPoint &)));
mEditIdAction = new QAction(this);
@ -352,7 +353,7 @@ void CSVWorld::IdContextMenu::excludeId(const std::string &id)
QString CSVWorld::IdContextMenu::getWidgetValue() const
{
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget);
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(mWidget);
QLabel *label = qobject_cast<QLabel *>(mWidget);
QString value = "";
@ -411,7 +412,7 @@ void CSVWorld::IdContextMenu::showContextMenu(const QPoint &pos)
{
removeEditIdActionFromMenu();
}
if (!mContextMenu->actions().isEmpty())
{
mContextMenu->exec(mWidget->mapToGlobal(pos));
@ -588,9 +589,9 @@ void CSVWorld::EditWidget::remake(int row)
tablesLayout->addWidget(label);
tablesLayout->addWidget(table);
connect(table,
SIGNAL(editRequest(const CSMWorld::UniversalId &, const std::string &)),
this,
connect(table,
SIGNAL(editRequest(const CSMWorld::UniversalId &, const std::string &)),
this,
SIGNAL(editIdRequest(const CSMWorld::UniversalId &, const std::string &)));
}
else if (!(flags & CSMWorld::ColumnBase::Flag_Dialogue_List))
@ -830,9 +831,28 @@ void CSVWorld::SimpleDialogueSubView::updateCurrentId()
}
void CSVWorld::DialogueSubView::addButtonBar()
{
if (mButtons)
return;
mButtons = new RecordButtonBar (getUniversalId(), getTable(), mBottom,
&getCommandDispatcher(), this);
getMainLayout().insertWidget (1, mButtons);
// connections
connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview()));
connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord()));
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
}
CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id,
CSMDoc::Document& document, const CreatorFactoryBase& creatorFactory, bool sorting)
: SimpleDialogueSubView (id, document)
: SimpleDialogueSubView (id, document), mButtons (0)
{
// bottom box
mBottom = new TableBottomBox (creatorFactory, document, id, this);
@ -843,32 +863,44 @@ CSVWorld::DialogueSubView::DialogueSubView (const CSMWorld::UniversalId& id,
this, SLOT (requestFocus (const std::string&)));
// button bar
mButtons = new RecordButtonBar (id, getTable(), mBottom,
&getCommandDispatcher(), this);
if (CSMSettings::UserSettings::instance().setting ("dialogues/toolbar", QString("true")) == "true")
addButtonBar();
// layout
getMainLayout().addWidget (mButtons);
getMainLayout().addWidget (mBottom);
// connections
connect (mButtons, SIGNAL (showPreview()), this, SLOT (showPreview()));
connect (mButtons, SIGNAL (viewRecord()), this, SLOT (viewRecord()));
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
}
void CSVWorld::DialogueSubView::setEditLock (bool locked)
{
SimpleDialogueSubView::setEditLock (locked);
mButtons->setEditLock (locked);
if (mButtons)
mButtons->setEditLock (locked);
}
void CSVWorld::DialogueSubView::updateUserSetting (const QString& name, const QStringList& value)
{
SimpleDialogueSubView::updateUserSetting (name, value);
mButtons->updateUserSetting (name, value);
if (name=="dialogues/toolbar")
{
if (value.at(0)==QString ("true"))
{
addButtonBar();
}
else
{
if (mButtons)
{
getMainLayout().removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
}
}
if (mButtons)
mButtons->updateUserSetting (name, value);
}
void CSVWorld::DialogueSubView::showPreview ()
@ -908,7 +940,7 @@ void CSVWorld::DialogueSubView::switchToRow (int row)
setUniversalId (CSMWorld::UniversalId (type, id));
updateCurrentId();
getEditWidget().remake (row);
int stateColumn = getTable().findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
@ -923,5 +955,5 @@ void CSVWorld::DialogueSubView::requestFocus (const std::string& id)
QModelIndex index = getTable().getModelIndex (id, 0);
if (index.isValid())
switchToRow (index.row());
switchToRow (index.row());
}

@ -195,8 +195,8 @@ namespace CSVWorld
CSMDoc::Document& mDocument;
std::vector<CSMWorld::NestedTableProxyModel*> mNestedModels; //Plain, raw C pointers, deleted in the dtor
void createEditorContextMenu(QWidget *editor,
CSMWorld::ColumnBase::Display display,
void createEditorContextMenu(QWidget *editor,
CSMWorld::ColumnBase::Display display,
int currentRow) const;
public:
@ -236,7 +236,7 @@ namespace CSVWorld
void updateCurrentId();
bool isLocked() const;
public:
SimpleDialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
@ -256,10 +256,14 @@ namespace CSVWorld
class DialogueSubView : public SimpleDialogueSubView
{
Q_OBJECT
TableBottomBox* mBottom;
RecordButtonBar *mButtons;
private:
void addButtonBar();
public:
DialogueSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document,
@ -268,14 +272,14 @@ namespace CSVWorld
virtual void setEditLock (bool locked);
virtual void updateUserSetting (const QString& name, const QStringList& value);
private slots:
void showPreview();
void viewRecord();
void switchToRow (int row);
void switchToRow (int row);
void requestFocus (const std::string& id);
};

@ -17,19 +17,32 @@
#include "scriptedit.hpp"
#include "recordbuttonbar.hpp"
void CSVWorld::ScriptSubView::addButtonBar()
{
if (mButtons)
return;
mButtons = new RecordButtonBar (getUniversalId(), *mModel, 0, &mCommandDispatcher, this);
mLayout.insertWidget (1, mButtons);
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
}
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mStatus(0),
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mStatus(0), mButtons (0),
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
{
std::vector<std::string> selection (1, id.getId());
mCommandDispatcher.setSelection (selection);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget (mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this), 2);
mLayout.addWidget (mEditor = new ScriptEdit (mDocument, ScriptHighlighter::Mode_General, this), 2);
QWidget *widget = new QWidget (this);;
widget->setLayout (layout);
widget->setLayout (&mLayout);
setWidget (widget);
mModel = &dynamic_cast<CSMWorld::IdTable&> (
@ -49,9 +62,8 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
mEditor->setPlainText (mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString());
// buttons
mButtons = new RecordButtonBar (id, *mModel, 0, &mCommandDispatcher, this);
layout->addWidget (mButtons);
if (CSMSettings::UserSettings::instance().setting ("script-editor/toolbar", QString("true")) == "true")
addButtonBar();
// status bar
QStatusBar *statusBar = new QStatusBar(mBottom);
@ -64,7 +76,7 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
bottmLayout->addWidget (statusBar);
mBottom->setLayout (bottmLayout);
layout->addWidget (mBottom, 0);
mLayout.addWidget (mBottom, 0);
// signals
connect (mEditor, SIGNAL (textChanged()), this, SLOT (textChanged()));
@ -75,11 +87,6 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
connect (mModel, SIGNAL (rowsAboutToBeRemoved (const QModelIndex&, int, int)),
this, SLOT (rowsAboutToBeRemoved (const QModelIndex&, int, int)));
connect (mButtons, SIGNAL (switchToRow (int)), this, SLOT (switchToRow (int)));
connect (this, SIGNAL (universalIdChanged (const CSMWorld::UniversalId&)),
mButtons, SLOT (universalIdChanged (const CSMWorld::UniversalId&)));
updateStatusBar();
connect(mEditor, SIGNAL(cursorPositionChanged()), this, SLOT(updateStatusBar()));
}
@ -88,16 +95,33 @@ void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStr
{
if (name == "script-editor/show-linenum")
{
std::string showLinenum = value.at(0).toStdString();
std::string showLinenum = value.at(0).toUtf8().constData();
mEditor->showLineNum(showLinenum == "true");
mBottom->setVisible(showLinenum == "true");
}
else if (name == "script-editor/mono-font")
{
mEditor->setMonoFont(value.at(0).toStdString() == "true");
mEditor->setMonoFont (value.at(0)==QString ("true"));
}
else if (name=="script-editor/toolbar")
{
if (value.at(0)==QString ("true"))
{
addButtonBar();
}
else
{
if (mButtons)
{
mLayout.removeWidget (mButtons);
delete mButtons;
mButtons = 0;
}
}
}
mButtons->updateUserSetting (name, value);
if (mButtons)
mButtons->updateUserSetting (name, value);
}
void CSVWorld::ScriptSubView::updateStatusBar ()
@ -113,7 +137,10 @@ void CSVWorld::ScriptSubView::updateStatusBar ()
void CSVWorld::ScriptSubView::setEditLock (bool locked)
{
mEditor->setReadOnly (locked);
mButtons->setEditLock (locked);
if (mButtons)
mButtons->setEditLock (locked);
mCommandDispatcher.setEditLock (locked);
}

@ -1,12 +1,15 @@
#ifndef CSV_WORLD_SCRIPTSUBVIEW_H
#define CSV_WORLD_SCRIPTSUBVIEW_H
#include <QVBoxLayout>
#include "../../model/world/commanddispatcher.hpp"
#include "../doc/subview.hpp"
class QModelIndex;
class QLabel;
class QVBoxLayout;
namespace CSMDoc
{
@ -35,6 +38,11 @@ namespace CSVWorld
QLabel *mStatus;
RecordButtonBar *mButtons;
CSMWorld::CommandDispatcher mCommandDispatcher;
QVBoxLayout mLayout;
private:
void addButtonBar();
public:

Loading…
Cancel
Save