mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-11 00:39:59 +00:00
179 lines
4.3 KiB
C++
179 lines
4.3 KiB
C++
|
|
#include "view.hpp"
|
|
|
|
#include <sstream>
|
|
|
|
#include <QCloseEvent>
|
|
#include <QMenuBar>
|
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
#include "viewmanager.hpp"
|
|
#include "operations.hpp"
|
|
|
|
void CSVDoc::View::closeEvent (QCloseEvent *event)
|
|
{
|
|
if (!mViewManager.closeRequest (this))
|
|
event->ignore();
|
|
}
|
|
|
|
void CSVDoc::View::setupFileMenu()
|
|
{
|
|
QMenu *file = menuBar()->addMenu (tr ("&File"));
|
|
|
|
QAction *new_ = new QAction (tr ("New"), this);
|
|
connect (new_, SIGNAL (triggered()), this, SIGNAL (newDocumentRequest()));
|
|
file->addAction (new_);
|
|
|
|
mSave = new QAction (tr ("&Save"), this);
|
|
connect (mSave, SIGNAL (triggered()), this, SLOT (save()));
|
|
file->addAction (mSave);
|
|
}
|
|
|
|
void CSVDoc::View::setupEditMenu()
|
|
{
|
|
QMenu *edit = menuBar()->addMenu (tr ("&Edit"));
|
|
|
|
mUndo = mDocument->getUndoStack().createUndoAction (this, tr("&Undo"));
|
|
mUndo->setShortcuts (QKeySequence::Undo);
|
|
edit->addAction (mUndo);
|
|
|
|
mRedo= mDocument->getUndoStack().createRedoAction (this, tr("&Redo"));
|
|
mRedo->setShortcuts (QKeySequence::Redo);
|
|
edit->addAction (mRedo);
|
|
|
|
// test
|
|
QAction *test = new QAction (tr ("&Test Command"), this);
|
|
connect (test, SIGNAL (triggered()), this, SLOT (test()));
|
|
edit->addAction (test);
|
|
mEditingActions.push_back (test);
|
|
}
|
|
|
|
void CSVDoc::View::setupViewMenu()
|
|
{
|
|
QMenu *view = menuBar()->addMenu (tr ("&View"));
|
|
|
|
QAction *newWindow = new QAction (tr ("&New View"), this);
|
|
connect (newWindow, SIGNAL (triggered()), this, SLOT (newView()));
|
|
view->addAction (newWindow);
|
|
}
|
|
|
|
void CSVDoc::View::setupWorldMenu()
|
|
{
|
|
QMenu *world = menuBar()->addMenu (tr ("&World"));
|
|
|
|
mVerify = new QAction (tr ("&Verify"), this);
|
|
connect (mVerify, SIGNAL (triggered()), this, SLOT (verify()));
|
|
world->addAction (mVerify);
|
|
}
|
|
|
|
void CSVDoc::View::setupUi()
|
|
{
|
|
setupFileMenu();
|
|
setupEditMenu();
|
|
setupViewMenu();
|
|
setupWorldMenu();
|
|
}
|
|
|
|
void CSVDoc::View::updateTitle()
|
|
{
|
|
std::ostringstream stream;
|
|
|
|
stream << mDocument->getName();
|
|
|
|
if (mDocument->getState() & CSMDoc::Document::State_Modified)
|
|
stream << " *";
|
|
|
|
if (mViewTotal>1)
|
|
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
|
|
|
|
setWindowTitle (stream.str().c_str());
|
|
}
|
|
|
|
void CSVDoc::View::updateActions()
|
|
{
|
|
bool editing = !(mDocument->getState() & CSMDoc::Document::State_Locked);
|
|
|
|
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());
|
|
|
|
mSave->setEnabled (!(mDocument->getState() & CSMDoc::Document::State_Saving));
|
|
mVerify->setEnabled (!(mDocument->getState() & CSMDoc::Document::State_Verifying));
|
|
}
|
|
|
|
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
|
|
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
|
|
{
|
|
setCentralWidget (new QWidget);
|
|
resize (200, 200); /// \todo get default size from settings and set reasonable minimal size
|
|
|
|
mOperations = new Operations;
|
|
addDockWidget (Qt::BottomDockWidgetArea, mOperations);
|
|
|
|
updateTitle();
|
|
|
|
setupUi();
|
|
}
|
|
|
|
const CSMDoc::Document *CSVDoc::View::getDocument() const
|
|
{
|
|
return mDocument;
|
|
}
|
|
|
|
CSMDoc::Document *CSVDoc::View::getDocument()
|
|
{
|
|
return mDocument;
|
|
}
|
|
|
|
void CSVDoc::View::setIndex (int viewIndex, int totalViews)
|
|
{
|
|
mViewIndex = viewIndex;
|
|
mViewTotal = totalViews;
|
|
updateTitle();
|
|
}
|
|
|
|
void CSVDoc::View::updateDocumentState()
|
|
{
|
|
updateTitle();
|
|
updateActions();
|
|
|
|
static const int operations[] =
|
|
{
|
|
CSMDoc::Document::State_Saving, CSMDoc::Document::State_Verifying,
|
|
-1 // end marker
|
|
};
|
|
|
|
int state = mDocument->getState() ;
|
|
|
|
for (int i=0; operations[i]!=-1; ++i)
|
|
if (!(state & operations[i]))
|
|
mOperations->quitOperation (operations[i]);
|
|
}
|
|
|
|
void CSVDoc::View::updateProgress (int current, int max, int type, int threads)
|
|
{
|
|
mOperations->setProgress (current, max, type, threads);
|
|
}
|
|
|
|
void CSVDoc::View::newView()
|
|
{
|
|
mViewManager.addView (mDocument);
|
|
}
|
|
|
|
void CSVDoc::View::test()
|
|
{
|
|
mDocument->getUndoStack().push (new QUndoCommand());
|
|
}
|
|
|
|
void CSVDoc::View::save()
|
|
{
|
|
mDocument->save();
|
|
}
|
|
|
|
void CSVDoc::View::verify()
|
|
{
|
|
mDocument->verify();
|
|
} |