Debian Codegraph @

src/Gui/Quarter/ContextMenu.cpp

raw
1
2 /**************************************************************************\
3 * Copyright (c) Kongsberg Oil & Gas Technologies AS
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * Redistributions of source code must retain the above copyright notice,
11 * this list of conditions and the following disclaimer.
12 *
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.
16 *
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.
20 *
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 \**************************************************************************/
33
34 #include <QActionGroup>
35 #include <QMenu>
36
37 #include "ContextMenu.h"
38 #include "QuarterWidget.h"
39
40
41 using namespace SIM::Coin3D::Quarter;
42
43 ContextMenu::ContextMenu(QuarterWidget * quarterwidget)
44 : quarterwidget(quarterwidget)
45 {
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");
51
52 this->contextmenu->addMenu(functionsmenu);
53 this->contextmenu->addMenu(rendermenu);
54 this->contextmenu->addMenu(stereomenu);
55 this->contextmenu->addMenu(transparencymenu);
56
57 SoRenderManager * sorendermanager = quarterwidget->getSoRenderManager();
58
59 QActionGroup * rendermodegroup = nullptr;
60 QActionGroup * stereomodegroup = nullptr;
61 QActionGroup * transparencytypegroup = nullptr;
62
63 Q_FOREACH (QAction * action, quarterwidget->renderModeActions()) {
64 if (!rendermodegroup) {
65 rendermodegroup = action->actionGroup();
66 } else {
67 assert(rendermodegroup && rendermodegroup == action->actionGroup());
68 }
69
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);
74 }
75
76 Q_FOREACH (QAction * action, quarterwidget->stereoModeActions()) {
77 if (!stereomodegroup) {
78 stereomodegroup = action->actionGroup();
79 } else {
80 assert(stereomodegroup && stereomodegroup == action->actionGroup());
81 }
82
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);
87 }
88
89 Q_FOREACH (QAction * action, quarterwidget->transparencyTypeActions()) {
90 if (!transparencytypegroup) {
91 transparencytypegroup = action->actionGroup();
92 } else {
93 assert(transparencytypegroup && transparencytypegroup == action->actionGroup());
94 }
95
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);
101 }
102
103 QAction * viewall = new QAction("View All", quarterwidget);
104 QAction * seek = new QAction("Seek", quarterwidget);
105 functionsmenu->addAction(viewall);
106 functionsmenu->addAction(seek);
107
108 QObject::connect(seek, &QAction::triggered,
109 this->quarterwidget, &QuarterWidget::seek);
110
111 QObject::connect(viewall, &QAction::triggered,
112 this->quarterwidget, &QuarterWidget::viewAll);
113
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);
121
122 QObject::connect(stereomodegroup, &QActionGroup::triggered,
123 this, &ContextMenu::changeStereoMode);
124
125 QObject::connect(transparencytypegroup, &QActionGroup::triggered,
126 this, &ContextMenu::changeTransparencyType);
127 }
128
129 ContextMenu::~ContextMenu()
130 {
131 delete this->functionsmenu;
132 delete this->rendermenu;
133 delete this->stereomenu;
134 delete this->transparencymenu;
135 delete this->contextmenu;
136 }
137
138 QMenu *
139 ContextMenu::getMenu() const
140 {
141 return this->contextmenu;
142 }
143
144 void
145 ContextMenu::changeRenderMode(QAction * action)
146 {
147 QuarterWidget::RenderMode mode =
148 static_cast<QuarterWidget::RenderMode>(action->data().toInt());
149
150 this->quarterwidget->setRenderMode(mode);
151 this->quarterwidget->getSoRenderManager()->scheduleRedraw();
152 }
153
154 void
155 ContextMenu::changeStereoMode(QAction * action)
156 {
157 QuarterWidget::StereoMode mode =
158 static_cast<QuarterWidget::StereoMode>(action->data().toInt());
159
160 this->quarterwidget->setStereoMode(mode);
161 this->quarterwidget->getSoRenderManager()->scheduleRedraw();
162 }
163
164 void
165 ContextMenu::changeTransparencyType(QAction * action)
166 {
167 QuarterWidget::TransparencyType type =
168 static_cast<QuarterWidget::TransparencyType>(action->data().toInt());
169
170 this->quarterwidget->setTransparencyType(type);
171 this->quarterwidget->getSoRenderManager()->scheduleRedraw();
172 }