diff --git a/qad/graphic/graphic.cpp b/qad/graphic/graphic.cpp index ad88d06..b75d938 100644 --- a/qad/graphic/graphic.cpp +++ b/qad/graphic/graphic.cpp @@ -1,12 +1,18 @@ #include "graphic.h" #include "qad_types.h" +#include "uglwidget.h" #include "ui_graphic.h" #include "ui_graphic_conf.h" #if QT_VERSION >= 0x050100 //# include #endif -#ifndef GL_MULTISAMPLE -# define GL_MULTISAMPLE 0x809D +#ifndef Q_OS_ANDROID +# define HAS_GL +#endif +#ifdef HAS_GL +# ifndef GL_MULTISAMPLE +# define GL_MULTISAMPLE 0x809D +# endif #endif @@ -54,20 +60,24 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max connect(ui->canvas_raster, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * ))); connect(ui->canvas_raster, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * ))); connect(ui->canvas_raster, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * ))); - connect(ui->canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent())); - connect(ui->canvas_gl, SIGNAL(mouseMoveEvent(QMouseEvent * )), this, SLOT(canvasMouseMoveEvent(QMouseEvent * ))); - connect(ui->canvas_gl, SIGNAL(mousePressEvent(QMouseEvent * )), this, SLOT(canvasMousePressEvent(QMouseEvent * ))); - connect(ui->canvas_gl, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(canvasMouseReleaseEvent(QMouseEvent * ))); - connect(ui->canvas_gl, SIGNAL(mouseDoubleClickEvent(QMouseEvent*)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent * ))); - connect(ui->canvas_gl, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * ))); - connect(ui->canvas_gl, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * ))); - connect(ui->canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * ))); +#ifdef HAS_GL + canvas_gl = new UGLWidget(); + ui->layoutCanvas->addWidget(canvas_gl); + connect(canvas_gl, SIGNAL(paintSignal()), this, SLOT(canvasPaintEvent())); + connect(canvas_gl, SIGNAL(mouseMoveEvent(QMouseEvent * )), this, SLOT(canvasMouseMoveEvent(QMouseEvent * ))); + connect(canvas_gl, SIGNAL(mousePressEvent(QMouseEvent * )), this, SLOT(canvasMousePressEvent(QMouseEvent * ))); + connect(canvas_gl, SIGNAL(mouseReleaseEvent(QMouseEvent * )), this, SLOT(canvasMouseReleaseEvent(QMouseEvent * ))); + connect(canvas_gl, SIGNAL(mouseDoubleClickEvent(QMouseEvent*)), this, SLOT(canvasMouseDoubleClickEvent(QMouseEvent * ))); + connect(canvas_gl, SIGNAL(wheelEvent(QWheelEvent * )), this, SLOT(canvasWheelEvent(QWheelEvent * ))); + connect(canvas_gl, SIGNAL(leaveEvent(QEvent * )), this, SLOT(canvasLeaveEvent(QEvent * ))); + connect(canvas_gl, SIGNAL(keyPressEvent(QKeyEvent * )), this, SLOT(canvasKeyPressEvent(QKeyEvent * ))); + canvas_gl->grabGesture(Qt::PinchGesture); + canvas_gl->grabGesture(Qt::PanGesture); + canvas_gl->installEventFilter(this); +#endif ui->canvas_raster->grabGesture(Qt::PinchGesture); ui->canvas_raster->grabGesture(Qt::PanGesture); ui->canvas_raster->installEventFilter(this); - ui->canvas_gl->grabGesture(Qt::PinchGesture); - ui->canvas_gl->grabGesture(Qt::PanGesture); - ui->canvas_gl->installEventFilter(this); icon_exp_x = QIcon(":/icons/expand_x.png"); icon_exp_y = QIcon(":/icons/expand_y.png"); icon_exp_sx = QIcon(":/icons/expand_s_x.png"); @@ -111,8 +121,8 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), line_x_min(this), line_x_max selpen.setStyle(Qt::DashLine); back_color = Qt::white; buttons_ = AllButtons; - setButtonsPosition(Graphic::Left); setOpenGL(false); + setButtonsPosition(Graphic::Left); setAntialiasing(false); setCaption(""); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -207,14 +217,14 @@ void Graphic::canvasPaintEvent() { //pwid = wid; //phei = hei; QPainter p; +#ifdef HAS_GL if (isOGL) { -#ifdef ANDROID p.fillRect(canvas->rect(), Qt::black); -#else glClearColor(0.f, 0.f, 0.f, 0.f); -#endif p.begin(canvas); - } else p.begin(buffer); + } else +#endif + p.begin(buffer); p.fillRect(canvas->rect(), back_color); painter = &p; p.setFont(font()); @@ -231,12 +241,12 @@ void Graphic::canvasPaintEvent() { if (grid) drawGrid(); p.setRenderHint(QPainter::Antialiasing, aalias); - if (isOGL) { #ifndef ANDROID + if (isOGL) { if (aalias) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); -#endif } +#endif //p.setRenderHint(QPainter::HighQualityAntialiasing, aalias); if (!aalias) p.translate(-0.5, -0.5); drawGraphics(); @@ -305,7 +315,9 @@ void Graphic::canvasMouseMoveEvent(QMouseEvent * e) { void Graphic::canvasMousePressEvent(QMouseEvent * e) { emit graphicMousePressEvent(canvas2real(QPointF(e->pos())), e->buttons()); if (!navigation) return; - ui->canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); +#ifdef HAS_GL + canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); +#endif ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); prevpos = e->pos(); startpos = prevpos; @@ -344,7 +356,9 @@ void Graphic::canvasMousePressEvent(QMouseEvent * e) { void Graphic::canvasMouseReleaseEvent(QMouseEvent * e) { emit graphicMouseReleaseEvent(canvas2real(QPointF(e->pos())), e->buttons()); if (!navigation) return; - ui->canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); +#ifdef HAS_GL + canvas_gl->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); +#endif ui->canvas_raster->setCursor(guides ? Qt::BlankCursor : Qt::ArrowCursor); QPointF tlp, brp; QRect sr; @@ -467,9 +481,9 @@ void Graphic::clear() { void Graphic::setAntialiasing(bool enabled) { if (aalias == enabled) return; aalias = enabled; - /*QGLFormat f = ui->canvas_gl->format(); + /*QGLFormat f = canvas_gl->format(); f.setSampleBuffers(enabled); - ui->canvas_gl->setFormat(f);*/ + canvas_gl->setFormat(f);*/ update(); } @@ -669,16 +683,22 @@ void Graphic::saveImage() { void Graphic::setOpenGL(bool on) { +#ifdef HAS_GL isOGL = on; if (on) { ui->canvas_raster->hide(); - ui->canvas_gl->show(); - canvas = ui->canvas_gl; + canvas_gl->show(); + canvas = canvas_gl; } else { - ui->canvas_gl->hide(); + canvas_gl->hide(); ui->canvas_raster->show(); canvas = ui->canvas_raster; } +#else + isOGL = false; + ui->canvas_raster->show(); + canvas = ui->canvas_raster; +#endif /*line_x_min.setParent(canvas); line_x_max.setParent(canvas); line_y_min.setParent(canvas); @@ -1264,19 +1284,23 @@ void Graphic::setCurrentAction(GraphicAction action) { void Graphic::setCanvasCursor(QCursor cursor) { ui->canvas_raster->setCursor(cursor); - ui->canvas_gl->setCursor(cursor); +#ifdef HAS_GL + canvas_gl->setCursor(cursor); +#endif } void Graphic::swapToBuffer() { QImage timg; //qDebug() << "render start"; +#ifdef HAS_GL if (isOGL) { - timg = ui->canvas_gl->grabFrameBuffer(); + timg = canvas_gl->grabFrameBuffer(); QPainter p(buffer); p.drawImage(0, 0, timg); p.end(); } +#endif //qDebug() << "render finish"; bufferActive = true; } diff --git a/qad/graphic/graphic.h b/qad/graphic/graphic.h index ed4cdc1..467fb72 100644 --- a/qad/graphic/graphic.h +++ b/qad/graphic/graphic.h @@ -27,6 +27,7 @@ namespace Ui { class Graphic; }; +class UGLWidget; class Graphic: public QFrame { @@ -343,6 +344,7 @@ protected: QPair gridMark(double v) const; Ui::Graphic * ui; + UGLWidget * canvas_gl; ///QMutex mutex, mutex_; QWidget * canvas; QImage * buffer; diff --git a/qad/graphic/graphic.ui b/qad/graphic/graphic.ui index 7b23d2b..f096c8a 100644 --- a/qad/graphic/graphic.ui +++ b/qad/graphic/graphic.ui @@ -64,7 +64,7 @@ Grid - + :/icons/view-grid.png:/icons/view-grid.png @@ -81,7 +81,7 @@ Cursor axis - + :/icons/edit-guides.png:/icons/edit-guides.png @@ -95,7 +95,7 @@ Only expand Y - + :/icons/expand_s_y.png:/icons/expand_s_y.png @@ -109,7 +109,7 @@ Only expand X - + :/icons/expand_s_x.png:/icons/expand_s_x.png @@ -134,7 +134,7 @@ Border inputs - + :/icons/border-line.png:/icons/border-line.png @@ -151,7 +151,7 @@ Legend - + :/icons/legend.png:/icons/legend.png @@ -182,7 +182,7 @@ Configure ... - + :/icons/configure.png:/icons/configure.png @@ -193,7 +193,7 @@ Save image ... - + :/icons/document-save.png:/icons/document-save.png @@ -220,7 +220,7 @@ Clear - + :/icons/edit-clear.png:/icons/edit-clear.png @@ -231,7 +231,7 @@ Close - + :/icons/dialog-close.png:/icons/dialog-close.png @@ -338,13 +338,6 @@ 0 - - - - true - - - @@ -439,14 +432,10 @@ QWidget
uwidget.h
- - UGLWidget - QWidget -
uglwidget.h
-
- + +