Update git submodules
[LibreOffice.git] / vcl / qt5 / Qt5Tools.cxx
blob6642c66af0cf8c5f59e91c670dfe34bd371fa955
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
22 #include <cairo.h>
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)
35 sal_uInt16 nCode = 0;
36 if (eKeyModifiers & Qt::ShiftModifier)
37 nCode |= KEY_SHIFT;
38 if (eKeyModifiers & Qt::ControlModifier)
39 nCode |= KEY_MOD1;
40 if (eKeyModifiers & Qt::AltModifier)
41 nCode |= KEY_MOD2;
42 if (eKeyModifiers & Qt::MetaModifier)
43 nCode |= KEY_MOD3;
44 return nCode;
47 sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons)
49 sal_uInt16 nCode = 0;
50 if (eButtons & Qt::LeftButton)
51 nCode |= MOUSE_LEFT;
52 if (eButtons & Qt::MiddleButton)
53 nCode |= MOUSE_MIDDLE;
54 if (eButtons & Qt::RightButton)
55 nCode |= MOUSE_RIGHT;
56 return nCode;
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;
68 return eRet;
71 sal_Int8 toVclDropActions(Qt::DropActions dragOperation)
73 sal_Int8 nRet(0);
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;
80 return nRet;
83 sal_Int8 toVclDropAction(Qt::DropAction dragOperation)
85 sal_Int8 nRet(0);
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;
92 return nRet;
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;
104 return eAct;
107 QImage toQImage(const Image& rImage)
109 QImage aImage;
111 if (!!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());
119 return aImage;
122 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */