qvolray

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