1 #include "contextmenulist.hpp"
2 
3 #include <QMenu>
4 #include <QContextMenuEvent>
5 #include <QMouseEvent>
6 
7 #include "../../model/prefs/state.hpp"
8 
ContextMenuList(QWidget * parent)9 CSVPrefs::ContextMenuList::ContextMenuList(QWidget* parent)
10     :QListWidget(parent)
11 {
12 }
13 
contextMenuEvent(QContextMenuEvent * e)14 void CSVPrefs::ContextMenuList::contextMenuEvent(QContextMenuEvent* e)
15 {
16     QMenu* menu = new QMenu();
17 
18     menu->addAction("Reset category to default", this, SLOT(resetCategory()));
19     menu->addAction("Reset all to default", this, SLOT(resetAll()));
20 
21     menu->exec(e->globalPos());
22     delete menu;
23 }
24 
mousePressEvent(QMouseEvent * e)25 void CSVPrefs::ContextMenuList::mousePressEvent(QMouseEvent* e)
26 {
27     // enable all buttons except right click
28     // This means that when right-clicking to enable the
29     // context menu, the page doesn't switch at the same time.
30     if (!(e->buttons() & Qt::RightButton))
31     {
32         QListWidget::mousePressEvent(e);
33     }
34 }
35 
resetCategory()36 void CSVPrefs::ContextMenuList::resetCategory()
37 {
38     CSMPrefs::State::get().resetCategory(currentItem()->text().toStdString());
39 }
40 
resetAll()41 void CSVPrefs::ContextMenuList::resetAll()
42 {
43     CSMPrefs::State::get().resetAll();
44 }
45