openmw-tes3coop/apps/opencs/view/doc/view.cpp
2012-11-22 15:25:16 +01:00

71 lines
No EOL
1.4 KiB
C++

#include "view.hpp"
#include <sstream>
#include <QCloseEvent>
#include <QMenuBar>
#include "viewmanager.hpp"
void CSVDoc::View::closeEvent (QCloseEvent *event)
{
if (!mViewManager.closeRequest (this))
event->ignore();
}
void CSVDoc::View::setupUi()
{
// view menu
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::updateTitle()
{
std::ostringstream stream;
stream << "New Document ";
if (mViewTotal>1)
stream << " [" << (mViewIndex+1) << "/" << mViewTotal << "]";
setWindowTitle (stream.str().c_str());
}
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);
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::newView()
{
mViewManager.addView (mDocument);
}