qvolray

view src/ui.cc @ 27:011ac823600c

broken up the OpenGL code to multiple source files (untested)
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 14 Apr 2012 06:37:31 +0300
parents f4cc61b5a3eb
children aeef3c2ae472
line source
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <QtGui>
4 #include "ui.h"
6 static Volume *volume;
8 static MainGLView *maingl;
10 MainWindow::MainWindow()
11 {
12 setWindowTitle("Volume Renderer");
14 // OpenGL view
15 maingl = new MainGLView;
16 setCentralWidget(maingl);
18 // side-window
19 sidewin = new SideWindow;
20 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
21 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
22 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
24 // actions
25 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
26 act_open->setStatusTip("Open a volume dataset");
27 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
29 QAction *act_quit = new QAction("&Quit", this);
30 act_quit->setStatusTip("Quit");
31 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
33 // menus
34 QMenu *mfile = menuBar()->addMenu("&File");
35 mfile->addAction(act_open);
36 mfile->addAction(act_quit);
38 // toolbars
39 QToolBar *tfile = addToolBar("&File");
40 tfile->addAction(act_open);
42 statusBar();
43 show();
44 }
46 void MainWindow::open_volume()
47 {
48 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
49 if(!fname.isNull()) {
50 Volume *vol = new Volume;
52 if(vol->load(qPrintable(fname))) {
53 delete volume;
54 volume = vol;
55 volray_setvolume(vol);
56 post_redisplay();
57 } else {
58 delete vol;
59 }
60 }
61 }
64 SideWindow::SideWindow()
65 {
66 QGroupBox *groupbox = new QGroupBox("Volume slice");
67 {
68 slice_view = new SliceGLView(maingl);
70 QCheckBox *chk_clip = new QCheckBox("clip");
71 chk_clip->setChecked(false);
72 connect(chk_clip, SIGNAL(stateChanged(int)), this, SLOT(clip_change(int)));
74 QSlider *zslider = new QSlider(Qt::Horizontal);
75 zslider->setRange(0, 256);
76 zslider->setValue(volray_getvalue(VOLRAY_ZCURSOR) * 256.0);
77 connect(zslider, SIGNAL(valueChanged(int)), this, SLOT(zslider_change(int)));
79 QVBoxLayout *vbox = new QVBoxLayout;
80 vbox->addWidget(slice_view);
81 vbox->addWidget(chk_clip);
82 vbox->addWidget(zslider);
84 groupbox->setLayout(vbox);
85 }
87 QWidget *win = new QWidget;
88 setWidget(win);
90 QVBoxLayout *vbox = new QVBoxLayout;
91 vbox->addWidget(groupbox);
92 vbox->addStretch();
94 win->setLayout(vbox);
95 }
97 void SideWindow::zslider_change(int val)
98 {
99 volray_setvalue(VOLRAY_ZCURSOR, (float)val / 256.0);
100 }
102 void SideWindow::clip_change(int checked)
103 {
104 volray_setvalue(VOLRAY_ZCLIP, checked);
105 }
107 void post_redisplay()
108 {
109 maingl->updateGL();
110 }