nuclear@13: #include nuclear@13: #include nuclear@13: #include nuclear@13: #include "ui.h" nuclear@13: nuclear@13: static GLView *glview; nuclear@13: static Volume *volume; nuclear@13: nuclear@13: MainWindow::MainWindow() nuclear@13: { nuclear@13: setWindowTitle("Volume Renderer"); nuclear@13: nuclear@13: // OpenGL view nuclear@13: glview = new GLView; nuclear@13: setCentralWidget(glview); nuclear@13: nuclear@14: // side-window nuclear@14: sidewin = new SideWindow; nuclear@14: sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); nuclear@14: sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable); nuclear@14: addDockWidget(Qt::LeftDockWidgetArea, sidewin); nuclear@14: nuclear@13: // actions nuclear@13: QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this); nuclear@13: act_open->setStatusTip("Open a volume dataset"); nuclear@13: QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume())); nuclear@13: nuclear@13: QAction *act_quit = new QAction("&Quit", this); nuclear@13: act_quit->setStatusTip("Quit"); nuclear@13: QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close())); nuclear@13: nuclear@13: // menus nuclear@13: QMenu *mfile = menuBar()->addMenu("&File"); nuclear@13: mfile->addAction(act_open); nuclear@13: mfile->addAction(act_quit); nuclear@13: nuclear@13: // toolbars nuclear@13: QToolBar *tfile = addToolBar("&File"); nuclear@13: tfile->addAction(act_open); nuclear@13: nuclear@13: statusBar(); nuclear@13: show(); nuclear@13: } nuclear@13: nuclear@13: void MainWindow::open_volume() nuclear@13: { nuclear@13: QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)"); nuclear@13: if(!fname.isNull()) { nuclear@13: Volume *vol = new Volume; nuclear@13: nuclear@13: if(vol->load(qPrintable(fname))) { nuclear@13: delete volume; nuclear@13: volume = vol; nuclear@13: volray_setvolume(vol); nuclear@13: post_redisplay(); nuclear@13: } else { nuclear@13: delete vol; nuclear@13: } nuclear@13: } nuclear@13: } nuclear@13: nuclear@14: nuclear@14: SideWindow::SideWindow() nuclear@14: { nuclear@14: } nuclear@14: nuclear@14: nuclear@13: void post_redisplay() nuclear@13: { nuclear@13: glview->updateGL(); nuclear@13: } nuclear@13: nuclear@13: nuclear@13: GLView::GLView(QWidget *parent) nuclear@13: : QGLWidget(QGLFormat(QGL::DoubleBuffer), parent) nuclear@13: { nuclear@13: } nuclear@13: nuclear@13: QSize GLView::minimumSizeHint() const nuclear@13: { nuclear@13: return QSize(320, 200); nuclear@13: } nuclear@13: nuclear@13: QSize GLView::sizeHint() const nuclear@13: { nuclear@13: return QSize(1280, 800); nuclear@13: } nuclear@13: nuclear@13: void GLView::initializeGL() nuclear@13: { nuclear@13: if(!volray_init()) { nuclear@13: exit(0); nuclear@13: } nuclear@13: } nuclear@13: nuclear@13: void GLView::resizeGL(int xsz, int ysz) nuclear@13: { nuclear@13: volray_resize(xsz, ysz); nuclear@13: } nuclear@13: nuclear@13: void GLView::paintGL() nuclear@13: { nuclear@13: volray_draw(); nuclear@13: } nuclear@13: nuclear@13: static int button_number(Qt::MouseButton bn) nuclear@13: { nuclear@13: switch(bn) { nuclear@13: case Qt::LeftButton: nuclear@13: return 0; nuclear@13: case Qt::MidButton: nuclear@13: return 1; nuclear@13: case Qt::RightButton: nuclear@13: return 2; nuclear@13: default: nuclear@13: break; nuclear@13: } nuclear@13: return -1; nuclear@13: } nuclear@13: nuclear@13: void GLView::mousePressEvent(QMouseEvent *ev) nuclear@13: { nuclear@13: int bn = button_number(ev->button()); nuclear@13: if(bn >= 0) { nuclear@13: volray_mouse(bn, 1, ev->x(), ev->y()); nuclear@13: } nuclear@13: } nuclear@13: nuclear@13: void GLView::mouseReleaseEvent(QMouseEvent *ev) nuclear@13: { nuclear@13: int bn = button_number(ev->button()); nuclear@13: if(bn >= 0) { nuclear@13: volray_mouse(bn, 0, ev->x(), ev->y()); nuclear@13: } nuclear@13: } nuclear@13: nuclear@13: void GLView::mouseMoveEvent(QMouseEvent *ev) nuclear@13: { nuclear@13: volray_motion(ev->x(), ev->y()); nuclear@13: }