page switching mechanism

openmw-38
Marc Zinnschlag 9 years ago
parent 0dc3d10112
commit 5e40b4d2e8

@ -124,7 +124,7 @@ opencs_units_noqt (view/settings
)
opencs_units (view/prefs
dialogue
dialogue pagebase
)
opencs_units (model/settings

@ -98,6 +98,16 @@ CSMPrefs::State::Iterator CSMPrefs::State::end()
return mCategories.end();
}
CSMPrefs::Category& CSMPrefs::State::getCategory (const std::string& key)
{
Iterator iter = mCategories.find (key);
if (iter==mCategories.end())
throw std::logic_error ("Invalid user settings category: " + key);
return iter->second;
}
CSMPrefs::State& CSMPrefs::State::get()
{
if (!sThis)

@ -59,6 +59,8 @@ namespace CSMPrefs
Iterator end();
Category& getCategory (const std::string& key);
static State& get();
};

@ -10,6 +10,8 @@
#include "../../model/prefs/state.hpp"
#include "pagebase.hpp"
void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
{
mList = new QListWidget (main);
@ -35,7 +37,8 @@ void CSVPrefs::Dialogue::buildCategorySelector (QSplitter *main)
mList->setMaximumWidth (maxWidth + 10);
/// \todo connect to selection signal
connect (mList, SIGNAL (currentItemChanged (QListWidgetItem *, QListWidgetItem *)),
this, SLOT (selectionChanged (QListWidgetItem *, QListWidgetItem *)));
}
void CSVPrefs::Dialogue::buildContentArea (QSplitter *main)
@ -86,3 +89,25 @@ void CSVPrefs::Dialogue::show()
QWidget::show();
}
void CSVPrefs::Dialogue::selectionChanged (QListWidgetItem *current, QListWidgetItem *previous)
{
if (current)
{
std::string key = current->text().toUtf8().data();
for (int i=0; i<mContent->count(); ++i)
{
PageBase& page = dynamic_cast<PageBase&> (*mContent->widget (i));
if (page.getCategory().getKey()==key)
{
mContent->setCurrentIndex (i);
return;
}
}
PageBase *page = new PageBase (CSMPrefs::get().getCategory (key), mContent);
mContent->setCurrentIndex (mContent->addWidget (page));
}
}

@ -6,6 +6,7 @@
class QSplitter;
class QListWidget;
class QStackedWidget;
class QListWidgetItem;
namespace CSVPrefs
{
@ -33,6 +34,10 @@ namespace CSVPrefs
public slots:
void show();
private slots:
void selectionChanged (QListWidgetItem *current, QListWidgetItem *previous);
};
}

@ -0,0 +1,19 @@
#include "pagebase.hpp"
#include <QLabel>
#include "../../model/prefs/category.hpp"
CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent)
: QScrollArea (parent), mCategory (category)
{
QLabel *temp = new QLabel (category.getKey().c_str(), this);
setWidget (temp);
}
CSMPrefs::Category& CSVPrefs::PageBase::getCategory()
{
return mCategory;
}

@ -0,0 +1,27 @@
#ifndef CSV_PREFS_PAGEBASE_H
#define CSV_PREFS_PAGEBASE_H
#include <QScrollArea>
namespace CSMPrefs
{
class Category;
}
namespace CSVPrefs
{
class PageBase : public QScrollArea
{
Q_OBJECT
CSMPrefs::Category& mCategory;
public:
PageBase (CSMPrefs::Category& category, QWidget *parent);
CSMPrefs::Category& getCategory();
};
}
#endif
Loading…
Cancel
Save