2012-11-22 12:30:02 +00:00
|
|
|
#include "view.hpp"
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
#include <sstream>
|
2012-11-26 11:29:22 +00:00
|
|
|
#include <stdexcept>
|
2012-11-22 13:10:23 +00:00
|
|
|
|
|
|
|
#include <QCloseEvent>
|
2012-11-22 13:49:58 +00:00
|
|
|
#include <QMenuBar>
|
2012-11-24 12:17:21 +00:00
|
|
|
#include <QMdiArea>
|
2013-02-23 03:53:32 +00:00
|
|
|
#include <QDockWidget>
|
2012-11-22 13:10:23 +00:00
|
|
|
|
2012-11-22 14:54:31 +00:00
|
|
|
#include "../../model/doc/document.hpp"
|
2012-12-11 12:22:43 +00:00
|
|
|
#include "../world/subviews.hpp"
|
2012-12-11 14:35:47 +00:00
|
|
|
#include "../tools/subviews.hpp"
|
2013-05-10 15:00:58 +00:00
|
|
|
#include "../settings/usersettingsdialog.hpp"
|
2012-11-22 13:10:23 +00:00
|
|
|
#include "viewmanager.hpp"
|
2012-11-23 11:20:35 +00:00
|
|
|
#include "operations.hpp"
|
2012-12-11 12:22:43 +00:00
|
|
|
#include "subview.hpp"
|
2012-11-22 13:10:23 +00:00
|
|
|
|
|
|
|
void CSVDoc::View::closeEvent (QCloseEvent *event)
|
|
|
|
{
|
|
|
|
if (!mViewManager.closeRequest (this))
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
void CSVDoc::View::setupFileMenu()
|
|
|
|
{
|
|
|
|
QMenu *file = menuBar()->addMenu (tr ("&File"));
|
|
|
|
|
2012-11-23 13:05:49 +00:00
|
|
|
QAction *new_ = new QAction (tr ("New"), this);
|
|
|
|
connect (new_, SIGNAL (triggered()), this, SIGNAL (newDocumentRequest()));
|
|
|
|
file->addAction (new_);
|
|
|
|
|
2013-02-05 21:06:36 +00:00
|
|
|
QAction *open = new QAction (tr ("&Open"), this);
|
2013-02-02 15:14:58 +00:00
|
|
|
connect (open, SIGNAL (triggered()), this, SIGNAL (loadDocumentRequest()));
|
|
|
|
file->addAction (open);
|
|
|
|
|
2012-11-23 09:52:46 +00:00
|
|
|
mSave = new QAction (tr ("&Save"), this);
|
|
|
|
connect (mSave, SIGNAL (triggered()), this, SLOT (save()));
|
|
|
|
file->addAction (mSave);
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 14:54:31 +00:00
|
|
|
void CSVDoc::View::setupEditMenu()
|
|
|
|
{
|
|
|
|
QMenu *edit = menuBar()->addMenu (tr ("&Edit"));
|
|
|
|
|
2012-11-22 23:51:04 +00:00
|
|
|
mUndo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo"));
|
|
|
|
mUndo->setShortcuts (QKeySequence::Undo);
|
|
|
|
edit->addAction (mUndo);
|
2012-11-22 14:54:31 +00:00
|
|
|
|
2012-11-22 23:51:04 +00:00
|
|
|
mRedo= mDocument->getUndoStack().createRedoAction (this, tr("&Redo"));
|
|
|
|
mRedo->setShortcuts (QKeySequence::Redo);
|
|
|
|
edit->addAction (mRedo);
|
2013-05-11 12:40:10 +00:00
|
|
|
|
|
|
|
QAction *userSettings = new QAction (tr ("&Preferences"), this);
|
|
|
|
connect (userSettings, SIGNAL (triggered()), this, SLOT (showUserSettings()));
|
|
|
|
edit->addAction (userSettings);
|
2012-11-22 14:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::setupViewMenu()
|
2012-11-22 13:49:58 +00:00
|
|
|
{
|
|
|
|
QMenu *view = menuBar()->addMenu (tr ("&View"));
|
|
|
|
|
|
|
|
QAction *newWindow = new QAction (tr ("&New View"), this);
|
|
|
|
connect (newWindow, SIGNAL (triggered()), this, SLOT (newView()));
|
|
|
|
view->addAction (newWindow);
|
|
|
|
}
|
|
|
|
|
2012-11-23 12:15:45 +00:00
|
|
|
void CSVDoc::View::setupWorldMenu()
|
|
|
|
{
|
|
|
|
QMenu *world = menuBar()->addMenu (tr ("&World"));
|
|
|
|
|
2012-11-26 11:29:22 +00:00
|
|
|
QAction *globals = new QAction (tr ("Globals"), this);
|
|
|
|
connect (globals, SIGNAL (triggered()), this, SLOT (addGlobalsSubView()));
|
|
|
|
world->addAction (globals);
|
|
|
|
|
2013-02-08 08:58:19 +00:00
|
|
|
QAction *gmsts = new QAction (tr ("Game settings"), this);
|
|
|
|
connect (gmsts, SIGNAL (triggered()), this, SLOT (addGmstsSubView()));
|
|
|
|
world->addAction (gmsts);
|
|
|
|
|
2012-11-23 12:15:45 +00:00
|
|
|
mVerify = new QAction (tr ("&Verify"), this);
|
|
|
|
connect (mVerify, SIGNAL (triggered()), this, SLOT (verify()));
|
|
|
|
world->addAction (mVerify);
|
|
|
|
}
|
|
|
|
|
2012-11-22 14:54:31 +00:00
|
|
|
void CSVDoc::View::setupUi()
|
|
|
|
{
|
2012-11-22 23:36:01 +00:00
|
|
|
setupFileMenu();
|
2012-11-22 14:54:31 +00:00
|
|
|
setupEditMenu();
|
|
|
|
setupViewMenu();
|
2012-11-23 12:15:45 +00:00
|
|
|
setupWorldMenu();
|
2012-11-22 14:54:31 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
void CSVDoc::View::updateTitle()
|
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
2012-11-23 13:05:49 +00:00
|
|
|
stream << mDocument->getName();
|
2012-11-22 14:09:04 +00:00
|
|
|
|
2012-12-08 13:44:03 +00:00
|
|
|
if (mDocument->getState() & CSMDoc::State_Modified)
|
2012-11-22 22:42:17 +00:00
|
|
|
stream << " *";
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
if (mViewTotal>1)
|
|
|
|
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
|
|
|
|
|
|
|
|
setWindowTitle (stream.str().c_str());
|
|
|
|
}
|
|
|
|
|
2012-11-22 23:51:04 +00:00
|
|
|
void CSVDoc::View::updateActions()
|
|
|
|
{
|
2012-12-08 13:44:03 +00:00
|
|
|
bool editing = !(mDocument->getState() & CSMDoc::State_Locked);
|
2012-11-22 23:51:04 +00:00
|
|
|
|
|
|
|
for (std::vector<QAction *>::iterator iter (mEditingActions.begin()); iter!=mEditingActions.end(); ++iter)
|
|
|
|
(*iter)->setEnabled (editing);
|
|
|
|
|
|
|
|
mUndo->setEnabled (editing & mDocument->getUndoStack().canUndo());
|
|
|
|
mRedo->setEnabled (editing & mDocument->getUndoStack().canRedo());
|
2012-11-23 09:52:46 +00:00
|
|
|
|
2012-12-08 13:44:03 +00:00
|
|
|
mSave->setEnabled (!(mDocument->getState() & CSMDoc::State_Saving));
|
|
|
|
mVerify->setEnabled (!(mDocument->getState() & CSMDoc::State_Verifying));
|
2012-11-22 23:51:04 +00:00
|
|
|
}
|
|
|
|
|
2013-02-23 03:53:32 +00:00
|
|
|
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews, QMainWindow *viewParent)
|
|
|
|
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews), QMainWindow (viewParent)
|
2012-11-22 12:30:02 +00:00
|
|
|
{
|
2012-11-24 12:17:21 +00:00
|
|
|
setDockOptions (QMainWindow::AllowNestedDocks);
|
|
|
|
|
|
|
|
resize (300, 300); /// \todo get default size from settings and set reasonable minimal size
|
2012-11-22 14:09:04 +00:00
|
|
|
|
2013-02-23 03:53:32 +00:00
|
|
|
mSubViewWindow = new QMainWindow();
|
|
|
|
setCentralWidget (mSubViewWindow);
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
mOperations = new Operations;
|
|
|
|
addDockWidget (Qt::BottomDockWidgetArea, mOperations);
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
updateTitle();
|
2012-11-22 13:49:58 +00:00
|
|
|
|
|
|
|
setupUi();
|
2012-11-26 11:29:22 +00:00
|
|
|
|
2012-12-11 12:22:43 +00:00
|
|
|
CSVWorld::addSubViewFactories (mSubViewFactory);
|
2012-12-11 14:35:47 +00:00
|
|
|
CSVTools::addSubViewFactories (mSubViewFactory);
|
2013-02-23 03:53:32 +00:00
|
|
|
|
|
|
|
connect (mOperations, SIGNAL (abortOperation (int)), this, SLOT (abortOperation (int)));
|
2012-11-26 11:29:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CSVDoc::View::~View()
|
|
|
|
{
|
2012-11-22 13:10:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const CSMDoc::Document *CSVDoc::View::getDocument() const
|
|
|
|
{
|
|
|
|
return mDocument;
|
|
|
|
}
|
|
|
|
|
|
|
|
CSMDoc::Document *CSVDoc::View::getDocument()
|
|
|
|
{
|
|
|
|
return mDocument;
|
2012-11-22 13:49:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
void CSVDoc::View::setIndex (int viewIndex, int totalViews)
|
|
|
|
{
|
|
|
|
mViewIndex = viewIndex;
|
|
|
|
mViewTotal = totalViews;
|
|
|
|
updateTitle();
|
|
|
|
}
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
void CSVDoc::View::updateDocumentState()
|
|
|
|
{
|
|
|
|
updateTitle();
|
2012-11-22 23:51:04 +00:00
|
|
|
updateActions();
|
2012-11-23 11:20:35 +00:00
|
|
|
|
|
|
|
static const int operations[] =
|
|
|
|
{
|
2012-12-08 13:44:03 +00:00
|
|
|
CSMDoc::State_Saving, CSMDoc::State_Verifying,
|
2012-11-23 11:20:35 +00:00
|
|
|
-1 // end marker
|
|
|
|
};
|
|
|
|
|
|
|
|
int state = mDocument->getState() ;
|
|
|
|
|
|
|
|
for (int i=0; operations[i]!=-1; ++i)
|
|
|
|
if (!(state & operations[i]))
|
2013-02-23 03:53:32 +00:00
|
|
|
mOperations->quitOperation (operations[i]);
|
2012-11-30 12:58:10 +00:00
|
|
|
|
2012-12-11 12:22:43 +00:00
|
|
|
QList<CSVDoc::SubView *> subViews = findChildren<CSVDoc::SubView *>();
|
2012-11-30 12:58:10 +00:00
|
|
|
|
2012-12-11 12:22:43 +00:00
|
|
|
for (QList<CSVDoc::SubView *>::iterator iter (subViews.begin()); iter!=subViews.end(); ++iter)
|
2012-12-08 13:44:03 +00:00
|
|
|
(*iter)->setEditLock (state & CSMDoc::State_Locked);
|
2012-11-22 22:42:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-23 11:20:35 +00:00
|
|
|
void CSVDoc::View::updateProgress (int current, int max, int type, int threads)
|
2012-11-23 09:25:34 +00:00
|
|
|
{
|
2012-11-23 11:20:35 +00:00
|
|
|
mOperations->setProgress (current, max, type, threads);
|
2012-11-23 09:25:34 +00:00
|
|
|
}
|
|
|
|
|
2012-11-24 12:17:21 +00:00
|
|
|
void CSVDoc::View::addSubView (const CSMWorld::UniversalId& id)
|
|
|
|
{
|
|
|
|
/// \todo add an user setting for limiting the number of sub views per top level view. Automatically open a new top level view if this
|
|
|
|
/// number is exceeded
|
|
|
|
|
|
|
|
/// \todo if the sub view limit setting is one, the sub view title bar should be hidden and the text in the main title bar adjusted
|
|
|
|
/// accordingly
|
|
|
|
|
|
|
|
/// \todo add an user setting to reuse sub views (on a per document basis or on a per top level view basis)
|
|
|
|
|
2012-12-11 12:22:43 +00:00
|
|
|
SubView *view = mSubViewFactory.makeSubView (id, *mDocument);
|
2013-02-23 03:53:32 +00:00
|
|
|
mSubViewWindow->addDockWidget (Qt::TopDockWidgetArea, view);
|
2012-12-12 21:36:20 +00:00
|
|
|
|
|
|
|
connect (view, SIGNAL (focusId (const CSMWorld::UniversalId&)), this,
|
|
|
|
SLOT (addSubView (const CSMWorld::UniversalId&)));
|
|
|
|
|
2012-11-24 12:17:21 +00:00
|
|
|
view->show();
|
|
|
|
}
|
|
|
|
|
2012-11-22 13:49:58 +00:00
|
|
|
void CSVDoc::View::newView()
|
|
|
|
{
|
|
|
|
mViewManager.addView (mDocument);
|
2012-11-22 15:00:23 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 23:36:01 +00:00
|
|
|
void CSVDoc::View::save()
|
|
|
|
{
|
|
|
|
mDocument->save();
|
2012-11-23 12:15:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::verify()
|
|
|
|
{
|
2012-12-11 14:35:47 +00:00
|
|
|
addSubView (mDocument->verify());
|
2012-11-24 12:17:21 +00:00
|
|
|
}
|
|
|
|
|
2012-11-26 11:29:22 +00:00
|
|
|
void CSVDoc::View::addGlobalsSubView()
|
2012-11-24 12:17:21 +00:00
|
|
|
{
|
2012-11-26 11:29:22 +00:00
|
|
|
addSubView (CSMWorld::UniversalId::Type_Globals);
|
2013-02-08 08:58:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::addGmstsSubView()
|
|
|
|
{
|
|
|
|
addSubView (CSMWorld::UniversalId::Type_Gmsts);
|
2013-02-23 03:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::abortOperation (int type)
|
|
|
|
{
|
|
|
|
mDocument->abortOperation (type);
|
|
|
|
updateActions();
|
|
|
|
}
|
|
|
|
|
|
|
|
QDockWidget *CSVDoc::View::getOperations() const
|
|
|
|
{
|
|
|
|
return mOperations;
|
|
|
|
}
|
2013-05-08 01:33:42 +00:00
|
|
|
|
|
|
|
void CSVDoc::View::showUserSettings()
|
|
|
|
{
|
2013-05-11 10:55:46 +00:00
|
|
|
CSVSettings::UserSettingsDialog *settingsDialog = new CSVSettings::UserSettingsDialog(this);
|
2013-05-08 01:33:42 +00:00
|
|
|
|
|
|
|
connect (settingsDialog, SIGNAL (signalUpdateEditorSetting (const QString &, const QString &)),
|
|
|
|
this, SLOT (slotUpdateEditorSetting (const QString &, const QString &)) );
|
|
|
|
|
|
|
|
settingsDialog->show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::slotUpdateEditorSetting(const QString &settingName, const QString &settingValue)
|
|
|
|
{
|
|
|
|
static QString lastValue = "";
|
|
|
|
|
|
|
|
if (lastValue != settingValue)
|
|
|
|
{
|
2013-05-11 10:55:46 +00:00
|
|
|
//evaluate settingName against tokens to determine which function to call to update Editor application.
|
2013-05-08 01:33:42 +00:00
|
|
|
|
|
|
|
lastValue = settingValue;
|
|
|
|
}
|
|
|
|
}
|