track labels
[mussa.git] / qui / PathScene.cpp
1 #include <QDir>
2 #include <QFileDialog>
3 #include <QMessageBox>
4 #include <QMouseEvent>
5 #include <QRubberBand>
6 #include <QRect>
7 #include <QString>
8 #include <iostream>
9 #include <set>
10
11 #include <GL/gl.h>
12 #include <math.h>
13
14 #include "qui/PathScene.hpp"
15 #include "alg/glsequence.hpp"
16 #include "mussa_exceptions.hpp"
17
18 using namespace std;
19
20 PathScene::PathScene(QWidget *parent)
21   : QGLWidget(parent),
22     rubberBand(0),
23     drawingBand(false)
24
25 }
26
27 QSize PathScene::sizeHint() const
28 {
29   //return QSize((int)GlTracks::viewportHeight(), (int)GlTracks::viewportWidth());
30   return QSize(600, 400);
31 }
32
33 void PathScene::setViewportCenter(float x)
34 {
35   const float epsilon = 1e-10;
36   float center = GlTracks::viewportCenter();
37   float difference = fabsf(x - center);
38   float abs_x = fabsf(x);
39   center = fabsf(center);
40
41   // the difference < epsilon * val is one of the recommended tests
42   // for float equality.
43   // of course since we're looking for not equals, we need to toss a
44   // not at the beginning
45   if (not (difference < epsilon * abs_x or difference < epsilon * center))
46   {
47     GlTracks::setViewportCenter(x);
48     emit viewportChanged();
49     update();
50   }
51 }
52
53 void PathScene::setZoom(int new_zoom)
54 {
55   if (new_zoom != GlTracks::zoom()) {
56     GlTracks::setZoom(new_zoom);
57     emit viewportChanged();
58     update();
59   }
60 }
61
62 void PathScene::setClipPlane(int )
63 {
64 /*
65   if (clipZ != (double) newZ){
66     clipZ = (double) newZ;
67     update();
68   }
69 */
70 }
71
72 void PathScene::clear()
73 {
74   GlTracks::clear();
75   emit tracksChanged();
76 }
77
78 void PathScene::push_sequence(const Sequence &s)
79 {
80   GlTracks::push_sequence(s);
81   emit tracksChanged();
82 }
83
84 void PathScene::push_sequence(GlSequence &gs)
85 {
86   GlTracks::push_sequence(gs);
87   emit tracksChanged();
88 }
89
90 ////////////////////
91 // Rendering code
92 void PathScene::initializeGL()
93 {
94   GlTracks::initializeGL();
95 }
96
97 void PathScene::resizeGL(int width, int height)
98 {
99   GlTracks::resizeGL(width, height);
100 }
101
102 void PathScene::paintGL()
103 {
104   GlTracks::paintGL();
105 }
106
107 void PathScene::mousePressEvent( QMouseEvent *e)
108 {
109   drawingBand = true;
110
111   selectedMode = false;
112   bandOrigin = e->pos();
113   if (!rubberBand)
114     rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
115   
116   rubberBand->setGeometry(QRect(bandOrigin, QSize()));
117   rubberBand->show();
118 }
119
120 void PathScene::mouseMoveEvent( QMouseEvent *e)
121 {
122   if (drawingBand)
123     rubberBand->setGeometry(QRect(bandOrigin, e->pos()).normalized());
124 }
125
126 void PathScene::mouseReleaseEvent( QMouseEvent *e)
127 {
128   drawingBand = false;
129   rubberBand->hide();
130   QRect r = QRect(bandOrigin, e->pos()).normalized();
131   bandOrigin = r.topLeft();
132
133   selectRegion(r.top(), r.left(), r.bottom(), r.right());
134 }