Mercurial > hg > octave-lyh
annotate gui/src/Plot2dWidget.cpp @ 13471:4baf5e6bba13
Modifications to plotting.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Wed, 20 Apr 2011 10:18:02 +0200 |
parents | f7356554594c |
children | 5dcf3331f2a6 |
rev | line source |
---|---|
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
1 #include "Plot2dWidget.h" |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
2 #include <QVBoxLayout> |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
3 #include <QHBoxLayout> |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
4 #include <QPushButton> |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
5 #include <QTimer> |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
6 #include <math.h> |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
7 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
8 Plot2dView::Plot2dView(QWidget *parent) |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
9 : QGLWidget(parent) { |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
10 construct(); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
11 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
12 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
13 void Plot2dView::construct() { |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
14 QTimer *animationTimer = new QTimer(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
15 animationTimer->setInterval(20); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
16 animationTimer->start(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
17 m_zoom = 1.0; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
18 m_scrollX = 0.0; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
19 m_scrollY = 0.0; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
20 m_leftMouseButtonDown = false; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
21 connect(animationTimer, SIGNAL(timeout()), this, SLOT(animate())); |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
22 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
23 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
24 void Plot2dView::initializeGL() { |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
25 glClearColor(0.0,0.0, 0.0, 0.0); |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
26 glEnable(GL_POINT_SMOOTH); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
27 // glEnable(GL_LINE_SMOOTH); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
28 glEnable(GL_POLYGON_SMOOTH); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
29 glEnable(GL_BLEND); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
30 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
31 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
32 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
33 void Plot2dView::paintGL() { |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
34 glMatrixMode(GL_MODELVIEW_MATRIX); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
35 glLoadIdentity(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
36 glScaled(m_zoom, m_zoom, 0.0); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
37 glTranslated(-0.5 - m_scrollX, -0.5 - m_scrollY, 0.0); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
38 |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
39 glClear(GL_COLOR_BUFFER_BIT); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
40 glBegin(GL_LINES); |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
41 glColor3d(1.0, 1.0, 1.0); |
13471
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
42 glVertex2d(0.0, 0.0); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
43 glVertex2d(1.0, 0.0); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
44 glVertex2d(0.0, 0.0); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
45 glVertex2d(0.0, 1.0); |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
46 glEnd(); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
47 |
13471
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
48 for(double phi = 0.0; phi < 2*3.141; phi += 2*3.141 / 3) { |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
49 glBegin(GL_LINES); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
50 glColor3d(phi / (2 * 3.141), 1.0, 1.0 - phi / (2 * 3.141)); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
51 for(double d = 0.0; d < 1.0; d +=0.01) |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
52 glVertex2d(d, sin(d*2*3.141 + phi) / 2 + 0.5); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
53 glEnd(); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
54 } |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
55 |
13471
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
56 glMatrixMode(GL_MODELVIEW_MATRIX); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
57 glLoadIdentity(); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
58 |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
59 glColor3d(1.0, 1.0, 1.0); |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
60 renderText(-0.9, -0.9, 0.0, QString("Scaling: %1, Translation: (%2/%3)") |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
61 .arg(m_zoom) |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
62 .arg(m_scrollX) |
4baf5e6bba13
Modifications to plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13470
diff
changeset
|
63 .arg(m_scrollY)); |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
64 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
65 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
66 void Plot2dView::resizeGL(int w, int h) { |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
67 glViewport(0, 0, w, h); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
68 glMatrixMode(GL_MODELVIEW_MATRIX); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
69 glLoadIdentity(); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
70 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
71 glMatrixMode(GL_PROJECTION_MATRIX); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
72 glLoadIdentity(); |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
73 glOrtho(-1.0, 1.0, -1.0, 1.0, 0.0, 100.0); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
74 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
75 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
76 void Plot2dView::wheelEvent(QWheelEvent *wheelEvent) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
77 m_zoomAcceleration += ((double)wheelEvent->delta()) / 5000; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
78 wheelEvent->accept(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
79 updateGL(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
80 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
81 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
82 void Plot2dView::mousePressEvent(QMouseEvent *mouseEvent) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
83 if(mouseEvent->button() == Qt::LeftButton) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
84 m_leftMouseButtonDown = true; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
85 m_lastMouseButtonDownX = mouseEvent->x(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
86 m_lastMouseButtonDownY = mouseEvent->y(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
87 mouseEvent->accept(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
88 } |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
89 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
90 |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
91 void Plot2dView::mouseReleaseEvent(QMouseEvent *mouseEvent) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
92 if(mouseEvent->button() == Qt::LeftButton) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
93 m_leftMouseButtonDown = false; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
94 mouseEvent->accept(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
95 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
96 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
97 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
98 void Plot2dView::mouseMoveEvent(QMouseEvent *mouseEvent) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
99 if(m_leftMouseButtonDown) { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
100 m_scrollX -= ((double)mouseEvent->x() - m_lastMouseButtonDownX) / 100; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
101 m_scrollY += ((double)mouseEvent->y() - m_lastMouseButtonDownY) / 100; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
102 m_lastMouseButtonDownX = (double)mouseEvent->x(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
103 m_lastMouseButtonDownY = (double)mouseEvent->y(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
104 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
105 updateGL(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
106 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
107 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
108 void Plot2dView::animate() { |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
109 m_zoom += m_zoomAcceleration; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
110 if(m_zoom < 0) |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
111 m_zoom = 0; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
112 m_zoomAcceleration *= 0.2; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
113 if(abs(m_zoomAcceleration) < 0.01) |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
114 m_zoomAcceleration = 0; |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
115 updateGL(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
116 } |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
117 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
118 Plot2dWidget::Plot2dWidget(QWidget *parent) |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
119 : QWidget(parent) { |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
120 construct(); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
121 } |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
122 |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
123 void Plot2dWidget::construct() { |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
124 QVBoxLayout *layout = new QVBoxLayout(); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
125 m_plot2dView = new Plot2dView(this); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
126 m_plot2dView->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
127 layout->addWidget(m_plot2dView); |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
128 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
129 m_tabWidget = new QTabWidget(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
130 m_tabWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
131 layout->addWidget(m_tabWidget); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
132 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
133 m_dataSourceTab = new QWidget(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
134 m_verticalAxisTab = new QWidget(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
135 m_horizontalAxisTab = new QWidget(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
136 m_tabWidget->addTab(m_dataSourceTab, tr("Data Source")); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
137 m_tabWidget->addTab(m_verticalAxisTab, tr("Vertical Axis")); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
138 m_tabWidget->addTab(m_horizontalAxisTab, tr("Horizontal Axis")); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
139 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
140 // Build data source tab. |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
141 QHBoxLayout *dataSourceTabLayout = new QHBoxLayout(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
142 |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
143 m_dataSourceTypeComboBox = new QComboBox(this); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
144 m_dataSourceTypeComboBox->addItem(tr("Parameterized")); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
145 m_dataSourceTypeComboBox->addItem(tr("Sampled")); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
146 dataSourceTabLayout->addWidget(m_dataSourceTypeComboBox); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
147 dataSourceTabLayout->addStretch(); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
148 m_dataSourceTab->setLayout(dataSourceTabLayout); |
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
149 |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
150 layout->setMargin(0); |
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
151 setLayout(layout); |
13470
f7356554594c
Plot can be moved around with mouse and zoomed with scrollwheel.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
13469
diff
changeset
|
152 |
13469
a20f8763105f
Added some OpenGL plotting.
Jacob Dawid <jacob.dawid@googlemail.com>
parents:
diff
changeset
|
153 } |