/**************************************************************************** ** Copyright (c) 2021, Fougue Ltd. ** All rights reserved. ** See license at https://github.com/fougue/mayo/blob/master/LICENSE.txt ****************************************************************************/ #pragma once #include "../base/occ_handle.h" #include #include #include #include #if OCC_VERSION_HEX >= 0x070600 # include // WARNING Qt5 / Qt6 #endif #include namespace Mayo { // Base interface for bridging Qt and OpenCascade 3D view // IWidgetOccView does not handle input devices interaction like keyboard and mouse class IWidgetOccView { public: const OccHandle& v3dView() const { return m_view; } virtual void redraw() = 0; virtual QWidget* widget() = 0; virtual bool supportsWidgetOpacity() const = 0; using Creator = std::function&, QWidget*)>; static void setCreator(Creator fn); static IWidgetOccView* create(const OccHandle& view, QWidget* parent = nullptr); protected: IWidgetOccView(const OccHandle& view) : m_view(view) {} private: OccHandle m_view; }; #if OCC_VERSION_HEX >= 0x070600 // Integration of OpenCascade 7.6 with QOpenGLWidget allows widgets with translucid background to be // correctly displayed over V3d_View // QOpenGLWidgetOccView implementation is based on https://github.com/gkv311/occt-samples-qopenglwidget class QOpenGLWidgetOccView : public QOpenGLWidget, public IWidgetOccView { public: QOpenGLWidgetOccView(const OccHandle& view, QWidget* parent = nullptr); void redraw() override; QWidget* widget() override { return this; } bool supportsWidgetOpacity() const override { return true; } static QOpenGLWidgetOccView* create(const OccHandle& view, QWidget* parent); static OccHandle createCompatibleGraphicsDriver(); protected: // -- QOpenGLWidget void initializeGL() override; void paintGL() override; }; #endif // Fallback using traditional QWidget wrapper, no translucid background support class QWidgetOccView : public QWidget, public IWidgetOccView { public: QWidgetOccView(const OccHandle& view, QWidget* parent = nullptr); void redraw() override; QWidget* widget() override { return this; } bool supportsWidgetOpacity() const override { return false; } static QWidgetOccView* create(const OccHandle& view, QWidget* parent); static OccHandle createCompatibleGraphicsDriver(); protected: // -- QWidget void showEvent(QShowEvent* event) override; void paintEvent(QPaintEvent* event) override; void resizeEvent(QResizeEvent* event) override; QPaintEngine* paintEngine() const override { return nullptr; } }; } // namespace Mayo