34
#include <QActionGroup>
37
#include "ContextMenu.h"
38
#include "QuarterWidget.h"
41
using namespace SIM::Coin3D::Quarter;
43
ContextMenu::ContextMenu(QuarterWidget * quarterwidget)
44
: quarterwidget(quarterwidget)
46
this->contextmenu = new QMenu;
47
this->functionsmenu = new QMenu("Functions");
48
this->rendermenu = new QMenu("Render Mode");
49
this->stereomenu = new QMenu("Stereo Mode");
50
this->transparencymenu = new QMenu("Transparency Type");
52
this->contextmenu->addMenu(functionsmenu);
53
this->contextmenu->addMenu(rendermenu);
54
this->contextmenu->addMenu(stereomenu);
55
this->contextmenu->addMenu(transparencymenu);
57
SoRenderManager * sorendermanager = quarterwidget->getSoRenderManager();
59
QActionGroup * rendermodegroup = nullptr;
60
QActionGroup * stereomodegroup = nullptr;
61
QActionGroup * transparencytypegroup = nullptr;
63
Q_FOREACH (QAction * action, quarterwidget->renderModeActions()) {
64
if (!rendermodegroup) {
65
rendermodegroup = action->actionGroup();
67
assert(rendermodegroup && rendermodegroup == action->actionGroup());
70
int rendermode = static_cast<QuarterWidget::RenderMode>(sorendermanager->getRenderMode());
71
int data = static_cast<QuarterWidget::RenderMode>(action->data().toInt());
72
action->setChecked(rendermode == data);
73
rendermenu->addAction(action);
76
Q_FOREACH (QAction * action, quarterwidget->stereoModeActions()) {
77
if (!stereomodegroup) {
78
stereomodegroup = action->actionGroup();
80
assert(stereomodegroup && stereomodegroup == action->actionGroup());
83
int stereomode = static_cast<QuarterWidget::StereoMode>(sorendermanager->getStereoMode());
84
int data = static_cast<QuarterWidget::StereoMode>(action->data().toInt());
85
action->setChecked(stereomode == data);
86
stereomenu->addAction(action);
89
Q_FOREACH (QAction * action, quarterwidget->transparencyTypeActions()) {
90
if (!transparencytypegroup) {
91
transparencytypegroup = action->actionGroup();
93
assert(transparencytypegroup && transparencytypegroup == action->actionGroup());
96
SoGLRenderAction * renderaction = sorendermanager->getGLRenderAction();
97
int transparencytype = static_cast<SoGLRenderAction::TransparencyType>(renderaction->getTransparencyType());
98
int data = static_cast<SoGLRenderAction::TransparencyType>(action->data().toInt());
99
action->setChecked(transparencytype == data);
100
transparencymenu->addAction(action);
103
QAction * viewall = new QAction("View All", quarterwidget);
104
QAction * seek = new QAction("Seek", quarterwidget);
105
functionsmenu->addAction(viewall);
106
functionsmenu->addAction(seek);
108
QObject::connect(seek, &QAction::triggered,
109
this->quarterwidget, &QuarterWidget::seek);
111
QObject::connect(viewall, &QAction::triggered,
112
this->quarterwidget, &QuarterWidget::viewAll);
119
QObject::connect(rendermodegroup, &QActionGroup::triggered,
120
this, &ContextMenu::changeRenderMode);
122
QObject::connect(stereomodegroup, &QActionGroup::triggered,
123
this, &ContextMenu::changeStereoMode);
125
QObject::connect(transparencytypegroup, &QActionGroup::triggered,
126
this, &ContextMenu::changeTransparencyType);
129
ContextMenu::~ContextMenu()
131
delete this->functionsmenu;
132
delete this->rendermenu;
133
delete this->stereomenu;
134
delete this->transparencymenu;
135
delete this->contextmenu;
139
ContextMenu::getMenu() const
141
return this->contextmenu;
145
ContextMenu::changeRenderMode(QAction * action)
147
QuarterWidget::RenderMode mode =
148
static_cast<QuarterWidget::RenderMode>(action->data().toInt());
150
this->quarterwidget->setRenderMode(mode);
151
this->quarterwidget->getSoRenderManager()->scheduleRedraw();
155
ContextMenu::changeStereoMode(QAction * action)
157
QuarterWidget::StereoMode mode =
158
static_cast<QuarterWidget::StereoMode>(action->data().toInt());
160
this->quarterwidget->setStereoMode(mode);
161
this->quarterwidget->getSoRenderManager()->scheduleRedraw();
165
ContextMenu::changeTransparencyType(QAction * action)
167
QuarterWidget::TransparencyType type =
168
static_cast<QuarterWidget::TransparencyType>(action->data().toInt());
170
this->quarterwidget->setTransparencyType(type);
171
this->quarterwidget->getSoRenderManager()->scheduleRedraw();