Move context menu code to PageBase

pull/1286/head
PlutonicOverkill 8 years ago
parent 16f8341de3
commit cd75c5618c

@ -110,7 +110,7 @@ opencs_units_noqt (view/tools
)
opencs_units (view/prefs
dialogue pagebase page keybindingpage contextmenulist contextmenuwidget
dialogue pagebase page keybindingpage contextmenulist
)
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/category.hpp"
#include "../../view/prefs/contextmenuwidget.hpp"
namespace CSVPrefs
{
@ -20,7 +19,7 @@ namespace CSVPrefs
, mPageSelector(0)
{
// Need one widget for scroll area
CSVPrefs::ContextMenuWidget* topWidget = new CSVPrefs::ContextMenuWidget(category.getKey());
QWidget* topWidget = new QWidget();
QVBoxLayout* topLayout = new QVBoxLayout(topWidget);
// Allows switching between "pages"

@ -5,25 +5,17 @@
#include "../../model/prefs/setting.hpp"
#include "../../model/prefs/category.hpp"
#include "../../view/prefs/contextmenuwidget.hpp"
CSVPrefs::Page::Page (CSMPrefs::Category& category, QWidget *parent)
: PageBase (category, parent)
{
// topWidget can expand while widget stays the same size
// 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);
QWidget *widget = new QWidget (parent);
mGrid = new QGridLayout (widget);
for (CSMPrefs::Category::Iterator iter = category.begin(); iter!=category.end(); ++iter)
addSetting (*iter);
setWidgetResizable(true);
setWidget (topWidget);
setWidget (widget);
}
void CSVPrefs::Page::addSetting (CSMPrefs::Setting *setting)

@ -1,7 +1,11 @@
#include "pagebase.hpp"
#include <QMenu>
#include <QContextMenuEvent>
#include "../../model/prefs/category.hpp"
#include "../../model/prefs/state.hpp"
CSVPrefs::PageBase::PageBase (CSMPrefs::Category& category, QWidget *parent)
: QScrollArea (parent), mCategory (category)
@ -11,3 +15,24 @@ CSMPrefs::Category& CSVPrefs::PageBase::getCategory()
{
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>
class QContextMenuEvent;
namespace CSMPrefs
{
class Category;
@ -21,6 +23,16 @@ namespace CSVPrefs
PageBase (CSMPrefs::Category& category, QWidget *parent);
CSMPrefs::Category& getCategory();
protected:
void contextMenuEvent(QContextMenuEvent*);
private slots:
void resetCategory();
void resetAll();
};
}

Loading…
Cancel
Save