qvolray

annotate src/ui.cc @ 14:88312413467c

adding a sidewidget
author John Tsiombikas <nuclear@member.fsf.org>
date Tue, 10 Apr 2012 06:35:34 +0300
parents 17d9dc2edc91
children 4c62be57fc1a
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 GLView *glview;
nuclear@13 7 static Volume *volume;
nuclear@13 8
nuclear@13 9 MainWindow::MainWindow()
nuclear@13 10 {
nuclear@13 11 setWindowTitle("Volume Renderer");
nuclear@13 12
nuclear@13 13 // OpenGL view
nuclear@13 14 glview = new GLView;
nuclear@13 15 setCentralWidget(glview);
nuclear@13 16
nuclear@14 17 // side-window
nuclear@14 18 sidewin = new SideWindow;
nuclear@14 19 sidewin->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
nuclear@14 20 sidewin->setFeatures(QDockWidget::DockWidgetMovable | QDockWidget::DockWidgetFloatable);
nuclear@14 21 addDockWidget(Qt::LeftDockWidgetArea, sidewin);
nuclear@14 22
nuclear@13 23 // actions
nuclear@13 24 QAction *act_open = new QAction(qApp->style()->standardIcon(QStyle::SP_DialogOpenButton), "&Open...", this);
nuclear@13 25 act_open->setStatusTip("Open a volume dataset");
nuclear@13 26 QObject::connect(act_open, SIGNAL(triggered()), this, SLOT(open_volume()));
nuclear@13 27
nuclear@13 28 QAction *act_quit = new QAction("&Quit", this);
nuclear@13 29 act_quit->setStatusTip("Quit");
nuclear@13 30 QObject::connect(act_quit, SIGNAL(triggered()), this, SLOT(close()));
nuclear@13 31
nuclear@13 32 // menus
nuclear@13 33 QMenu *mfile = menuBar()->addMenu("&File");
nuclear@13 34 mfile->addAction(act_open);
nuclear@13 35 mfile->addAction(act_quit);
nuclear@13 36
nuclear@13 37 // toolbars
nuclear@13 38 QToolBar *tfile = addToolBar("&File");
nuclear@13 39 tfile->addAction(act_open);
nuclear@13 40
nuclear@13 41 statusBar();
nuclear@13 42 show();
nuclear@13 43 }
nuclear@13 44
nuclear@13 45 void MainWindow::open_volume()
nuclear@13 46 {
nuclear@13 47 QString fname = QFileDialog::getOpenFileName(this, "Open volume dataset", QString(), "Volume descriptors (*.vol)");
nuclear@13 48 if(!fname.isNull()) {
nuclear@13 49 Volume *vol = new Volume;
nuclear@13 50
nuclear@13 51 if(vol->load(qPrintable(fname))) {
nuclear@13 52 delete volume;
nuclear@13 53 volume = vol;
nuclear@13 54 volray_setvolume(vol);
nuclear@13 55 post_redisplay();
nuclear@13 56 } else {
nuclear@13 57 delete vol;
nuclear@13 58 }
nuclear@13 59 }
nuclear@13 60 }
nuclear@13 61
nuclear@14 62
nuclear@14 63 SideWindow::SideWindow()
nuclear@14 64 {
nuclear@14 65 }
nuclear@14 66
nuclear@14 67
nuclear@13 68 void post_redisplay()
nuclear@13 69 {
nuclear@13 70 glview->updateGL();
nuclear@13 71 }
nuclear@13 72
nuclear@13 73
nuclear@13 74 GLView::GLView(QWidget *parent)
nuclear@13 75 : QGLWidget(QGLFormat(QGL::DoubleBuffer), parent)
nuclear@13 76 {
nuclear@13 77 }
nuclear@13 78
nuclear@13 79 QSize GLView::minimumSizeHint() const
nuclear@13 80 {
nuclear@13 81 return QSize(320, 200);
nuclear@13 82 }
nuclear@13 83
nuclear@13 84 QSize GLView::sizeHint() const
nuclear@13 85 {
nuclear@13 86 return QSize(1280, 800);
nuclear@13 87 }
nuclear@13 88
nuclear@13 89 void GLView::initializeGL()
nuclear@13 90 {
nuclear@13 91 if(!volray_init()) {
nuclear@13 92 exit(0);
nuclear@13 93 }
nuclear@13 94 }
nuclear@13 95
nuclear@13 96 void GLView::resizeGL(int xsz, int ysz)
nuclear@13 97 {
nuclear@13 98 volray_resize(xsz, ysz);
nuclear@13 99 }
nuclear@13 100
nuclear@13 101 void GLView::paintGL()
nuclear@13 102 {
nuclear@13 103 volray_draw();
nuclear@13 104 }
nuclear@13 105
nuclear@13 106 static int button_number(Qt::MouseButton bn)
nuclear@13 107 {
nuclear@13 108 switch(bn) {
nuclear@13 109 case Qt::LeftButton:
nuclear@13 110 return 0;
nuclear@13 111 case Qt::MidButton:
nuclear@13 112 return 1;
nuclear@13 113 case Qt::RightButton:
nuclear@13 114 return 2;
nuclear@13 115 default:
nuclear@13 116 break;
nuclear@13 117 }
nuclear@13 118 return -1;
nuclear@13 119 }
nuclear@13 120
nuclear@13 121 void GLView::mousePressEvent(QMouseEvent *ev)
nuclear@13 122 {
nuclear@13 123 int bn = button_number(ev->button());
nuclear@13 124 if(bn >= 0) {
nuclear@13 125 volray_mouse(bn, 1, ev->x(), ev->y());
nuclear@13 126 }
nuclear@13 127 }
nuclear@13 128
nuclear@13 129 void GLView::mouseReleaseEvent(QMouseEvent *ev)
nuclear@13 130 {
nuclear@13 131 int bn = button_number(ev->button());
nuclear@13 132 if(bn >= 0) {
nuclear@13 133 volray_mouse(bn, 0, ev->x(), ev->y());
nuclear@13 134 }
nuclear@13 135 }
nuclear@13 136
nuclear@13 137 void GLView::mouseMoveEvent(QMouseEvent *ev)
nuclear@13 138 {
nuclear@13 139 volray_motion(ev->x(), ev->y());
nuclear@13 140 }