forked from mirror/openmw-tes3mp
Add custom page for key bindings.
parent
b685c0ce6c
commit
65201badf6
@ -0,0 +1,89 @@
|
||||
#include "keybindingpage.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
#include <QComboBox>
|
||||
#include <QGridLayout>
|
||||
#include <QSpacerItem>
|
||||
#include <QStackedLayout>
|
||||
#include <QVBoxLayout>
|
||||
|
||||
#include "../../model/prefs/setting.hpp"
|
||||
#include "../../model/prefs/category.hpp"
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
KeyBindingPage::KeyBindingPage(CSMPrefs::Category& category, QWidget* parent)
|
||||
: PageBase(category, parent)
|
||||
, mStackedLayout(0)
|
||||
, mPageLayout(0)
|
||||
, mPageSelector(0)
|
||||
{
|
||||
// Need one widget for scroll area
|
||||
QWidget* topWidget = new QWidget();
|
||||
QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
|
||||
|
||||
// Allows switching between "pages"
|
||||
QWidget* stackedWidget = new QWidget();
|
||||
mStackedLayout = new QStackedLayout(stackedWidget);
|
||||
|
||||
mPageSelector = new QComboBox();
|
||||
connect(mPageSelector, SIGNAL(currentIndexChanged(int)), mStackedLayout, SLOT(setCurrentIndex(int)));
|
||||
|
||||
topLayout->addWidget(mPageSelector);
|
||||
topLayout->addWidget(stackedWidget);
|
||||
topLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
|
||||
// Add each option
|
||||
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
|
||||
addSetting (*iter);
|
||||
|
||||
setWidgetResizable(true);
|
||||
setWidget(topWidget);
|
||||
}
|
||||
|
||||
void KeyBindingPage::addSetting(CSMPrefs::Setting *setting)
|
||||
{
|
||||
std::pair<QWidget*, QWidget*> widgets = setting->makeWidgets (this);
|
||||
|
||||
if (widgets.first)
|
||||
{
|
||||
// Label, Option widgets
|
||||
assert(mPageLayout);
|
||||
|
||||
int next = mPageLayout->rowCount();
|
||||
mPageLayout->addWidget(widgets.first, next, 0);
|
||||
mPageLayout->addWidget(widgets.second, next, 1);
|
||||
}
|
||||
else if (widgets.second)
|
||||
{
|
||||
// Wide single widget
|
||||
assert(mPageLayout);
|
||||
|
||||
int next = mPageLayout->rowCount();
|
||||
mPageLayout->addWidget(widgets.second, next, 0, 1, 2);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (setting->getLabel().empty())
|
||||
{
|
||||
// Insert empty space
|
||||
assert(mPageLayout);
|
||||
|
||||
int next = mPageLayout->rowCount();
|
||||
mPageLayout->addWidget(new QWidget(), next, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create new page
|
||||
QWidget* pageWidget = new QWidget();
|
||||
mPageLayout = new QGridLayout(pageWidget);
|
||||
mPageLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
|
||||
|
||||
mStackedLayout->addWidget(pageWidget);
|
||||
|
||||
mPageSelector->addItem(QString::fromUtf8(setting->getLabel().c_str()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
#ifndef CSV_PREFS_KEYBINDINGPAGE_H
|
||||
#define CSV_PREFS_KEYBINDINGPAGE_H
|
||||
|
||||
#include "pagebase.hpp"
|
||||
|
||||
class QComboBox;
|
||||
class QGridLayout;
|
||||
class QStackedLayout;
|
||||
|
||||
namespace CSMPrefs
|
||||
{
|
||||
class Setting;
|
||||
}
|
||||
|
||||
namespace CSVPrefs
|
||||
{
|
||||
class KeyBindingPage : public PageBase
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
|
||||
KeyBindingPage(CSMPrefs::Category& category, QWidget* parent);
|
||||
|
||||
void addSetting(CSMPrefs::Setting* setting);
|
||||
|
||||
private:
|
||||
|
||||
QStackedLayout* mStackedLayout;
|
||||
QGridLayout* mPageLayout;
|
||||
QComboBox* mPageSelector;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue