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

Katarina Behrens (via logerrit) logerrit at kemper.freedesktop.org
Fri May 24 07:43:46 UTC 2019


 vcl/inc/qt5/Qt5Frame.hxx |    5 +++--
 vcl/qt5/Qt5Frame.cxx     |   29 ++++++++++++++++++++++++-----
 vcl/qt5/Qt5Widget.cxx    |    5 +++--
 3 files changed, 30 insertions(+), 9 deletions(-)

New commits:
commit c58487251272b390e9c56a880fa4788d0a5b5a7f
Author:     Katarina Behrens <Katarina.Behrens at cib.de>
AuthorDate: Thu May 23 18:11:43 2019 +0200
Commit:     Katarina Behrens <Katarina.Behrens at cib.de>
CommitDate: Fri May 24 09:42:35 2019 +0200

    tdf#125160: honour keyboard modifiers if used during DnD
    
    e.g. copy-DnD with Ctrl held down. This is qt5 remix of tdf#109227
    
    Change-Id: Ib0794c7468cc04d3d50686952305717e10c90c9a
    Reviewed-on: https://gerrit.libreoffice.org/72878
    Tested-by: Jenkins
    Reviewed-by: Katarina Behrens <Katarina.Behrens at cib.de>

diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx
index 6fe1333bd138..9b9c13b4b7fa 100644
--- a/vcl/inc/qt5/Qt5Frame.hxx
+++ b/vcl/inc/qt5/Qt5Frame.hxx
@@ -140,8 +140,9 @@ public:
     virtual void registerDropTarget(Qt5DropTarget* pDropTarget);
     virtual void deregisterDropTarget(Qt5DropTarget const* pDropTarget);
     void draggingStarted(const int x, const int y, Qt::DropActions eActions,
-                         const QMimeData* pQMimeData);
-    void dropping(const int x, const int y, const QMimeData* pQMimeData);
+                         Qt::KeyboardModifiers eKeyMod, const QMimeData* pQMimeData);
+    void dropping(const int x, const int y, Qt::KeyboardModifiers eKeyMod,
+                  const QMimeData* pQMimeData);
 
     virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override;
     virtual void Show(bool bVisible, bool bNoActivate = false) override;
diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx
index 3cfb5d5d9e33..41a4544b4acb 100644
--- a/vcl/qt5/Qt5Frame.cxx
+++ b/vcl/qt5/Qt5Frame.cxx
@@ -1159,16 +1159,30 @@ void Qt5Frame::deregisterDropTarget(Qt5DropTarget const* pDropTarget)
 }
 
 void Qt5Frame::draggingStarted(const int x, const int y, Qt::DropActions eActions,
-                               const QMimeData* pQMimeData)
+                               Qt::KeyboardModifiers eKeyMod, const QMimeData* pQMimeData)
 {
     assert(m_pDropTarget);
 
+    sal_Int8 nUserDropAction = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
+    if ((eKeyMod & Qt::ShiftModifier) && !(eKeyMod & Qt::ControlModifier))
+        nUserDropAction = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
+    else if ((eKeyMod & Qt::ControlModifier) && !(eKeyMod & Qt::ShiftModifier))
+        nUserDropAction = css::datatransfer::dnd::DNDConstants::ACTION_COPY;
+    else if ((eKeyMod & Qt::ShiftModifier) && (eKeyMod & Qt::ControlModifier))
+        nUserDropAction = css::datatransfer::dnd::DNDConstants::ACTION_LINK;
+
     css::datatransfer::dnd::DropTargetDragEnterEvent aEvent;
     aEvent.Source = static_cast<css::datatransfer::dnd::XDropTarget*>(m_pDropTarget);
     aEvent.Context = static_cast<css::datatransfer::dnd::XDropTargetDragContext*>(m_pDropTarget);
     aEvent.LocationX = x;
     aEvent.LocationY = y;
-    aEvent.DropAction = getPreferredDropAction(eActions);
+
+    // system drop action if neither Shift nor Control is held
+    if (!(eKeyMod & (Qt::ShiftModifier | Qt::ControlModifier)))
+        aEvent.DropAction = getPreferredDropAction(eActions);
+    // otherwise user-preferred action
+    else
+        aEvent.DropAction = nUserDropAction;
     aEvent.SourceActions = toVclDropActions(eActions);
 
     css::uno::Reference<css::datatransfer::XTransferable> xTransferable;
@@ -1190,7 +1204,8 @@ void Qt5Frame::draggingStarted(const int x, const int y, Qt::DropActions eAction
         m_pDropTarget->fire_dragOver(aEvent);
 }
 
-void Qt5Frame::dropping(const int x, const int y, const QMimeData* pQMimeData)
+void Qt5Frame::dropping(const int x, const int y, Qt::KeyboardModifiers eKeyMod,
+                        const QMimeData* pQMimeData)
 {
     assert(m_pDropTarget);
 
@@ -1199,8 +1214,12 @@ void Qt5Frame::dropping(const int x, const int y, const QMimeData* pQMimeData)
     aEvent.Context = static_cast<css::datatransfer::dnd::XDropTargetDropContext*>(m_pDropTarget);
     aEvent.LocationX = x;
     aEvent.LocationY = y;
-    aEvent.DropAction = m_pDropTarget->proposedDragAction()
-                        | css::datatransfer::dnd::DNDConstants::ACTION_DEFAULT;
+
+    if (!(eKeyMod & (Qt::ShiftModifier | Qt::ControlModifier)))
+        aEvent.DropAction = m_pDropTarget->proposedDragAction()
+                            | css::datatransfer::dnd::DNDConstants::ACTION_DEFAULT;
+    else
+        aEvent.DropAction = m_pDropTarget->proposedDragAction();
     aEvent.SourceActions = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
 
     css::uno::Reference<css::datatransfer::XTransferable> xTransferable;
diff --git a/vcl/qt5/Qt5Widget.cxx b/vcl/qt5/Qt5Widget.cxx
index a388bf941672..4d620767472f 100644
--- a/vcl/qt5/Qt5Widget.cxx
+++ b/vcl/qt5/Qt5Widget.cxx
@@ -221,7 +221,8 @@ void Qt5Widget::dragMoveEvent(QDragMoveEvent* event)
 {
     QPoint point = event->pos();
 
-    m_rFrame.draggingStarted(point.x(), point.y(), event->possibleActions(), event->mimeData());
+    m_rFrame.draggingStarted(point.x(), point.y(), event->possibleActions(),
+                             event->keyboardModifiers(), event->mimeData());
     QWidget::dragMoveEvent(event);
 }
 
@@ -229,7 +230,7 @@ void Qt5Widget::dropEvent(QDropEvent* event)
 {
     QPoint point = event->pos();
 
-    m_rFrame.dropping(point.x(), point.y(), event->mimeData());
+    m_rFrame.dropping(point.x(), point.y(), event->keyboardModifiers(), event->mimeData());
     QWidget::dropEvent(event);
 }
 


More information about the Libreoffice-commits mailing list