2 This file is part of GammaRay, the Qt application inspection and
5 Copyright (C) 2010-2011 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com
6 Author: Kevin Funk <kevin.funk@kdab.com>
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
28 #include "vtkwidget.h"
29 #include <vtkGraphLayoutView.h>
30 #include <vtkForceDirectedLayoutStrategy.h>
31 #include <vtkRenderWindow.h>
32 #include <vtkSpanTreeLayoutStrategy.h>
33 #include <vtkSimple2DLayoutStrategy.h>
34 #include <vtkTreeLayoutStrategy.h>
36 using namespace GammaRay
;
38 VtkPanel::VtkPanel(VtkWidget
*vtkWidget
, QWidget
*parent
)
40 m_vtkWidget(vtkWidget
),
41 m_currentLayout("spanTree")
43 addWidget(new QLabel(tr("Layout:")));
44 m_layoutBox
= new QComboBox
;
46 m_layoutBox
->addItem(tr("Tree Layout"), "tree");
49 m_layoutBox
->addItem(tr("Span Tree Layout"), "spanTree");
50 m_layoutBox
->addItem(tr("Force Directed Layout"), "forceDirected");
51 m_layoutBox
->addItem(tr("Force Directed Layout (3D)"), "forceDirected3D");
52 m_layoutBox
->addItem(tr("Simple 2D Layout"), "simple2D");
53 connect(m_layoutBox
, SIGNAL(currentIndexChanged(int)), SLOT(currentIndexChanged(int)));
54 addWidget(m_layoutBox
);
56 addWidget(new QLabel(tr("Stereo:")));
57 m_stereoBox
= new QComboBox
;
58 m_stereoBox
->addItem(tr("Off"), 0);
59 m_stereoBox
->addItem(tr("Crystal Eyes"), VTK_STEREO_CRYSTAL_EYES
);
60 m_stereoBox
->addItem(tr("Red/Blue"), VTK_STEREO_RED_BLUE
);
61 m_stereoBox
->addItem(tr("Interlaced"), VTK_STEREO_INTERLACED
);
62 m_stereoBox
->addItem(tr("Left"), VTK_STEREO_LEFT
);
63 m_stereoBox
->addItem(tr("Right"), VTK_STEREO_RIGHT
);
64 m_stereoBox
->addItem(tr("Dresden"), VTK_STEREO_DRESDEN
);
65 m_stereoBox
->addItem(tr("Anaglyph"), VTK_STEREO_ANAGLYPH
);
66 m_stereoBox
->addItem(tr("Checkboard"), VTK_STEREO_CHECKERBOARD
);
67 connect(m_stereoBox
, SIGNAL(currentIndexChanged(int)), SLOT(stereoModeChanged(int)));
68 addWidget(m_stereoBox
);
71 static vtkGraphLayoutStrategy
*layoutStrategyForName(const QString
&layoutName
)
73 if (layoutName
== "tree") {
74 vtkTreeLayoutStrategy
*strategy
= vtkTreeLayoutStrategy::New();
75 strategy
->SetRadial(true);
77 } else if (layoutName
== "spanTree") {
78 return vtkSpanTreeLayoutStrategy::New();
79 } else if (layoutName
== "forceDirected") {
80 return vtkForceDirectedLayoutStrategy::New();
81 } else if (layoutName
== "forceDirected3D") {
82 vtkForceDirectedLayoutStrategy
*strategy
= vtkForceDirectedLayoutStrategy::New();
83 strategy
->SetThreeDimensionalLayout(true);
85 } else if (layoutName
== "simple2D") {
86 return vtkSimple2DLayoutStrategy::New();
92 void VtkPanel::currentIndexChanged(int index
)
94 const QString layoutName
= m_layoutBox
->itemData(index
).toString();
95 if (m_currentLayout
== layoutName
) {
100 vtkGraphLayoutStrategy
*strategy
= layoutStrategyForName(layoutName
);
101 m_vtkWidget
->layoutView()->SetLayoutStrategy(strategy
);
102 m_vtkWidget
->layoutView()->ResetCamera();
103 m_vtkWidget
->layoutView()->Render();
104 m_vtkWidget
->GetInteractor()->Start();
105 m_currentLayout
= layoutName
;
108 void VtkPanel::stereoModeChanged(int index
)
110 const int stereoMode
= m_stereoBox
->itemData(index
).toInt();
111 if (stereoMode
<= 0) {
112 m_vtkWidget
->layoutView()->GetRenderWindow()->SetStereoRender(false);
114 m_vtkWidget
->layoutView()->GetRenderWindow()->SetStereoRender(true);
115 m_vtkWidget
->layoutView()->GetRenderWindow()->SetStereoType(stereoMode
);
117 m_vtkWidget
->layoutView()->GetRenderWindow()->StereoUpdate();
120 VtkPanel::~VtkPanel()
125 #include "vtkpanel.moc"