bump product version to 6.4.0.3
[LibreOffice.git] / vcl / inc / qt5 / Qt5Tools.hxx
blob47f37d85c74d36393bdf8397c104a53fc117624e
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 #pragma once
22 #include <QtCore/QPoint>
23 #include <QtCore/QRect>
24 #include <QtCore/QSize>
25 #include <QtCore/QString>
26 #include <QtGui/QImage>
28 #include <rtl/string.hxx>
29 #include <rtl/ustring.hxx>
30 #include <tools/color.hxx>
31 #include <tools/gen.hxx>
33 #include <com/sun/star/uno/Sequence.hxx>
34 #include <com/sun/star/datatransfer/dnd/DNDConstants.hpp>
36 #include <memory>
38 class Image;
39 class QImage;
41 inline OUString toOUString(const QString& s)
43 // QString stores UTF16, just like OUString
44 return OUString(reinterpret_cast<const sal_Unicode*>(s.data()), s.length());
47 inline QString toQString(const OUString& s)
49 return QString::fromUtf16(reinterpret_cast<ushort const*>(s.getStr()), s.getLength());
52 inline QRect toQRect(const tools::Rectangle& rRect)
54 return QRect(rRect.Left(), rRect.Top(), rRect.GetWidth(), rRect.GetHeight());
57 inline tools::Rectangle toRectangle(const QRect& rRect)
59 return tools::Rectangle(rRect.left(), rRect.top(), rRect.right(), rRect.bottom());
62 inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Height()); }
64 inline Size toSize(const QSize& rSize) { return Size(rSize.width(), rSize.height()); }
66 inline Point toPoint(const QPoint& rPoint) { return Point(rPoint.x(), rPoint.y()); }
68 inline QColor toQColor(const Color& rColor)
70 return QColor(rColor.GetRed(), rColor.GetGreen(), rColor.GetBlue(),
71 255 - rColor.GetTransparency());
74 Qt::DropActions toQtDropActions(sal_Int8 dragOperation);
75 sal_Int8 toVclDropActions(Qt::DropActions dragOperation);
76 sal_Int8 toVclDropAction(Qt::DropAction dragOperation);
77 Qt::DropAction getPreferredDropAction(sal_Int8 dragOperation);
79 inline QList<int> toQList(const css::uno::Sequence<sal_Int32>& aSequence)
81 QList<int> aList;
82 for (sal_Int32 i = 0; i < aSequence.getLength(); i++)
84 aList.append(aSequence[i]);
86 return aList;
89 static constexpr QImage::Format Qt5_DefaultFormat32 = QImage::Format_ARGB32;
91 inline QImage::Format getBitFormat(sal_uInt16 nBitCount)
93 switch (nBitCount)
95 case 1:
96 return QImage::Format_Mono;
97 case 8:
98 return QImage::Format_Indexed8;
99 case 24:
100 return QImage::Format_RGB888;
101 case 32:
102 return Qt5_DefaultFormat32;
103 default:
104 std::abort();
105 break;
107 return QImage::Format_Invalid;
110 inline sal_uInt16 getFormatBits(QImage::Format eFormat)
112 switch (eFormat)
114 case QImage::Format_Mono:
115 return 1;
116 case QImage::Format_Indexed8:
117 return 8;
118 case QImage::Format_RGB888:
119 return 24;
120 case Qt5_DefaultFormat32:
121 case QImage::Format_ARGB32_Premultiplied:
122 return 32;
123 default:
124 std::abort();
125 return 0;
129 typedef struct _cairo_surface cairo_surface_t;
130 struct CairoDeleter
132 void operator()(cairo_surface_t* pSurface) const;
135 typedef std::unique_ptr<cairo_surface_t, CairoDeleter> UniqueCairoSurface;
137 sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers);
138 sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons);
140 QImage toQImage(const Image& rImage);
142 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */