Delegate input events of HardwareRenderer to RendererStack
This commit is contained in:
@@ -47,18 +47,21 @@ void HardwareRenderer::resizeEvent(QResizeEvent *event) {
|
|||||||
QOpenGLWindow::resizeEvent(event);
|
QOpenGLWindow::resizeEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
void HardwareRenderer::mouseReleaseEvent(QMouseEvent *event)
|
bool HardwareRenderer::event(QEvent *event)
|
||||||
{
|
{
|
||||||
if (this->geometry().contains(event->pos()) && event->button() == Qt::LeftButton && !mouse_capture)
|
switch (event->type())
|
||||||
{
|
{
|
||||||
plat_mouse_capture(1);
|
default:
|
||||||
this->setCursor(Qt::BlankCursor);
|
return QOpenGLWindow::event(event);
|
||||||
return;
|
case QEvent::MouseButtonPress:
|
||||||
}
|
case QEvent::MouseMove:
|
||||||
if (mouse_capture && event->button() == Qt::MiddleButton)
|
case QEvent::MouseButtonRelease:
|
||||||
{
|
case QEvent::KeyPress:
|
||||||
plat_mouse_capture(0);
|
case QEvent::KeyRelease:
|
||||||
this->setCursor(Qt::ArrowCursor);
|
case QEvent::Wheel:
|
||||||
return;
|
case QEvent::Enter:
|
||||||
|
case QEvent::Leave:
|
||||||
|
return QApplication::sendEvent(parentWidget, event);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
@@ -23,15 +23,17 @@ class HardwareRenderer : public QOpenGLWindow, protected QOpenGLFunctions, publi
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
bool wayland = false;
|
bool wayland = false;
|
||||||
|
QWidget* parentWidget{nullptr};
|
||||||
public:
|
public:
|
||||||
void resizeGL(int w, int h) override;
|
void resizeGL(int w, int h) override;
|
||||||
void initializeGL() override;
|
void initializeGL() override;
|
||||||
void paintGL() override;
|
void paintGL() override;
|
||||||
HardwareRenderer(QWindow* parent = nullptr)
|
HardwareRenderer(QWidget* parent = nullptr)
|
||||||
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent), QOpenGLFunctions()
|
: QOpenGLWindow(QOpenGLWindow::NoPartialUpdate, parent->windowHandle()), QOpenGLFunctions()
|
||||||
{
|
{
|
||||||
setMinimumSize(QSize(16, 16));
|
setMinimumSize(QSize(16, 16));
|
||||||
setFlags(Qt::FramelessWindowHint);
|
setFlags(Qt::FramelessWindowHint);
|
||||||
|
parentWidget = parent;
|
||||||
}
|
}
|
||||||
~HardwareRenderer()
|
~HardwareRenderer()
|
||||||
{
|
{
|
||||||
@@ -49,5 +51,5 @@ public slots:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
void resizeEvent(QResizeEvent *event) override;
|
void resizeEvent(QResizeEvent *event) override;
|
||||||
void mouseReleaseEvent(QMouseEvent* event) override;
|
bool event(QEvent* event) override;
|
||||||
};
|
};
|
||||||
|
@@ -184,7 +184,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
|||||||
case Renderer::OpenGL:
|
case Renderer::OpenGL:
|
||||||
{
|
{
|
||||||
this->createWinId();
|
this->createWinId();
|
||||||
auto hw = new HardwareRenderer(this->windowHandle());
|
auto hw = new HardwareRenderer(this);
|
||||||
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
|
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
|
||||||
hw->setRenderType(HardwareRenderer::RenderType::OpenGL);
|
hw->setRenderType(HardwareRenderer::RenderType::OpenGL);
|
||||||
current.reset(this->createWindowContainer(hw, this));
|
current.reset(this->createWindowContainer(hw, this));
|
||||||
@@ -193,7 +193,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
|||||||
case Renderer::OpenGLES:
|
case Renderer::OpenGLES:
|
||||||
{
|
{
|
||||||
this->createWinId();
|
this->createWinId();
|
||||||
auto hw = new HardwareRenderer(this->windowHandle());
|
auto hw = new HardwareRenderer(this);
|
||||||
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
|
connect(this, &RendererStack::blitToRenderer, hw, &HardwareRenderer::onBlit, Qt::QueuedConnection);
|
||||||
hw->setRenderType(HardwareRenderer::RenderType::OpenGLES);
|
hw->setRenderType(HardwareRenderer::RenderType::OpenGLES);
|
||||||
current.reset(this->createWindowContainer(hw, this));
|
current.reset(this->createWindowContainer(hw, this));
|
||||||
@@ -201,6 +201,7 @@ void RendererStack::switchRenderer(Renderer renderer) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
current->setFocusPolicy(Qt::NoFocus);
|
current->setFocusPolicy(Qt::NoFocus);
|
||||||
|
current->setFocusProxy(this);
|
||||||
addWidget(current.get());
|
addWidget(current.get());
|
||||||
|
|
||||||
for (auto& in_use : buffers_in_use)
|
for (auto& in_use : buffers_in_use)
|
||||||
|
Reference in New Issue
Block a user