1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-01-20 14:23:53 +00:00
openmw/apps/opencs/view/prefs/keybindingpage.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.1 KiB
C++
Raw Normal View History

2016-07-27 23:15:24 +00:00
#include "keybindingpage.hpp"
#include <cassert>
2022-10-19 17:02:00 +00:00
#include <string>
#include <utility>
#include <vector>
2016-07-27 23:15:24 +00:00
#include <QComboBox>
#include <QGridLayout>
#include <QLabel>
#include <QPushButton>
2016-07-27 23:15:24 +00:00
#include <QStackedLayout>
#include <QVBoxLayout>
2022-10-19 17:02:00 +00:00
#include <apps/opencs/view/prefs/pagebase.hpp>
2016-07-27 23:15:24 +00:00
#include "../../model/prefs/category.hpp"
#include "../../model/prefs/setting.hpp"
#include "../../model/prefs/state.hpp"
2016-07-27 23:15:24 +00:00
namespace CSVPrefs
{
KeyBindingPage::KeyBindingPage(CSMPrefs::Category& category, QWidget* parent)
: PageBase(category, parent)
2020-11-13 07:39:47 +00:00
, mStackedLayout(nullptr)
, mPageLayout(nullptr)
, mPageSelector(nullptr)
2016-07-27 23:15:24 +00:00
{
2017-05-08 05:24:28 +00:00
// Need one widget for scroll area
2017-05-11 07:46:51 +00:00
QWidget* topWidget = new QWidget();
2017-05-08 05:24:28 +00:00
QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
// Allows switching between "pages"
QWidget* stackedWidget = new QWidget();
mStackedLayout = new QStackedLayout(stackedWidget);
mPageSelector = new QComboBox();
connect(mPageSelector, qOverload<int>(&QComboBox::currentIndexChanged), mStackedLayout,
&QStackedLayout::setCurrentIndex);
2017-05-08 05:24:28 +00:00
QFrame* lineSeparator = new QFrame(topWidget);
lineSeparator->setFrameShape(QFrame::HLine);
lineSeparator->setFrameShadow(QFrame::Sunken);
// Reset key bindings button
QPushButton* resetButton = new QPushButton("Reset to Defaults", topWidget);
connect(resetButton, &QPushButton::clicked, this, &KeyBindingPage::resetKeyBindings);
2017-05-08 05:24:28 +00:00
topLayout->addWidget(mPageSelector);
topLayout->addWidget(stackedWidget);
topLayout->addWidget(lineSeparator);
topLayout->addWidget(resetButton);
2017-05-08 05:24:28 +00:00
topLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
// Add each option
for (CSMPrefs::Category::Iterator iter = category.begin(); iter != category.end(); ++iter)
addSetting(*iter);
setWidgetResizable(true);
setWidget(topWidget);
2016-07-27 23:15:24 +00:00
}
void KeyBindingPage::addSetting(CSMPrefs::Setting* setting)
{
const CSMPrefs::SettingWidgets widgets = setting->makeWidgets(this);
2016-07-27 23:15:24 +00:00
if (widgets.mLabel != nullptr && widgets.mInput != nullptr)
2016-07-27 23:15:24 +00:00
{
// Label, Option widgets
assert(mPageLayout);
int next = mPageLayout->rowCount();
mPageLayout->addWidget(widgets.mLabel, next, 0);
mPageLayout->addWidget(widgets.mInput, next, 1);
2016-07-27 23:15:24 +00:00
}
else if (widgets.mInput != nullptr)
2016-07-27 23:15:24 +00:00
{
// Wide single widget
assert(mPageLayout);
int next = mPageLayout->rowCount();
mPageLayout->addWidget(widgets.mInput, next, 0, 1, 2);
2016-07-27 23:15:24 +00:00
}
else
2016-07-27 23:15:24 +00:00
{
// Create new page
QWidget* pageWidget = new QWidget();
mPageLayout = new QGridLayout(pageWidget);
mPageLayout->setSizeConstraint(QLayout::SetMinAndMaxSize);
mStackedLayout->addWidget(pageWidget);
mPageSelector->addItem(setting->getLabel());
2016-07-27 23:15:24 +00:00
}
}
void KeyBindingPage::resetKeyBindings()
{
CSMPrefs::State::get().resetCategory("Key Bindings");
}
2016-07-27 23:15:24 +00:00
}