From 12399b0c519bcd47788f917a87ffef2ace09a5b7 Mon Sep 17 00:00:00 2001 From: peri4 Date: Thu, 15 Jul 2021 16:00:01 +0300 Subject: [PATCH] no real OpenGL in Graphic in Qt Designer --- libs/graphic/graphic.cpp | 10 +++++----- libs/graphic/graphic.h | 5 ++++- libs/graphic/plugin/graphicplugin.cpp | 8 ++++++-- libs/graphic/plugin/graphicplugin.h | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/libs/graphic/graphic.cpp b/libs/graphic/graphic.cpp index ad3c1c8..ff86110 100644 --- a/libs/graphic/graphic.cpp +++ b/libs/graphic/graphic.cpp @@ -61,7 +61,7 @@ Graphic::Graphic(QWidget * parent): QFrame(parent), canvas(0), line_x_min(this), canvas_gl = 0; gesture_angle = 45.; leg_update = true; - visible_update = fullscr = need_mouse_pan = false; + visible_update = fullscr = need_mouse_pan = m_fakeGL = false; gestures = #ifdef Q_OS_ANDROID true; @@ -334,7 +334,7 @@ void Graphic::canvasPaintEvent() { } QPainter p; #ifdef HAS_GL - if (isOGL) { + if (isOGL && !m_fakeGL) { p.fillRect(canvas->rect(), Qt::black); glClearColor(0.f, 0.f, 0.f, 0.f); p.begin(canvas); @@ -358,7 +358,7 @@ void Graphic::canvasPaintEvent() { drawGrid(); p.setRenderHint(QPainter::Antialiasing, aalias); #ifdef HAS_GL - if (isOGL) { + if (isOGL && !m_fakeGL) { if (aalias) glEnable(GL_MULTISAMPLE); else glDisable(GL_MULTISAMPLE); } @@ -370,7 +370,7 @@ void Graphic::canvasPaintEvent() { if (pause_) drawPause(); emit graphicPaintEvent(painter); p.end(); - if (isOGL) return; + if (isOGL && !m_fakeGL) return; p.begin(canvas); p.drawImage(0, 0, *buffer); p.end(); @@ -863,7 +863,7 @@ void Graphic::exportGraphics(QString filename) { void Graphic::setOpenGL(bool on) { #ifdef HAS_GL isOGL = on; - if (on) { + if (on && !m_fakeGL) { if (!canvas_gl) { canvas_gl = new UGLWidget(); ui->layoutCanvas->addWidget(canvas_gl); diff --git a/libs/graphic/graphic.h b/libs/graphic/graphic.h index de6f86f..e6d28ea 100644 --- a/libs/graphic/graphic.h +++ b/libs/graphic/graphic.h @@ -44,6 +44,7 @@ namespace Ui { class UGLWidget; +class GraphicPlugin; Q_DECLARE_METATYPE(QVector) @@ -119,6 +120,8 @@ class QAD_GRAPHIC_EXPORT Graphic: public QFrame Q_PROPERTY(Graphic::GraphicsData graphicsData READ graphicsData WRITE setGraphicsData) Q_PROPERTY(QByteArray graphicsDataRaw READ graphicsDataRaw WRITE setGraphicsDataRaw) + friend class GraphicPlugin; + public: Graphic(QWidget * parent = 0); virtual ~Graphic(); @@ -406,7 +409,7 @@ protected: double gridx, gridy, history, visible_time, inc_x, grid_numbers_x, grid_numbers_y, LN10; double eminx, eminy, emaxx, emaxy, pause_phase, gesture_angle; int lastw, lasth, min_repaint_int, timer_pause, thick; - bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures, m_LODOptimization; + bool aalias, aupdate, grid, guides, isFit, isOGL, isHover, bufferActive, cancel, pause_, gestures, m_LODOptimization, m_fakeGL; bool hasLblX, hasLblY, navigation, only_expand_y, only_expand_x, is_lines_update, leg_update, visible_update, fullscr, need_mouse_pan; protected slots: diff --git a/libs/graphic/plugin/graphicplugin.cpp b/libs/graphic/plugin/graphicplugin.cpp index c4ff495..4a0afc2 100644 --- a/libs/graphic/plugin/graphicplugin.cpp +++ b/libs/graphic/plugin/graphicplugin.cpp @@ -4,11 +4,12 @@ GraphicPlugin::GraphicPlugin(QObject * parent): QObject(parent) { - m_initialized = false; + m_initialized = m_designer = false; } void GraphicPlugin::initialize(QDesignerFormEditorInterface * /* core */) { + m_designer = true; if (m_initialized) return; @@ -24,7 +25,10 @@ bool GraphicPlugin::isInitialized() const { QWidget * GraphicPlugin::createWidget(QWidget * parent) { - return new Graphic(parent); + auto ret = new Graphic(parent); + if (m_designer) + ret->m_fakeGL = true; + return ret; } diff --git a/libs/graphic/plugin/graphicplugin.h b/libs/graphic/plugin/graphicplugin.h index 4112d65..58af1a4 100644 --- a/libs/graphic/plugin/graphicplugin.h +++ b/libs/graphic/plugin/graphicplugin.h @@ -29,7 +29,7 @@ public: void initialize(QDesignerFormEditorInterface * core); private: - bool m_initialized; + bool m_initialized, m_designer; };