1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 21:23:52 +00:00

display view indices in title bar

This commit is contained in:
Marc Zinnschlag 2012-11-22 15:09:04 +01:00
parent 789cecb9df
commit 1ddcea1f07
4 changed files with 59 additions and 7 deletions

View file

@ -1,7 +1,7 @@
#include "view.hpp" #include "view.hpp"
#include <iostream> #include <sstream>
#include <QCloseEvent> #include <QCloseEvent>
#include <QMenuBar> #include <QMenuBar>
@ -16,7 +16,7 @@ void CSVDoc::View::closeEvent (QCloseEvent *event)
void CSVDoc::View::setupUi() void CSVDoc::View::setupUi()
{ {
// window menu // view menu
QMenu *view = menuBar()->addMenu (tr ("&View")); QMenu *view = menuBar()->addMenu (tr ("&View"));
QAction *newWindow = new QAction (tr ("&New View"), this); QAction *newWindow = new QAction (tr ("&New View"), this);
@ -25,12 +25,25 @@ void CSVDoc::View::setupUi()
view->addAction (newWindow); view->addAction (newWindow);
} }
CSVDoc::View::View (ViewManager& viewManager, CSMDoc::Document *document) void CSVDoc::View::updateTitle()
: mViewManager (viewManager), mDocument (document) {
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); setCentralWidget (new QWidget);
resize (200, 200); resize (200, 200);
setWindowTitle ("New Document");
updateTitle();
setupUi(); setupUi();
} }
@ -45,6 +58,13 @@ CSMDoc::Document *CSVDoc::View::getDocument()
return mDocument; return mDocument;
} }
void CSVDoc::View::setIndex (int viewIndex, int totalViews)
{
mViewIndex = viewIndex;
mViewTotal = totalViews;
updateTitle();
}
void CSVDoc::View::newView() void CSVDoc::View::newView()
{ {
mViewManager.addView (mDocument); mViewManager.addView (mDocument);

View file

@ -20,6 +20,8 @@ namespace CSVDoc
ViewManager& mViewManager; ViewManager& mViewManager;
CSMDoc::Document *mDocument; CSMDoc::Document *mDocument;
int mViewIndex;
int mViewTotal;
// not implemented // not implemented
View (const View&); View (const View&);
@ -31,15 +33,19 @@ namespace CSVDoc
void setupUi(); void setupUi();
void updateTitle();
public: public:
View (ViewManager& viewManager, CSMDoc::Document *document); View (ViewManager& viewManager, CSMDoc::Document *document, int totalViews);
///< The ownership of \a document is not transferred to *this. ///< The ownership of \a document is not transferred to *this.
const CSMDoc::Document *getDocument() const; const CSMDoc::Document *getDocument() const;
CSMDoc::Document *getDocument(); CSMDoc::Document *getDocument();
void setIndex (int viewIndex, int totalViews);
private slots: private slots:
void newView(); void newView();

View file

@ -1,10 +1,30 @@
#include "viewmanager.hpp" #include "viewmanager.hpp"
#include <map>
#include "../../model/doc/documentmanager.hpp" #include "../../model/doc/documentmanager.hpp"
#include "view.hpp" #include "view.hpp"
void CSVDoc::ViewManager::updateIndices()
{
std::map<CSMDoc::Document *, std::pair<int, int> > documents;
for (std::vector<View *>::const_iterator iter (mViews.begin()); iter!=mViews.end(); ++iter)
{
std::map<CSMDoc::Document *, std::pair<int, int> >::iterator document = documents.find ((*iter)->getDocument());
if (document==documents.end())
document =
documents.insert (
std::make_pair ((*iter)->getDocument(), std::make_pair (0, countViews ((*iter)->getDocument())))).
first;
(*iter)->setIndex (document->second.first++, document->second.second);
}
}
CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager) CSVDoc::ViewManager::ViewManager (CSMDoc::DocumentManager& documentManager)
: mDocumentManager (documentManager) : mDocumentManager (documentManager)
{ {
@ -22,12 +42,14 @@ CSVDoc::ViewManager::~ViewManager()
CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document) CSVDoc::View *CSVDoc::ViewManager::addView (CSMDoc::Document *document)
{ {
View *view = new View (*this, document); View *view = new View (*this, document, countViews (document)+1);
mViews.push_back (view); mViews.push_back (view);
view->show(); view->show();
updateIndices();
return view; return view;
} }
@ -57,6 +79,8 @@ bool CSVDoc::ViewManager::closeRequest (View *view)
if (last) if (last)
mDocumentManager.removeDocument (view->getDocument()); mDocumentManager.removeDocument (view->getDocument());
else
updateIndices();
} }
return true; return true;

View file

@ -23,6 +23,8 @@ namespace CSVDoc
ViewManager (const ViewManager&); ViewManager (const ViewManager&);
ViewManager& operator= (const ViewManager&); ViewManager& operator= (const ViewManager&);
void updateIndices();
public: public:
ViewManager (CSMDoc::DocumentManager& documentManager); ViewManager (CSMDoc::DocumentManager& documentManager);