2
/**************************************************************************\
3
* Copyright (c) Kongsberg Oil & Gas Technologies AS
6
* Redistribution and use in source and binary forms, with or without
7
* modification, are permitted provided that the following conditions are
10
* Redistributions of source code must retain the above copyright notice,
11
* this list of conditions and the following disclaimer.
13
* Redistributions in binary form must reproduce the above copyright
14
* notice, this list of conditions and the following disclaimer in the
15
* documentation and/or other materials provided with the distribution.
17
* Neither the name of the copyright holder nor the names of its
18
* contributors may be used to endorse or promote products derived from
19
* this software without specific prior written permission.
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
* HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
\**************************************************************************/
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);
114
// FIXME: It would be ideal to expose these actiongroups to Qt
115
// Designer and be able to connect them to the appropriate slots on
116
// QuarterWidget, but this is not possible in Qt. Exposing every
117
// single action is supposed to work, but it doesn't at the
118
// moment. (20081215 frodo)
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();