1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <Qt5Tools.hxx>
24 #include <tools/stream.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/pngwrite.hxx>
29 #include <QtGui/QImage>
31 void CairoDeleter::operator()(cairo_surface_t
* pSurface
) const { cairo_surface_destroy(pSurface
); }
33 sal_uInt16
GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers
)
36 if (eKeyModifiers
& Qt::ShiftModifier
)
38 if (eKeyModifiers
& Qt::ControlModifier
)
40 if (eKeyModifiers
& Qt::AltModifier
)
42 if (eKeyModifiers
& Qt::MetaModifier
)
47 sal_uInt16
GetMouseModCode(Qt::MouseButtons eButtons
)
50 if (eButtons
& Qt::LeftButton
)
52 if (eButtons
& Qt::MidButton
)
53 nCode
|= MOUSE_MIDDLE
;
54 if (eButtons
& Qt::RightButton
)
59 Qt::DropActions
toQtDropActions(sal_Int8 dragOperation
)
61 Qt::DropActions eRet
= Qt::IgnoreAction
;
62 if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_COPY
)
63 eRet
|= Qt::CopyAction
;
64 if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_MOVE
)
65 eRet
|= Qt::MoveAction
;
66 if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_LINK
)
67 eRet
|= Qt::LinkAction
;
71 sal_Int8
toVclDropActions(Qt::DropActions dragOperation
)
74 if (dragOperation
& Qt::CopyAction
)
75 nRet
|= css::datatransfer::dnd::DNDConstants::ACTION_COPY
;
76 if (dragOperation
& Qt::MoveAction
)
77 nRet
|= css::datatransfer::dnd::DNDConstants::ACTION_MOVE
;
78 if (dragOperation
& Qt::LinkAction
)
79 nRet
|= css::datatransfer::dnd::DNDConstants::ACTION_LINK
;
83 sal_Int8
toVclDropAction(Qt::DropAction dragOperation
)
86 if (dragOperation
== Qt::CopyAction
)
87 nRet
= css::datatransfer::dnd::DNDConstants::ACTION_COPY
;
88 else if (dragOperation
== Qt::MoveAction
)
89 nRet
= css::datatransfer::dnd::DNDConstants::ACTION_MOVE
;
90 else if (dragOperation
== Qt::LinkAction
)
91 nRet
= css::datatransfer::dnd::DNDConstants::ACTION_LINK
;
95 Qt::DropAction
getPreferredDropAction(sal_Int8 dragOperation
)
97 Qt::DropAction eAct
= Qt::IgnoreAction
;
98 if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_MOVE
)
99 eAct
= Qt::MoveAction
;
100 else if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_COPY
)
101 eAct
= Qt::CopyAction
;
102 else if (dragOperation
& css::datatransfer::dnd::DNDConstants::ACTION_LINK
)
103 eAct
= Qt::LinkAction
;
107 QImage
toQImage(const Image
& rImage
)
113 SvMemoryStream aMemStm
;
114 vcl::PNGWriter
aWriter(rImage
.GetBitmapEx());
115 aWriter
.Write(aMemStm
);
116 aImage
.loadFromData(static_cast<const uchar
*>(aMemStm
.GetData()), aMemStm
.TellEnd());
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */