Kaydet (Commit) c3751ed3 authored tarafından Katarina Behrens's avatar Katarina Behrens

tdf#120783: take suggested/preferred DnD ops into account

use those for drag operation start in Qt5Widget and eventually
to construct DropTargetDragEnterEvent

Change-Id: I3a92cbe722dadc64f8a210f7fd4016c8eb17216b
Reviewed-on: https://gerrit.libreoffice.org/68675
Tested-by: Jenkins
Reviewed-by: 's avatarKatarina Behrens <Katarina.Behrens@cib.de>
üst 98b8fa29
......@@ -139,7 +139,8 @@ public:
virtual void deregisterDragSource(Qt5DragSource const* pDragSource);
virtual void registerDropTarget(Qt5DropTarget* pDropTarget);
virtual void deregisterDropTarget(Qt5DropTarget const* pDropTarget);
void draggingStarted(const int x, const int y, const QMimeData* pQMimeData);
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);
virtual void SetExtendedFrameStyle(SalExtStyle nExtStyle) override;
......
......@@ -30,6 +30,7 @@
#include <tools/gen.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
#include <memory>
......@@ -64,6 +65,10 @@ inline QColor toQColor(const Color& rColor)
255 - rColor.GetTransparency());
}
Qt::DropActions toQtDropActions(sal_Int8 dragOperation);
sal_Int8 toVclDropActions(Qt::DropActions dragOperation);
Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation);
inline QList<int> toQList(const css::uno::Sequence<sal_Int32>& aSequence)
{
QList<int> aList;
......
......@@ -72,7 +72,7 @@ public slots:
public:
Qt5Widget(Qt5Frame& rFrame, Qt::WindowFlags f = Qt::WindowFlags());
Qt5Frame* m_pFrame;
void startDrag();
void startDrag(sal_Int8 nSourceActions);
};
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -128,7 +128,7 @@ void Qt5DragSource::initialize(const css::uno::Sequence<css::uno::Any>& rArgumen
}
void Qt5DragSource::startDrag(
const datatransfer::dnd::DragGestureEvent& /*rEvent*/, sal_Int8 /*sourceActions*/,
const datatransfer::dnd::DragGestureEvent& /*rEvent*/, sal_Int8 sourceActions,
sal_Int32 /*cursor*/, sal_Int32 /*image*/,
const css::uno::Reference<css::datatransfer::XTransferable>& rTrans,
const css::uno::Reference<css::datatransfer::dnd::XDragSourceListener>& rListener)
......@@ -140,7 +140,7 @@ void Qt5DragSource::startDrag(
{
Qt5Widget* qw = static_cast<Qt5Widget*>(m_pFrame->GetQWidget());
m_ActiveDragSource = this;
qw->startDrag();
qw->startDrag(sourceActions);
}
else
dragFailed();
......
......@@ -1107,7 +1107,8 @@ void Qt5Frame::deregisterDropTarget(Qt5DropTarget const* pDropTarget)
m_pDropTarget = nullptr;
}
void Qt5Frame::draggingStarted(const int x, const int y, const QMimeData* pQMimeData)
void Qt5Frame::draggingStarted(const int x, const int y, Qt::DropActions eActions,
const QMimeData* pQMimeData)
{
assert(m_pDropTarget);
......@@ -1116,8 +1117,8 @@ void Qt5Frame::draggingStarted(const int x, const int y, const QMimeData* pQMime
aEvent.Context = static_cast<css::datatransfer::dnd::XDropTargetDragContext*>(m_pDropTarget);
aEvent.LocationX = x;
aEvent.LocationY = y;
aEvent.DropAction = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
aEvent.SourceActions = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
aEvent.DropAction = getPreferredDropAction(eActions);
aEvent.SourceActions = toVclDropActions(eActions);
css::uno::Reference<css::datatransfer::XTransferable> xTransferable;
if (!pQMimeData->hasFormat(sInternalMimeType))
......
......@@ -51,4 +51,42 @@ sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons)
return nCode;
}
Qt::DropActions toQtDropActions(sal_Int8 dragOperation)
{
Qt::DropActions eRet = Qt::IgnoreAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
eRet |= Qt::CopyAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
eRet |= Qt::MoveAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
eRet |= Qt::LinkAction;
return eRet;
}
sal_Int8 toVclDropActions(Qt::DropActions dragOperation)
{
sal_Int8 nRet(0);
if (dragOperation & Qt::CopyAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_COPY;
if (dragOperation & Qt::MoveAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
if (dragOperation & Qt::LinkAction)
nRet |= css::datatransfer::dnd::DNDConstants::ACTION_LINK;
return nRet;
}
Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation)
{
Qt::DropAction eAct = Qt::IgnoreAction;
if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
eAct = Qt::MoveAction;
else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
eAct = Qt::CopyAction;
else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
eAct = Qt::LinkAction;
return eAct;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -189,7 +189,7 @@ void Qt5Widget::wheelEvent(QWheelEvent* pEvent)
pEvent->accept();
}
void Qt5Widget::startDrag()
void Qt5Widget::startDrag(sal_Int8 nSourceActions)
{
// internal drag source
QMimeData* mimeData = new QMimeData;
......@@ -197,7 +197,7 @@ void Qt5Widget::startDrag()
QDrag* drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::MoveAction);
drag->exec(toQtDropActions(nSourceActions), Qt::MoveAction);
}
void Qt5Widget::dragEnterEvent(QDragEnterEvent* event)
......@@ -212,7 +212,7 @@ void Qt5Widget::dragMoveEvent(QDragMoveEvent* event)
{
QPoint point = event->pos();
m_pFrame->draggingStarted(point.x(), point.y(), event->mimeData());
m_pFrame->draggingStarted(point.x(), point.y(), event->possibleActions(), event->mimeData());
QWidget::dragMoveEvent(event);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment