Mark some Calc slots as inactive in readonly mode
[LibreOffice.git] / vcl / qt5 / QtTools.cxx
blob375cc892464f7a7e361b89a9d7f29c75741d4175
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 <QtTools.hxx>
22 #include <cairo.h>
24 #include <tools/stream.hxx>
25 #include <vcl/event.hxx>
26 #include <vcl/image.hxx>
27 #include <vcl/filter/PngImageWriter.hxx>
28 #include <vcl/qt/QtUtils.hxx>
29 #include <vcl/stdtext.hxx>
30 #include <vcl/svapp.hxx>
32 #include <QtGui/QImage>
34 void CairoDeleter::operator()(cairo_surface_t* pSurface) const { cairo_surface_destroy(pSurface); }
36 sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers)
38 sal_uInt16 nCode = 0;
39 if (eKeyModifiers & Qt::ShiftModifier)
40 nCode |= KEY_SHIFT;
41 if (eKeyModifiers & Qt::ControlModifier)
42 nCode |= KEY_MOD1;
43 if (eKeyModifiers & Qt::AltModifier)
44 nCode |= KEY_MOD2;
45 if (eKeyModifiers & Qt::MetaModifier)
46 nCode |= KEY_MOD3;
47 return nCode;
50 sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons)
52 sal_uInt16 nCode = 0;
53 if (eButtons & Qt::LeftButton)
54 nCode |= MOUSE_LEFT;
55 if (eButtons & Qt::MiddleButton)
56 nCode |= MOUSE_MIDDLE;
57 if (eButtons & Qt::RightButton)
58 nCode |= MOUSE_RIGHT;
59 return nCode;
62 Qt::DropActions toQtDropActions(sal_Int8 dragOperation)
64 Qt::DropActions eRet = Qt::IgnoreAction;
65 if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
66 eRet |= Qt::CopyAction;
67 if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
68 eRet |= Qt::MoveAction;
69 if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
70 eRet |= Qt::LinkAction;
71 return eRet;
74 sal_Int8 toVclDropActions(Qt::DropActions dragOperation)
76 sal_Int8 nRet(0);
77 if (dragOperation & Qt::CopyAction)
78 nRet |= css::datatransfer::dnd::DNDConstants::ACTION_COPY;
79 if (dragOperation & Qt::MoveAction)
80 nRet |= css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
81 if (dragOperation & Qt::LinkAction)
82 nRet |= css::datatransfer::dnd::DNDConstants::ACTION_LINK;
83 return nRet;
86 sal_Int8 toVclDropAction(Qt::DropAction dragOperation)
88 sal_Int8 nRet(0);
89 if (dragOperation == Qt::CopyAction)
90 nRet = css::datatransfer::dnd::DNDConstants::ACTION_COPY;
91 else if (dragOperation == Qt::MoveAction)
92 nRet = css::datatransfer::dnd::DNDConstants::ACTION_MOVE;
93 else if (dragOperation == Qt::LinkAction)
94 nRet = css::datatransfer::dnd::DNDConstants::ACTION_LINK;
95 return nRet;
98 Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation)
100 Qt::DropAction eAct = Qt::IgnoreAction;
101 if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_MOVE)
102 eAct = Qt::MoveAction;
103 else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_COPY)
104 eAct = Qt::CopyAction;
105 else if (dragOperation & css::datatransfer::dnd::DNDConstants::ACTION_LINK)
106 eAct = Qt::LinkAction;
107 return eAct;
110 QImage toQImage(const Image& rImage)
112 QImage aImage;
114 if (!!rImage)
116 SvMemoryStream aMemStm;
117 auto rBitmapEx = rImage.GetBitmapEx();
118 vcl::PngImageWriter aWriter(aMemStm);
119 aWriter.write(rBitmapEx);
120 aImage.loadFromData(static_cast<const uchar*>(aMemStm.GetData()), aMemStm.TellEnd());
123 return aImage;
126 QMessageBox::Icon vclMessageTypeToQtIcon(VclMessageType eType)
128 QMessageBox::Icon eRet = QMessageBox::Information;
129 switch (eType)
131 case VclMessageType::Info:
132 eRet = QMessageBox::Information;
133 break;
134 case VclMessageType::Warning:
135 eRet = QMessageBox::Warning;
136 break;
137 case VclMessageType::Question:
138 eRet = QMessageBox::Question;
139 break;
140 case VclMessageType::Error:
141 eRet = QMessageBox::Critical;
142 break;
143 case VclMessageType::Other:
144 eRet = QMessageBox::Information;
145 break;
147 return eRet;
150 QString vclMessageTypeToQtTitle(VclMessageType eType)
152 QString title;
153 switch (eType)
155 case VclMessageType::Info:
156 title = toQString(GetStandardInfoBoxText());
157 break;
158 case VclMessageType::Warning:
159 title = toQString(GetStandardWarningBoxText());
160 break;
161 case VclMessageType::Question:
162 title = toQString(GetStandardQueryBoxText());
163 break;
164 case VclMessageType::Error:
165 title = toQString(GetStandardErrorBoxText());
166 break;
167 case VclMessageType::Other:
168 title = toQString(Application::GetDisplayName());
169 break;
171 return title;
174 QString vclToQtStringWithAccelerator(const OUString& rText)
176 // preserve literal '&'s and use '&' instead of '~' for the accelerator
177 return toQString(rText.replaceAll("&", "&&").replace('~', '&'));
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */