1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
/************************************************************************
*
* Copyright (C) 2009-2025 IRCAD France
* Copyright (C) 2012-2020 IHU Strasbourg
*
* This file is part of Sight.
*
* Sight is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Sight. If not, see <https://www.gnu.org/licenses/>.
*
***********************************************************************/
#include "main_frame.hpp"
#include <core/base.hpp>
#include <ui/__/dialog/message.hpp>
#include <QCloseEvent>
#include <QGuiApplication>
#include <QLayout>
#include <QOpenGLWidget>
#include <QWindow>
namespace sight::ui::qt
{
//------------------------------------------------------------------------------
void main_frame::set_close_callback(CloseCallback _fct)
{
m_fct_close_callback = _fct;
}
//------------------------------------------------------------------------------
void main_frame::closeEvent(QCloseEvent* _event)
{
m_fct_close_callback();
_event->ignore();
}
//------------------------------------------------------------------------------
void main_frame::showEvent(QShowEvent* _event)
{
// This is a ugly hack to force the re-creation of the window type from RasterSurface to OpenGLSurface, *before*
// being shown for the first time.
// Otherwise, QWidget::setParent(..), which is called when adding a child to the layout, will do that while this
// window is visible making a flickering effect.
/// @see https://doc.qt.io/qt-6/qopenglwidget.html#limitations-and-other-considerations
/// @note With Qt 6.8.2, we can call window->setSurfaceType(QSurface::OpenGLSurface)
/// @note With Qt 6.4.x (Ubuntu 22.04), we must use an uglier hack, add/remove a dummy QOpenGLWidget to the layout
if(static bool once = false; !once)
{
if(auto* const window = this->windowHandle();
window != nullptr
&& window->surfaceType() != QSurface::OpenGLSurface
&& qApp->platformName() != "offscreen")
{
#if QT_VERSION >= QT_VERSION_CHECK(6, 8, 0)
window->setSurfaceType(QSurface::OpenGLSurface);
#else
QOpenGLWidget dummy;
this->setCentralWidget(&dummy);
this->takeCentralWidget();
#endif
}
once = true;
}
QMainWindow::showEvent(_event);
}
//------------------------------------------------------------------------------
} // namespace sight::ui::qt
|