diff --git a/toonz/sources/include/toonzqt/pickrgbutils.h b/toonz/sources/include/toonzqt/pickrgbutils.h index abfea52..e298300 100644 --- a/toonz/sources/include/toonzqt/pickrgbutils.h +++ b/toonz/sources/include/toonzqt/pickrgbutils.h @@ -23,7 +23,7 @@ // Forward declarations class QWidget; -class QGLWidget; +class QOpenGLWidget; //------------------------------------------------------------------------------- @@ -33,7 +33,7 @@ class QGLWidget; widget bounds. \warning Use this function only on plain widgets - in case your widget inherits - QGLWidget, invoke the overloaded function accepting a QGLWidget* type + QOpenGLWidget, invoke the overloaded function accepting a QOpenGLWidget* type instead. */ QRgb DVAPI pickRGB(QWidget *widget, const QRect &rect); @@ -42,14 +42,14 @@ inline QRgb pickRGB(QWidget *widget, const QPoint &pos) return pickRGB(widget, QRect(pos.x(), pos.y(), 1, 1)); } -//! Returns the average color displayed in a QGLWidget instance across the specified rect. +//! Returns the average color displayed in a QOpenGLWidget instance across the specified rect. /*! This function reads the widget's front frame buffer on given rect, and returns a mean of its pixels. \warning Pixel colors are undefined outside the widget's geometry. */ -QRgb DVAPI pickRGB(QGLWidget *widget, const QRect &rect); -inline QRgb pickRGB(QGLWidget *widget, const QPoint &pos) +QRgb DVAPI pickRGB(QOpenGLWidget *widget, const QRect &rect); +inline QRgb pickRGB(QOpenGLWidget *widget, const QPoint &pos) { return pickRGB(widget, QRect(pos.x(), pos.y(), 1, 1)); } diff --git a/toonz/sources/include/toonzqt/planeviewer.h b/toonz/sources/include/toonzqt/planeviewer.h index e6cf865..e19e888 100644 --- a/toonz/sources/include/toonzqt/planeviewer.h +++ b/toonz/sources/include/toonzqt/planeviewer.h @@ -9,7 +9,7 @@ #include "timage.h" // Qt includes -#include +#include #undef DVAPI #undef DVVAR @@ -44,10 +44,10 @@ class TVectorImageP; efficient image-drawing functions for all Toonz image types. */ -class DVAPI PlaneViewer : public QGLWidget +class DVAPI PlaneViewer : public QOpenGLWidget { public: - PlaneViewer(QWidget *parent = 0); + PlaneViewer(QWidget *parent); // Background functions void setBgColor(const TPixel32 &color1, const TPixel32 &color2); @@ -113,18 +113,20 @@ protected: double m_zoomRange[2]; //!< Viewport zoom range (default: [-1024, 1024]). protected: - virtual void mouseMoveEvent(QMouseEvent *event); - virtual void mousePressEvent(QMouseEvent *event); - virtual void wheelEvent(QWheelEvent *event); - virtual void keyPressEvent(QKeyEvent *event); - virtual void resizeEvent(QResizeEvent *event); - virtual void hideEvent(QHideEvent *event); + virtual void mouseMoveEvent(QMouseEvent *event) override; + virtual void mousePressEvent(QMouseEvent *event) override; + virtual void wheelEvent(QWheelEvent *event) override; + virtual void keyPressEvent(QKeyEvent *event) override; + virtual void hideEvent(QHideEvent *event) override; - void initMatrix(); + void initializeGL() override final; + void resizeGL(int width, int height) override final; private: GLdouble m_matrix[16]; bool m_firstResize; + int m_width; + int m_height; }; #endif //PLANE_VIEWER_H diff --git a/toonz/sources/include/toonzqt/styleeditor.h b/toonz/sources/include/toonzqt/styleeditor.h index ed6b804..1957d49 100644 --- a/toonz/sources/include/toonzqt/styleeditor.h +++ b/toonz/sources/include/toonzqt/styleeditor.h @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include #include @@ -141,7 +141,7 @@ enum CurrentWheel { rightTriangle }; -class DVAPI HexagonalColorWheel : public QGLWidget +class DVAPI HexagonalColorWheel : public QOpenGLWidget { Q_OBJECT diff --git a/toonz/sources/tnztools/hooktool.cpp b/toonz/sources/tnztools/hooktool.cpp index 1bace70..fa457f9 100644 --- a/toonz/sources/tnztools/hooktool.cpp +++ b/toonz/sources/tnztools/hooktool.cpp @@ -38,7 +38,6 @@ #include #include -#include using namespace ToolUtils; diff --git a/toonz/sources/tnztools/skeletontool.cpp b/toonz/sources/tnztools/skeletontool.cpp index ce0c906..abf7864 100644 --- a/toonz/sources/tnztools/skeletontool.cpp +++ b/toonz/sources/tnztools/skeletontool.cpp @@ -40,7 +40,7 @@ // Qt includes #include // Qt translation support #include -#include +#include // for QGLWidget::convertToGLFormat #include #include #include diff --git a/toonz/sources/tnztools/toolutils.cpp b/toonz/sources/tnztools/toolutils.cpp index d51951c..4012322 100644 --- a/toonz/sources/tnztools/toolutils.cpp +++ b/toonz/sources/tnztools/toolutils.cpp @@ -41,7 +41,7 @@ #include "tools/strokeselection.h" #include -#include +#include // for QGLWidget::convertToGLFormat #include #include diff --git a/toonz/sources/toonz/adjustlevelspopup.cpp b/toonz/sources/toonz/adjustlevelspopup.cpp index e1e3d4b..24f7e1d 100644 --- a/toonz/sources/toonz/adjustlevelspopup.cpp +++ b/toonz/sources/toonz/adjustlevelspopup.cpp @@ -111,7 +111,7 @@ public: TRasterP raster() const { return m_ras; } TRasterP &raster() { return m_ras; } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/adjustthicknesspopup.cpp b/toonz/sources/toonz/adjustthicknesspopup.cpp index e7a4f2f..f6fdb69 100644 --- a/toonz/sources/toonz/adjustthicknesspopup.cpp +++ b/toonz/sources/toonz/adjustthicknesspopup.cpp @@ -245,7 +245,7 @@ public: TVectorImageP image() const { return m_vi; } TVectorImageP &image() { return m_vi; } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/antialiaspopup.cpp b/toonz/sources/toonz/antialiaspopup.cpp index f78b406..227fb5f 100644 --- a/toonz/sources/toonz/antialiaspopup.cpp +++ b/toonz/sources/toonz/antialiaspopup.cpp @@ -88,7 +88,7 @@ public: void setImage(const TImageP &img) { m_img = img; } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/binarizepopup.cpp b/toonz/sources/toonz/binarizepopup.cpp index 0736a90..11902a8 100644 --- a/toonz/sources/toonz/binarizepopup.cpp +++ b/toonz/sources/toonz/binarizepopup.cpp @@ -141,7 +141,7 @@ public: TRasterP raster() const { return m_ras; } TRasterP &raster() { return m_ras; } - void paintGL() + void paintGL() override { pushGLWorldCoordinates(); drawBackground(); diff --git a/toonz/sources/toonz/brightnessandcontrastpopup.cpp b/toonz/sources/toonz/brightnessandcontrastpopup.cpp index 2e61c9d..4a0058e 100644 --- a/toonz/sources/toonz/brightnessandcontrastpopup.cpp +++ b/toonz/sources/toonz/brightnessandcontrastpopup.cpp @@ -218,7 +218,7 @@ public: TRasterP raster() const { return m_ras; } TRasterP &raster() { return m_ras; } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/comboviewerpane.cpp b/toonz/sources/toonz/comboviewerpane.cpp index 4553e99..5ce1d92 100644 --- a/toonz/sources/toonz/comboviewerpane.cpp +++ b/toonz/sources/toonz/comboviewerpane.cpp @@ -57,7 +57,6 @@ #include #include #include -#include #include #include #include diff --git a/toonz/sources/toonz/exportlevelpopup.cpp b/toonz/sources/toonz/exportlevelpopup.cpp index f4b5431..01607a1 100644 --- a/toonz/sources/toonz/exportlevelpopup.cpp +++ b/toonz/sources/toonz/exportlevelpopup.cpp @@ -119,10 +119,10 @@ public: TImageP &image() { return m_img; } protected: - void showEvent(QShowEvent *se); - void keyPressEvent(QKeyEvent *ke); + void showEvent(QShowEvent *se) override; + void keyPressEvent(QKeyEvent *ke) override; void keyPressEvent(QShowEvent *se); - void paintGL(); + void paintGL() override; void setActualPixelSize(); diff --git a/toonz/sources/toonz/flipbook.cpp b/toonz/sources/toonz/flipbook.cpp index 1e25c7b..db347be 100644 --- a/toonz/sources/toonz/flipbook.cpp +++ b/toonz/sources/toonz/flipbook.cpp @@ -1887,14 +1887,14 @@ void FlipBook::reset() void FlipBook::showEvent(QShowEvent *e) { TSceneHandle *sceneHandle = TApp::instance()->getCurrentScene(); - connect(sceneHandle, SIGNAL(sceneChanged()), m_imageViewer, SLOT(updateGL())); + connect(sceneHandle, SIGNAL(sceneChanged()), m_imageViewer, SLOT(update())); // for updating the blank frame button if (!m_imageViewer->isColorModel()) { connect(sceneHandle, SIGNAL(preferenceChanged()), m_flipConsole, SLOT(onPreferenceChanged())); m_flipConsole->onPreferenceChanged(); } m_flipConsole->setActive(true); - m_imageViewer->updateGL(); + m_imageViewer->update(); } //------------------------------------------------------------------- @@ -1902,7 +1902,7 @@ void FlipBook::showEvent(QShowEvent *e) void FlipBook::hideEvent(QHideEvent *e) { TSceneHandle *sceneHandle = TApp::instance()->getCurrentScene(); - disconnect(sceneHandle, SIGNAL(sceneChanged()), m_imageViewer, SLOT(updateGL())); + disconnect(sceneHandle, SIGNAL(sceneChanged()), m_imageViewer, SLOT(update())); m_flipConsole->setActive(false); } diff --git a/toonz/sources/toonz/imageviewer.cpp b/toonz/sources/toonz/imageviewer.cpp index 68220de..693eb58 100644 --- a/toonz/sources/toonz/imageviewer.cpp +++ b/toonz/sources/toonz/imageviewer.cpp @@ -189,7 +189,7 @@ public: /*! \class ImageViewer \brief The ImageViewer class provides to view an image. - Inherits \b QGLWidget. + Inherits \b QOpenGLWidget. The object allows also to manage pan and zoom event. It's possible to set a color mask TRop::ColorMask to image view. @@ -205,10 +205,22 @@ public: */ ImageViewer::ImageViewer(QWidget *parent, FlipBook *flipbook, bool showHistogram) - : QGLWidget(parent), m_pressedMousePos(0, 0), m_mouseButton(Qt::NoButton), m_draggingZoomSelection(false), m_image(), m_FPS(0), m_viewAff(), m_pos(0, 0), m_visualSettings(), m_compareSettings(), m_isHistogramEnable(showHistogram), m_flipbook(flipbook), m_isColorModel(false), m_histogramPopup(0), m_isRemakingPreviewFx(false) - //, m_ghibli3DLutUtil(0) //iwsw commented out temporarily - , - m_rectRGBPick(false) + : QOpenGLWidget(parent) + , m_pressedMousePos(0, 0) + , m_mouseButton(Qt::NoButton) + , m_draggingZoomSelection(false) + , m_image() + , m_FPS(0) + , m_viewAff() + , m_pos(0, 0) + , m_visualSettings() + , m_compareSettings() + , m_isHistogramEnable(showHistogram) + , m_flipbook(flipbook) + , m_isColorModel(false) + , m_histogramPopup(0) + , m_isRemakingPreviewFx(false) + , m_rectRGBPick(false) { m_visualSettings.m_sceneProperties = TApp::instance()->getCurrentScene()->getScene()->getProperties(); m_visualSettings.m_drawExternalBG = true; @@ -327,7 +339,7 @@ void ImageViewer::contextMenuEvent(QContextMenuEvent *event) action->setParent(0); delete menu; - updateGL(); + update(); } //----------------------------------------------------------------------------- @@ -1128,6 +1140,14 @@ void ImageViewer::adaptView(const QRect &geomRect) adaptView(imgBounds, viewRect); } +void ImageViewer::doSwapBuffers() { + glFlush(); +} + +void ImageViewer::changeSwapBehavior(bool enable) { + setUpdateBehavior(enable ? PartialUpdate : NoPartialUpdate); +} + //----------------------------------------------------------------------------- void ImageViewer::keyPressEvent(QKeyEvent *event) diff --git a/toonz/sources/toonz/imageviewer.h b/toonz/sources/toonz/imageviewer.h index f3c9b4f..43810b2 100644 --- a/toonz/sources/toonz/imageviewer.h +++ b/toonz/sources/toonz/imageviewer.h @@ -8,7 +8,7 @@ #include "toonz/imagepainter.h" -#include +#include //----------------------------------------------------------------------------- @@ -22,7 +22,7 @@ class HistogramPopup; // ImageViewer //-------------------- -class ImageViewer : public QGLWidget +class ImageViewer : public QOpenGLWidget { Q_OBJECT enum DragType { eNone, @@ -106,12 +106,8 @@ public: void adaptView(const TRect &imgRect, const TRect &viewRect); void adaptView(const QRect &viewerRect); - void doSwapBuffers() - { - swapBuffers(); - glFlush(); - } - void changeSwapBehavior(bool enable) { setAutoBufferSwap(enable); } + void doSwapBuffers(); + void changeSwapBehavior(bool enable); //iwsw commented out temporarily //Ghibli3DLutUtil* get3DLutUtil(){ return m_ghibli3DLutUtil; } diff --git a/toonz/sources/toonz/linesfadepopup.cpp b/toonz/sources/toonz/linesfadepopup.cpp index 85702ef..53b326c 100644 --- a/toonz/sources/toonz/linesfadepopup.cpp +++ b/toonz/sources/toonz/linesfadepopup.cpp @@ -107,7 +107,7 @@ public: TRasterP raster() const { return m_ras; } TRasterP &raster() { return m_ras; } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/linetestcapturepane.h b/toonz/sources/toonz/linetestcapturepane.h index e1be964..986d3d0 100644 --- a/toonz/sources/toonz/linetestcapturepane.h +++ b/toonz/sources/toonz/linetestcapturepane.h @@ -15,7 +15,6 @@ #include "toonzqt/checkbox.h" #include "toonzqt/colorfield.h" -#include #include #include #include diff --git a/toonz/sources/toonz/linetestviewer.cpp b/toonz/sources/toonz/linetestviewer.cpp index 713849a..a364aba 100644 --- a/toonz/sources/toonz/linetestviewer.cpp +++ b/toonz/sources/toonz/linetestviewer.cpp @@ -129,7 +129,7 @@ LineTestViewer::LineTestViewer(QWidget *parent) #ifdef USE_QPAINTER : QWidget(parent) #else - : QGLWidget(parent) + : QOpenGLWidget(parent) //, m_pboSupported(false) #endif //USE_QPAINTER , diff --git a/toonz/sources/toonz/linetestviewer.h b/toonz/sources/toonz/linetestviewer.h index dbc57f2..c53c468 100644 --- a/toonz/sources/toonz/linetestviewer.h +++ b/toonz/sources/toonz/linetestviewer.h @@ -15,7 +15,7 @@ #ifdef USE_QPAINTER #include #else -#include +#include #endif //----------------------------------------------------------------------------- @@ -25,7 +25,7 @@ #ifdef USE_QPAINTER class LineTestViewer : public QWidget #else -class LineTestViewer : public QGLWidget +class LineTestViewer : public QOpenGLWidget #endif { Q_OBJECT diff --git a/toonz/sources/toonz/meshifypopup.cpp b/toonz/sources/toonz/meshifypopup.cpp index a08e018..f26cf9c 100644 --- a/toonz/sources/toonz/meshifypopup.cpp +++ b/toonz/sources/toonz/meshifypopup.cpp @@ -514,7 +514,7 @@ public: m_img = TImageP(), m_xsh = TXsheetP(), m_row = -1, m_meshImg = TMeshImageP(); } - void paintGL() + void paintGL() override { drawBackground(); diff --git a/toonz/sources/toonz/sceneviewer.cpp b/toonz/sources/toonz/sceneviewer.cpp index cc48478..6bbad84 100644 --- a/toonz/sources/toonz/sceneviewer.cpp +++ b/toonz/sources/toonz/sceneviewer.cpp @@ -548,7 +548,7 @@ void SceneViewer::setVisual(const ImagePainter::VisualSettings &settings) m_visualSettings = settings; m_visualSettings.m_sceneProperties = TApp::instance()->getCurrentScene()->getScene()->getProperties(); if (repaint) - updateGL(); + update(); } //----------------------------------------------------------------------------- diff --git a/toonz/sources/toonz/vectorizerswatch.h b/toonz/sources/toonz/vectorizerswatch.h index 7413e7c..c8e79dd 100644 --- a/toonz/sources/toonz/vectorizerswatch.h +++ b/toonz/sources/toonz/vectorizerswatch.h @@ -79,8 +79,8 @@ public: void setDrawInProgress(bool draw) { m_drawInProgress = draw; } protected: - bool event(QEvent *e); - void paintGL(); + bool event(QEvent *e) override; + void paintGL() override; void drawVectors(); void drawInProgress(); }; diff --git a/toonz/sources/toonzlib/imagebuilders.cpp b/toonz/sources/toonzlib/imagebuilders.cpp index 10c1a93..7431ea7 100644 --- a/toonz/sources/toonzlib/imagebuilders.cpp +++ b/toonz/sources/toonzlib/imagebuilders.cpp @@ -275,14 +275,6 @@ TImageP ImageRasterizer::build(int imFlags, void *extData) QSurfaceFormat format; format.setProfile(QSurfaceFormat::CompatibilityProfile); - std::unique_ptr surface(new QOffscreenSurface()); - surface->setFormat(format); - surface->create(); - - std::unique_ptr context(new QOpenGLContext()); - context->create(); - context->makeCurrent(surface.get()); - TRaster32P ras(d); glPushAttrib(GL_ALL_ATTRIB_BITS); @@ -331,7 +323,6 @@ TImageP ImageRasterizer::build(int imFlags, void *extData) glPopAttrib(); - context->doneCurrent(); tglMakeCurrent(oldContext); TRasterImageP ri = TRasterImageP(ras); diff --git a/toonz/sources/toonzqt/pickrgbutils.cpp b/toonz/sources/toonzqt/pickrgbutils.cpp index d8b95da..27f2fe4 100644 --- a/toonz/sources/toonzqt/pickrgbutils.cpp +++ b/toonz/sources/toonzqt/pickrgbutils.cpp @@ -5,7 +5,7 @@ //Qt includes #include #include -#include +#include #include #include @@ -91,7 +91,7 @@ QRgb pickScreenRGB(const QRect &rect) //------------------------------------------------------------------------------ -QRgb pickRGB(QGLWidget *widget, const QRect &rect) +QRgb pickRGB(QOpenGLWidget *widget, const QRect &rect) { widget->makeCurrent(); diff --git a/toonz/sources/toonzqt/planeviewer.cpp b/toonz/sources/toonzqt/planeviewer.cpp index c8ff3a6..c2a90a7 100644 --- a/toonz/sources/toonzqt/planeviewer.cpp +++ b/toonz/sources/toonzqt/planeviewer.cpp @@ -57,9 +57,12 @@ bool PlaneViewerZoomer::zoom(bool zoomin, bool resetZoom) //========================================================================================= PlaneViewer::PlaneViewer(QWidget *parent) - : QGLWidget(parent), m_firstResize(true), m_xpos(0), m_ypos(0), m_aff() // initialized at the first resize - , - m_chessSize(40.0) + : QOpenGLWidget(parent) + , m_firstResize(true) + , m_xpos(0) + , m_ypos(0) + , m_aff() // initialized at the first resize + , m_chessSize(40.0) { m_zoomRange[0] = 1e-3, m_zoomRange[1] = 1024.0; setBgColor(TPixel32(235, 235, 235), TPixel32(235, 235, 235)); @@ -132,42 +135,38 @@ void PlaneViewer::drawBackground() //========================================================================================= -//! The initMatrix() function is used to match the identity matrix with the widget reference, -//! during widget size initialization. -void PlaneViewer::initMatrix() +void PlaneViewer::initializeGL() { - makeCurrent(); +} + +void PlaneViewer::resizeGL(int width, int height) +{ + glViewport(0, 0, width, height); - glViewport(0, 0, width(), height()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); - gluOrtho2D(0, width(), 0, height()); + gluOrtho2D(0, width, 0, height); + glMatrixMode(GL_MODELVIEW); glLoadIdentity(); - doneCurrent(); -} - -//========================================================================================= - -void PlaneViewer::resizeEvent(QResizeEvent *event) -{ - initMatrix(); - - const QSize &oldSize = event->oldSize(), &size = event->size(); - if (m_firstResize) { m_firstResize = false; - m_aff = TTranslation(0.5 * size.width(), 0.5 * size.height()); - } else { - TPointD oldCenter(oldSize.width() * 0.5, oldSize.height() * 0.5); - TPointD newCenter(size.width() * 0.5, size.height() * 0.5); + m_aff = TTranslation(0.5 * width, 0.5 * height); + m_width = width; + m_height = height; + } + else { + TPointD oldCenter(m_width * 0.5, m_height * 0.5); + TPointD newCenter(width * 0.5, height * 0.5); m_aff = m_aff.place(m_aff.inv() * oldCenter, newCenter); + m_width = width; + m_height = height; } } -//------------------------------------------------------ +//========================================================================================= void PlaneViewer::mouseMoveEvent(QMouseEvent *event) { @@ -201,7 +200,7 @@ void PlaneViewer::keyPressEvent(QKeyEvent *event) if (PlaneViewerZoomer(this).exec(event)) return; - QGLWidget::keyPressEvent(event); + QOpenGLWidget::keyPressEvent(event); } //------------------------------------------------------ diff --git a/toonz/sources/toonzqt/styleeditor.cpp b/toonz/sources/toonzqt/styleeditor.cpp index 78eb933..731fbae 100644 --- a/toonz/sources/toonzqt/styleeditor.cpp +++ b/toonz/sources/toonzqt/styleeditor.cpp @@ -587,8 +587,8 @@ QPixmap makeSquareShading( //***************************************************************************** HexagonalColorWheel::HexagonalColorWheel(QWidget *parent) - : QGLWidget(parent), m_bgColor(128, 128, 128) //defaul value in case this value does not set in the style sheet - //, m_ghibli3DLutUtil(0)//iwsw commented out temporarily + : QOpenGLWidget(parent) + , m_bgColor(128, 128, 128) //defaul value in case this value does not set in the style sheet { setObjectName("HexagonalColorWheel"); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); @@ -623,7 +623,8 @@ HexagonalColorWheel::~HexagonalColorWheel() void HexagonalColorWheel::initializeGL() { - qglClearColor(getBGColor()); + QColor const color = getBGColor(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); //iwsw commented out temporarily /* @@ -692,7 +693,8 @@ void HexagonalColorWheel::resizeGL(int width, int height) void HexagonalColorWheel::paintGL() { //call ClearColor() here in order to update bg color when the stylesheet is switched - qglClearColor(getBGColor()); + QColor const color = getBGColor(); + glClearColor(color.redF(), color.greenF(), color.blueF(), color.alphaF()); glMatrixMode(GL_MODELVIEW);