qvolray
view src/ui.cc @ 32:7e5a2dd9bca6
actions and shit
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 14 Apr 2012 22:51:41 +0300 |
parents | c1dd5b120504 |
children | e7c006b774ed |
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <vector>
4 #include <QtGui>
5 #include "ui.h"
6 #include "ui_maingl.h"
7 #include "ui_sliceview.h"
8 #include "ui_xferview.h"
11 static Volume *volume;
12 std::vector<QGLWidget*> glwlist;
14 MainWindow::MainWindow()
15 {
16 setWindowTitle("Volume Renderer");
18 // OpenGL view (this must be initialized first)
19 maingl = new MainGLView;
20 setCentralWidget(maingl);
21 glwlist.push_back(maingl);
23 // slice view sub-window
24 sidewin = new SideWindow;
25 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
26 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
27 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
29 // transfer function sub-window
30 xferwin = new XFerWin;
31 xferwin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
32 xferwin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
33 addDockWidget(Qt::LeftDockWidgetArea, xferwin);
35 // actions
36 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
37 act_open->setStatusTip("Open a volume dataset");
38 act_open->setShortcut(QKeySequence::Open);
39 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
41 QAction *act_quit = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton), "&Quit", this);
42 act_quit->setStatusTip("Exit program");
43 //act_quit->setShortcut(QKeySequence::Quit);
44 act_quit->setShortcut(QKeySequence(tr("Ctrl+Q", "File|Quit")));
45 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
47 // menus
48 QMenu *mfile = menuBar()->addMenu("&File");
49 mfile->addAction(act_open);
50 mfile->addAction(act_quit);
52 // toolbars
53 QToolBar *tfile = addToolBar("&File");
54 tfile->addAction(act_open);
56 statusBar();
57 show();
58 }
60 void MainWindow::open_volume()
61 {
62 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
63 if(!fname.isNull()) {
64 Volume *vol = new Volume;
66 if(vol->load(qPrintable(fname))) {
67 delete volume;
68 volume = vol;
69 volray_setvolume(vol);
70 post_redisplay();
71 } else {
72 delete vol;
73 }
74 }
75 }
78 SideWindow::SideWindow()
79 {
80 QGroupBox *group_slice = new QGroupBox("Volume slice");
81 {
82 slice_view = new SliceGLView(glwlist[0]);
83 glwlist.push_back(slice_view);
85 QCheckBox *chk_clip = new QCheckBox("clip");
86 chk_clip->setStatusTip("Enable clipping at the current slice");
87 chk_clip->setChecked(false);
88 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
90 QSlider *zslider = new QSlider(Qt::Horizontal);
91 zslider->setStatusTip("Change current Z slice");
92 zslider->setRange(0, 256);
93 zslider->setValue(volray_getvalue(VolRayOpt::ZCURSOR) * 256.0);
94 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
96 QVBoxLayout *vbox = new QVBoxLayout;
97 vbox->addWidget(slice_view);
98 vbox->addWidget(chk_clip);
99 vbox->addWidget(zslider);
101 group_slice->setLayout(vbox);
102 }
104 QWidget *win = new QWidget;
105 setWidget(win);
107 QVBoxLayout *vbox = new QVBoxLayout;
108 vbox->addWidget(group_slice);
109 vbox->addStretch();
111 win->setLayout(vbox);
112 }
114 void SideWindow::zslider_change(int val)
115 {
116 volray_setvalue(VolRayOpt::ZCURSOR, (float)val / 256.0);
117 }
119 void SideWindow::clip_change(int checked)
120 {
121 volray_setvalue(VolRayOpt::ZCLIP, checked);
122 }
125 XFerWin::XFerWin()
126 {
127 QGroupBox *group_xfer = new QGroupBox("Transfer function");
128 {
129 XFerGLView *xfer_view = new XFerGLView(glwlist[0]);
130 glwlist.push_back(xfer_view);
132 QVBoxLayout *vbox = new QVBoxLayout;
133 vbox->addWidget(xfer_view);
135 group_xfer->setLayout(vbox);
136 }
138 QWidget *win = new QWidget;
139 setWidget(win);
141 QVBoxLayout *vbox = new QVBoxLayout;
142 vbox->addWidget(group_xfer);
143 vbox->addStretch();
145 win->setLayout(vbox);
146 }
149 void post_redisplay()
150 {
151 for(auto glw : glwlist) {
152 glw->updateGL();
153 }
154 }