14 #include "graphwidget.h"
21 #include <QMouseEvent>
22 #include "graphpainter.h"
24 #include "graphdialogconnector.h"
25 #include "ui_graphdialog.h"
29 XQGraph::XQGraph( QWidget* parent, Qt::WindowFlags fl ) :
30 QOpenGLWidget(parent) {
35 setMouseTracking(
true);
37 QSurfaceFormat format;
38 format.setAlphaBufferSize(8);
39 format.setDepthBufferSize(16);
42 format.setProfile(QSurfaceFormat::CoreProfile);
62 XQGraph::mousePressEvent ( QMouseEvent* e) {
63 if( !m_painter )
return;
65 switch (e->button()) {
67 mode = XQGraphPainter::SelAxis;
70 mode = XQGraphPainter::SelPlane;
73 mode = XQGraphPainter::TiltTracking;
76 mode = XQGraphPainter::SelNone;
79 m_painter->selectObjs(e->pos().x(), e->pos().y(), XQGraphPainter::SelStart, mode);
82 XQGraph::mouseMoveEvent ( QMouseEvent* e) {
83 static XTime lasttime = XTime::now();
84 if(XTime::now() - lasttime < 0.033)
return;
85 if( !m_painter )
return;
86 m_painter->selectObjs(e->pos().x(), e->pos().y(), XQGraphPainter::Selecting);
89 XQGraph::mouseReleaseEvent ( QMouseEvent* e) {
90 if( !m_painter )
return;
91 m_painter->selectObjs(e->pos().x(), e->pos().y(), XQGraphPainter::SelFinish);
94 XQGraph::mouseDoubleClickEvent ( QMouseEvent* e) {
96 if( !m_painter )
return;
98 switch (e->button()) {
100 m_painter->showHelp();
103 m_conDialog = xqcon_create<XQGraphDialogConnector>(
116 XQGraph::wheelEvent ( QWheelEvent *e) {
119 m_painter->wheel(e->pos().x(), e->pos().y(), (double)e->delta() / 8.0);
122 XQGraph::showEvent ( QShowEvent *) {
123 shared_ptr<XGraph> graph = m_graph;
133 XQGraph::hideEvent ( QHideEvent * ) {
142 m_painter->initializeGL();
145 XQGraph::resizeGL (
int width,
int height ) {
147 double pixel_ratio = devicePixelRatio();
148 glViewport( 0, 0, (GLint)(width * pixel_ratio),
149 (GLint)(height * pixel_ratio));
151 m_painter->resizeGL(width, height);
157 m_painter->paintGL();