1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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>
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
)
39 if (eKeyModifiers
& Qt::ShiftModifier
)
41 if (eKeyModifiers
& Qt::ControlModifier
)
43 if (eKeyModifiers
& Qt::AltModifier
)
45 if (eKeyModifiers
& Qt::MetaModifier
)
50 sal_uInt16
GetMouseModCode(Qt::MouseButtons eButtons
)
53 if (eButtons
& Qt::LeftButton
)
55 if (eButtons
& Qt::MiddleButton
)
56 nCode
|= MOUSE_MIDDLE
;
57 if (eButtons
& Qt::RightButton
)
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
;
74 sal_Int8
toVclDropActions(Qt::DropActions dragOperation
)
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
;
86 sal_Int8
toVclDropAction(Qt::DropAction dragOperation
)
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
;
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
;
110 QImage
toQImage(const Image
& 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());
126 QMessageBox::Icon
vclMessageTypeToQtIcon(VclMessageType eType
)
128 QMessageBox::Icon eRet
= QMessageBox::Information
;
131 case VclMessageType::Info
:
132 eRet
= QMessageBox::Information
;
134 case VclMessageType::Warning
:
135 eRet
= QMessageBox::Warning
;
137 case VclMessageType::Question
:
138 eRet
= QMessageBox::Question
;
140 case VclMessageType::Error
:
141 eRet
= QMessageBox::Critical
;
143 case VclMessageType::Other
:
144 eRet
= QMessageBox::Information
;
150 QString
vclMessageTypeToQtTitle(VclMessageType eType
)
155 case VclMessageType::Info
:
156 title
= toQString(GetStandardInfoBoxText());
158 case VclMessageType::Warning
:
159 title
= toQString(GetStandardWarningBoxText());
161 case VclMessageType::Question
:
162 title
= toQString(GetStandardQueryBoxText());
164 case VclMessageType::Error
:
165 title
= toQString(GetStandardErrorBoxText());
167 case VclMessageType::Other
:
168 title
= toQString(Application::GetDisplayName());
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: */