mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
Move context menu code to PageBase
This commit is contained in:
parent
16f8341de3
commit
cd75c5618c
7 changed files with 41 additions and 82 deletions
|
@ -110,7 +110,7 @@ opencs_units_noqt (view/tools
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (view/prefs
|
opencs_units (view/prefs
|
||||||
dialogue pagebase page keybindingpage contextmenulist contextmenuwidget
|
dialogue pagebase page keybindingpage contextmenulist
|
||||||
)
|
)
|
||||||
|
|
||||||
opencs_units (model/prefs
|
opencs_units (model/prefs
|
||||||
|
|
|
@ -1,33 +0,0 @@
|
||||||
#include "contextmenuwidget.hpp"
|
|
||||||
|
|
||||||
#include <QMenu>
|
|
||||||
#include <QContextMenuEvent>
|
|
||||||
|
|
||||||
#include "../../model/prefs/state.hpp"
|
|
||||||
|
|
||||||
CSVPrefs::ContextMenuWidget::ContextMenuWidget(const std::string& category, QWidget* parent)
|
|
||||||
:QWidget(parent)
|
|
||||||
,mCategory(category)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVPrefs::ContextMenuWidget::contextMenuEvent(QContextMenuEvent* e)
|
|
||||||
{
|
|
||||||
QMenu* menu = new QMenu();
|
|
||||||
|
|
||||||
menu->addAction("Reset category to default", this, SLOT(resetCategory()));
|
|
||||||
menu->addAction("Reset all to default", this, SLOT(resetAll()));
|
|
||||||
|
|
||||||
menu->exec(e->globalPos());
|
|
||||||
delete menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVPrefs::ContextMenuWidget::resetCategory()
|
|
||||||
{
|
|
||||||
CSMPrefs::State::get().resetCategory(mCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
void CSVPrefs::ContextMenuWidget::resetAll()
|
|
||||||
{
|
|
||||||
CSMPrefs::State::get().resetAll();
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
#ifndef CSV_PREFS_CONTEXTMENUWIDGET_H
|
|
||||||
#define CSV_PREFS_CONTEXTMENUWIDGET_H
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
#include <QWidget>
|
|
||||||
|
|
||||||
class QContextMenuEvent;
|
|
||||||
|
|
||||||
namespace CSVPrefs
|
|
||||||
{
|
|
||||||
class ContextMenuWidget : public QWidget
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
ContextMenuWidget(const std::string& category, QWidget* parent = 0);
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
void contextMenuEvent(QContextMenuEvent* e);
|
|
||||||
|
|
||||||
private slots:
|
|
||||||
|
|
||||||
void resetCategory();
|
|
||||||
|
|
||||||
void resetAll();
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
std::string mCategory;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -9,7 +9,6 @@
|
||||||
|
|
||||||
#include "../../model/prefs/setting.hpp"
|
#include "../../model/prefs/setting.hpp"
|
||||||
#include "../../model/prefs/category.hpp"
|
#include "../../model/prefs/category.hpp"
|
||||||
#include "../../view/prefs/contextmenuwidget.hpp"
|
|
||||||
|
|
||||||
namespace CSVPrefs
|
namespace CSVPrefs
|
||||||
{
|
{
|
||||||
|
@ -20,7 +19,7 @@ namespace CSVPrefs
|
||||||
, mPageSelector(0)
|
, mPageSelector(0)
|
||||||
{
|
{
|
||||||
// Need one widget for scroll area
|
// Need one widget for scroll area
|
||||||
CSVPrefs::ContextMenuWidget* topWidget = new CSVPrefs::ContextMenuWidget(category.getKey());
|
QWidget* topWidget = new QWidget();
|
||||||
QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
|
QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
|
||||||
|
|
||||||
// Allows switching between "pages"
|
// Allows switching between "pages"
|
||||||
|
|
|
@ -5,25 +5,17 @@
|
||||||
|
|
||||||
#include "../../model/prefs/setting.hpp"
|
#include "../../model/prefs/setting.hpp"
|
||||||
#include "../../model/prefs/category.hpp"
|
#include "../../model/prefs/category.hpp"
|
||||||
#include "../../view/prefs/contextmenuwidget.hpp"
|
|
||||||
|
|
||||||
CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent)
|
CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent)
|
||||||
: PageBase (category, parent)
|
: PageBase (category, parent)
|
||||||
{
|
{
|
||||||
// topWidget can expand while widget stays the same size
|
QWidget *widget = new QWidget (parent);
|
||||||
// This is so the context menu triggers over the entire page
|
|
||||||
// but the user interface looks the same
|
|
||||||
CSVPrefs::ContextMenuWidget *topWidget = new CSVPrefs::ContextMenuWidget (category.getKey(), parent);
|
|
||||||
topWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
|
|
||||||
|
|
||||||
QWidget* widget = new QWidget(topWidget);
|
|
||||||
mGrid = new QGridLayout (widget);
|
mGrid = new QGridLayout (widget);
|
||||||
|
|
||||||
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
|
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
|
||||||
addSetting (*iter);
|
addSetting (*iter);
|
||||||
|
|
||||||
setWidgetResizable(true);
|
setWidget (widget);
|
||||||
setWidget (topWidget);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting)
|
void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting)
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
|
|
||||||
#include "pagebase.hpp"
|
#include "pagebase.hpp"
|
||||||
|
|
||||||
|
#include <QMenu>
|
||||||
|
#include <QContextMenuEvent>
|
||||||
|
|
||||||
#include "../../model/prefs/category.hpp"
|
#include "../../model/prefs/category.hpp"
|
||||||
|
#include "../../model/prefs/state.hpp"
|
||||||
|
|
||||||
CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent)
|
CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent)
|
||||||
: QScrollArea (parent), mCategory (category)
|
: QScrollArea (parent), mCategory (category)
|
||||||
|
@ -11,3 +15,24 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory()
|
||||||
{
|
{
|
||||||
return mCategory;
|
return mCategory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVPrefs::PageBase::contextMenuEvent(QContextMenuEvent* e)
|
||||||
|
{
|
||||||
|
QMenu* menu = new QMenu();
|
||||||
|
|
||||||
|
menu->addAction("Reset category to default", this, SLOT(resetCategory()));
|
||||||
|
menu->addAction("Reset all to default", this, SLOT(resetAll()));
|
||||||
|
|
||||||
|
menu->exec(e->globalPos());
|
||||||
|
delete menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVPrefs::PageBase::resetCategory()
|
||||||
|
{
|
||||||
|
CSMPrefs::State::get().resetCategory(getCategory().getKey());
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVPrefs::PageBase::resetAll()
|
||||||
|
{
|
||||||
|
CSMPrefs::State::get().resetAll();
|
||||||
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
|
|
||||||
#include <QScrollArea>
|
#include <QScrollArea>
|
||||||
|
|
||||||
|
class QContextMenuEvent;
|
||||||
|
|
||||||
namespace CSMPrefs
|
namespace CSMPrefs
|
||||||
{
|
{
|
||||||
class Category;
|
class Category;
|
||||||
|
@ -21,6 +23,16 @@ namespace CSVPrefs
|
||||||
PageBase (CSMPrefs::Category& category, QWidget *parent);
|
PageBase (CSMPrefs::Category& category, QWidget *parent);
|
||||||
|
|
||||||
CSMPrefs::Category& getCategory();
|
CSMPrefs::Category& getCategory();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
void contextMenuEvent(QContextMenuEvent*);
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
|
||||||
|
void resetCategory();
|
||||||
|
|
||||||
|
void resetAll();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue