[Libreoffice-commits] core.git: vcl/inc vcl/qt5

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Sun Aug 12 20:28:28 UTC 2018


 vcl/inc/qt5/Qt5Frame.hxx  |    2 
 vcl/inc/qt5/Qt5Widget.hxx |   39 +++++++++-
 vcl/qt5/Qt5Frame.cxx      |    4 -
 vcl/qt5/Qt5Widget.cxx     |  178 ++++++++--------------------------------------
 4 files changed, 73 insertions(+), 150 deletions(-)

New commits:
commit a7b18b63ec040a15b1008ec6ccb62e9733488a07
Author:     Katarina Behrens <Katarina.Behrens at cib.de>
AuthorDate: Fri Aug 10 18:29:10 2018 +0200
Commit:     Thorsten Behrens <Thorsten.Behrens at CIB.de>
CommitDate: Sun Aug 12 22:28:09 2018 +0200

    Revert templatization of Qt5Widget class
    
    it was not a step in the right direction in 1st place. We distinguish
    between main window frame (QMainWindow) and everything else (QWidget)
    differently now
    
    Change-Id: I331c9760f7616b2f199e63e5e521df74b08acc62
    Reviewed-on: https://gerrit.libreoffice.org/58853
    Tested-by: Jenkins
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 04ade0b38b2d..3bec15f1ecf4 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -39,7 +39,7 @@ class SvpSalGraphics;
 
 class VCLPLUG_QT5_PUBLIC Qt5Frame : public SalFrame
 {
-    friend class VclQtMixinBase;
+    friend class Qt5Widget;
 
     QWidget* m_pQWidget;
     Qt5MainWindow* m_pTopLevel;
diff --git a/vcl/inc/qt5/Qt5Widget.hxx b/vcl/inc/qt5/Qt5Widget.hxx
index 206b8b2d1d6e..19bbb9ff9e55 100644
--- a/vcl/inc/qt5/Qt5Widget.hxx
+++ b/vcl/inc/qt5/Qt5Widget.hxx
@@ -21,8 +21,43 @@
 
 #include <QtWidgets/QWidget>
 
-#include "Qt5Frame.hxx"
+class Qt5Frame;
+class Qt5Object;
+class QFocusEvent;
+class QKeyEvent;
+class QMouseEvent;
+class QMoveEvent;
+class QPaintEvent;
+class QResizeEvent;
+class QShowEvent;
+class QWheelEvent;
 
-QWidget* createQt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f);
+class Qt5Widget : public QWidget
+{
+    Q_OBJECT
+
+    Qt5Frame* m_pFrame;
+
+    bool handleKeyEvent(QKeyEvent*, bool);
+    void handleMouseButtonEvent(QMouseEvent*, bool);
+
+    virtual void focusInEvent(QFocusEvent*) override;
+    virtual void focusOutEvent(QFocusEvent*) override;
+    virtual void keyPressEvent(QKeyEvent*) override;
+    virtual void keyReleaseEvent(QKeyEvent*) override;
+    virtual void mouseMoveEvent(QMouseEvent*) override;
+    virtual void mousePressEvent(QMouseEvent*) override;
+    virtual void mouseReleaseEvent(QMouseEvent*) override;
+    virtual void moveEvent(QMoveEvent*) override;
+    virtual void paintEvent(QPaintEvent*) override;
+    virtual void resizeEvent(QResizeEvent*) override;
+    virtual void showEvent(QShowEvent*) override;
+    virtual void wheelEvent(QWheelEvent*) override;
+    virtual void closeEvent(QCloseEvent*) override;
+
+public:
+    Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f = Qt::WindowFlags());
+    virtual ~Qt5Widget() override;
+};
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index ab8d51fdb336..f609f3cbaa5b 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -101,11 +101,11 @@ Qt5Frame::Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo)
     if (!pParent && (aWinFlags == Qt::Window))
     {
         m_pTopLevel = new Qt5MainWindow(*this, nullptr, aWinFlags);
-        m_pQWidget = createQt5Widget(*this, aWinFlags);
+        m_pQWidget = new Qt5Widget(*this, aWinFlags);
         m_pTopLevel->setCentralWidget(m_pQWidget);
     }
     else
