2012-11-22 12:30:02 +00:00
|
|
|
|
|
|
|
#include "view.hpp"
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
#include <sstream>
|
2012-11-22 13:10:23 +00:00
|
|
|
|
|
|
|
#include <QCloseEvent>
|
2012-11-22 13:49:58 +00:00
|
|
|
#include <QMenuBar>
|
2012-11-22 13:10:23 +00:00
|
|
|
|
2012-11-22 14:54:31 +00:00
|
|
|
#include "../../model/doc/document.hpp"
|
|
|
|
|
2012-11-22 13:10:23 +00:00
|
|
|
#include "viewmanager.hpp"
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
QAction *save = new QAction (tr ("&Save"), this);
|
|
|
|
connect (save, SIGNAL (triggered()), this, SLOT (save()));
|
|
|
|
file->addAction (save);
|
2012-11-22 23:51:04 +00:00
|
|
|
mEditingActions.push_back (save);
|
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);
|
2012-11-22 15:00:23 +00:00
|
|
|
|
|
|
|
// test
|
|
|
|
QAction *test = new QAction (tr ("&Test Command"), this);
|
|
|
|
connect (test, SIGNAL (triggered()), this, SLOT (test()));
|
|
|
|
edit->addAction (test);
|
2012-11-22 23:51:04 +00:00
|
|
|
mEditingActions.push_back (test);
|
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-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-22 14:09:04 +00:00
|
|
|
void CSVDoc::View::updateTitle()
|
|
|
|
{
|
|
|
|
std::ostringstream stream;
|
|
|
|
|
|
|
|
stream << "New Document ";
|
|
|
|
|
2012-11-22 22:42:17 +00:00
|
|
|
if (mDocument->getState() & CSMDoc::Document::State_Modified)
|
|
|
|
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()
|
|
|
|
{
|
|
|
|
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());
|
|
|
|
}
|
|
|
|
|
2012-11-22 14:09:04 +00:00
|
|
|
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews)
|
|
|
|
: mViewManager (viewManager), mDocument (document), mViewIndex (totalViews-1), mViewTotal (totalViews)
|
2012-11-22 12:30:02 +00:00
|
|
|
{
|
2012-11-22 13:49:58 +00:00
|
|
|
setCentralWidget (new QWidget);
|
2012-11-22 12:30:02 +00:00
|
|
|
resize (200, 200);
|
2012-11-22 14:09:04 +00:00
|
|
|
|
|
|
|
updateTitle();
|
2012-11-22 13:49:58 +00:00
|
|
|
|
|
|
|
setupUi();
|
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-22 22:42:17 +00:00
|
|
|
}
|
|
|
|
|
2012-11-22 13:49:58 +00:00
|
|
|
void CSVDoc::View::newView()
|
|
|
|
{
|
|
|
|
mViewManager.addView (mDocument);
|
2012-11-22 15:00:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::test()
|
|
|
|
{
|
|
|
|
mDocument->getUndoStack().push (new QUndoCommand());
|
2012-11-22 23:36:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void CSVDoc::View::save()
|
|
|
|
{
|
|
|
|
mDocument->save();
|
2012-11-22 12:30:02 +00:00
|
|
|
}
|