-        m_pQWidget = createQt5Widget(*this, aWinFlags);
+        m_pQWidget = new Qt5Widget(*this, aWinFlags);
 
     if (pParent && !(pParent->m_nStyle & SalFrameStyleFlags::PLUG))
     {
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index f4008ed8fb0a..bb79b7cd6130 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -38,54 +38,28 @@
 #include <cairo.h>
 #include <headless/svpgdi.hxx>
 
-class VclQtMixinBase
+void Qt5Widget::paintEvent(QPaintEvent* pEvent)
 {
-public:
-    VclQtMixinBase(Qt5Frame* pFrame) { m_pFrame = pFrame; }
-
-    void mixinFocusInEvent(QFocusEvent*);
-    void mixinFocusOutEvent(QFocusEvent*);
-    void mixinKeyPressEvent(QKeyEvent*);
-    void mixinKeyReleaseEvent(QKeyEvent*);
-    void mixinMouseMoveEvent(QMouseEvent*);
-    void mixinMousePressEvent(QMouseEvent*);
-    void mixinMouseReleaseEvent(QMouseEvent*);
-    void mixinMoveEvent(QMoveEvent*);
-    void mixinPaintEvent(QPaintEvent*, QWidget* widget);
-    void mixinResizeEvent(QResizeEvent*, QSize aSize);
-    void mixinShowEvent(QShowEvent*);
-    void mixinWheelEvent(QWheelEvent*);
-    void mixinCloseEvent(QCloseEvent*);
-
-private:
-    bool mixinHandleKeyEvent(QKeyEvent*, bool);
-    void mixinHandleMouseButtonEvent(QMouseEvent*, bool);
-
-    Qt5Frame* m_pFrame;
-};
-
-void VclQtMixinBase::mixinPaintEvent(QPaintEvent* pEvent, QWidget* widget)
-{
-    QPainter p(widget);
+    QPainter p(this);
     if (m_pFrame->m_bUseCairo)
     {
         cairo_surface_t* pSurface = m_pFrame->m_pSurface.get();
         cairo_surface_flush(pSurface);
 
-        QImage aImage(cairo_image_surface_get_data(pSurface), widget->size().width(),
-                      widget->size().height(), Qt5_DefaultFormat32);
+        QImage aImage(cairo_image_surface_get_data(pSurface), size().width(), size().height(),
+                      Qt5_DefaultFormat32);
         p.drawImage(pEvent->rect().topLeft(), aImage, pEvent->rect());
     }
     else
         p.drawImage(pEvent->rect().topLeft(), *m_pFrame->m_pQImage, pEvent->rect());
 }
 
-void VclQtMixinBase::mixinResizeEvent(QResizeEvent*, QSize aSize)
+void Qt5Widget::resizeEvent(QResizeEvent* /*event*/)
 {
     if (m_pFrame->m_bUseCairo)
     {
-        int width = aSize.width();
-        int height = aSize.height();
+        int width = size().width();
+        int height = size().height();
 
         if (m_pFrame->m_pSvpGraphics)
         {
@@ -99,18 +73,18 @@ void VclQtMixinBase::mixinResizeEvent(QResizeEvent*, QSize aSize)
     }
     else
     {
-        QImage* pImage = new QImage(aSize, Qt5_DefaultFormat32);
+        QImage* pImage = new QImage(size(), Qt5_DefaultFormat32);
         m_pFrame->m_pQt5Graphics->ChangeQImage(pImage);
         m_pFrame->m_pQImage.reset(pImage);
     }
 
-    m_pFrame->maGeometry.nWidth = aSize.width();
-    m_pFrame->maGeometry.nHeight = aSize.height();
+    m_pFrame->maGeometry.nWidth = size().width();
+    m_pFrame->maGeometry.nHeight = size().height();
 
     m_pFrame->CallCallback(SalEvent::Resize, nullptr);
 }
 
-void VclQtMixinBase::mixinHandleMouseButtonEvent(QMouseEvent* pEvent, bool bReleased)
+void Qt5Widget::handleMouseButtonEvent(QMouseEvent* pEvent, bool bReleased)
 {
     SalMouseEvent aEvent;
     switch (pEvent->button())
@@ -141,17 +115,11 @@ void VclQtMixinBase::mixinHandleMouseButtonEvent(QMouseEvent* pEvent, bool bRele
     m_pFrame->CallCallback(nEventType, &aEvent);
 }
 
-void VclQtMixinBase::mixinMousePressEvent(QMouseEvent* pEvent)
-{
-    mixinHandleMouseButtonEvent(pEvent, false);
-}
+void Qt5Widget::mousePressEvent(QMouseEvent* pEvent) { handleMouseButtonEvent(pEvent, false); }
 
-void VclQtMixinBase::mixinMouseReleaseEvent(QMouseEvent* pEvent)
-{
-    mixinHandleMouseButtonEvent(pEvent, true);
-}
+void Qt5Widget::mouseReleaseEvent(QMouseEvent* pEvent) { handleMouseButtonEvent(pEvent, true); }
 
-void VclQtMixinBase::mixinMouseMoveEvent(QMouseEvent* pEvent)
+void Qt5Widget::mouseMoveEvent(QMouseEvent* pEvent)
 {
     SalMouseEvent aEvent;
     aEvent.mnTime = pEvent->timestamp();
@@ -164,7 +132,7 @@ void VclQtMixinBase::mixinMouseMoveEvent(QMouseEvent* pEvent)
     pEvent->accept();
 }
 
-void VclQtMixinBase::mixinWheelEvent(QWheelEvent* pEvent)
+void Qt5Widget::wheelEvent(QWheelEvent* pEvent)
 {
     SalWheelMouseEvent aEvent;
 
@@ -192,19 +160,16 @@ void VclQtMixinBase::mixinWheelEvent(QWheelEvent* pEvent)
     pEvent->accept();
 }
 
-void VclQtMixinBase::mixinMoveEvent(QMoveEvent*)
-{
-    m_pFrame->CallCallback(SalEvent::Move, nullptr);
-}
+void Qt5Widget::moveEvent(QMoveEvent*) { m_pFrame->CallCallback(SalEvent::Move, nullptr); }
 
-void VclQtMixinBase::mixinShowEvent(QShowEvent*)
+void Qt5Widget::showEvent(QShowEvent*)
 {
     QSize aSize(m_pFrame->GetQWidget()->size());
     SalPaintEvent aPaintEvt(0, 0, aSize.width(), aSize.height(), true);
     m_pFrame->CallCallback(SalEvent::Paint, &aPaintEvt);
 }
 
-void VclQtMixinBase::mixinCloseEvent(QCloseEvent* /*pEvent*/)
+void Qt5Widget::closeEvent(QCloseEvent* /*pEvent*/)
 {
     m_pFrame->CallCallback(SalEvent::Close, nullptr);
 }
@@ -349,7 +314,7 @@ static sal_uInt16 GetKeyCode(int keyval)
     return nCode;
 }
 
-bool VclQtMixinBase::mixinHandleKeyEvent(QKeyEvent* pEvent, bool bDown)
+bool Qt5Widget::handleKeyEvent(QKeyEvent* pEvent, bool bDown)
 {
     SalKeyEvent aEvent;
 
@@ -366,111 +331,34 @@ bool VclQtMixinBase::mixinHandleKeyEvent(QKeyEvent* pEvent, bool bDown)
     return bStopProcessingKey;
 }
 
-void VclQtMixinBase::mixinKeyPressEvent(QKeyEvent* pEvent)
+void Qt5Widget::keyPressEvent(QKeyEvent* pEvent)
 {
-    if (mixinHandleKeyEvent(pEvent, true))
+    if (handleKeyEvent(pEvent, true))
         pEvent->accept();
 }
 
-void VclQtMixinBase::mixinKeyReleaseEvent(QKeyEvent* pEvent)
+void Qt5Widget::keyReleaseEvent(QKeyEvent* pEvent)
 {
-    if (mixinHandleKeyEvent(pEvent, false))
+    if (handleKeyEvent(pEvent, false))
         pEvent->accept();
 }
 
-void VclQtMixinBase::mixinFocusInEvent(QFocusEvent*)
-{
-    m_pFrame->CallCallback(SalEvent::GetFocus, nullptr);
-}
+void Qt5Widget::focusInEvent(QFocusEvent*) { m_pFrame->CallCallback(SalEvent::GetFocus, nullptr); }
 
-void VclQtMixinBase::mixinFocusOutEvent(QFocusEvent*)
+void Qt5Widget::focusOutEvent(QFocusEvent*)
 {
     m_pFrame->CallCallback(SalEvent::LoseFocus, nullptr);
 }
 
-template <class ParentClassT> class Qt5Widget : public ParentClassT
-{
-    //Q_OBJECT
-
-    VclQtMixinBase maMixin;
-
-    virtual void focusInEvent(QFocusEvent* event) override
-    {
-        return maMixin.mixinFocusInEvent(event);
-    }
-
-    virtual void focusOutEvent(QFocusEvent* event) override
-    {
-        return maMixin.mixinFocusOutEvent(event);
-    }
-
-    virtual void keyPressEvent(QKeyEvent* event) override
-    {
-        return maMixin.mixinKeyPressEvent(event);
-    }
-
-    virtual void keyReleaseEvent(QKeyEvent* event) override
-    {
-        return maMixin.mixinKeyReleaseEvent(event);
-    }
-
-    virtual void mouseMoveEvent(QMouseEvent* event) override
-    {
-        return maMixin.mixinMouseMoveEvent(event);
-    }
-
-    virtual void mousePressEvent(QMouseEvent* event) override
-    {
-        return maMixin.mixinMousePressEvent(event);
-    }
-
-    virtual void mouseReleaseEvent(QMouseEvent* event) override
-    {
-        return maMixin.mixinMouseReleaseEvent(event);
-    }
-
-    virtual void moveEvent(QMoveEvent* event) override { return maMixin.mixinMoveEvent(event); }
-
-    virtual void paintEvent(QPaintEvent* event) override
-    {
-        return maMixin.mixinPaintEvent(event, this);
-    }
-
-    virtual void resizeEvent(QResizeEvent* event) override
-    {
-        return maMixin.mixinResizeEvent(event, ParentClassT::size());
-    }
-
-    virtual void showEvent(QShowEvent* event) override { return maMixin.mixinShowEvent(event); }
-
-    virtual void wheelEvent(QWheelEvent* event) override { return maMixin.mixinWheelEvent(event); }
-
-    virtual void closeEvent(QCloseEvent* event) override { return maMixin.mixinCloseEvent(event); }
-
-private:
-    Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)
-        : ParentClassT(Q_NULLPTR, f)
-        , maMixin(&rFrame)
-    {
-        Init();
-    }
-
-    void Init()
-    {
-        ParentClassT::create();
-        ParentClassT::setMouseTracking(true);
-        ParentClassT::setFocusPolicy(Qt::StrongFocus);
-    }
-
-public:
-    virtual ~Qt5Widget() override{};
-
-    friend QWidget* createQt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f);
-};
-
-QWidget* createQt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)
+Qt5Widget::Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f)
+    : QWidget(Q_NULLPTR, f)
+    , m_pFrame(&rFrame)
 {
-    return new Qt5Widget<QWidget>(rFrame, f);
+    create();
+    setMouseTracking(true);
+    setFocusPolicy(Qt::StrongFocus);
 }
 
+Qt5Widget::~Qt5Widget(){};
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list