Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / vcl / qt5 / Qt5Tools.hxx
blobbfd604993fd0e96632d39fe7426d44ec84ccf36e
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/QString>
23 #include <QtCore/QRect>
24 #include <QtCore/QSize>
25 #include <QtGui/QImage>
27 #include <rtl/string.hxx>
28 #include <rtl/ustring.hxx>
29 #include <tools/gen.hxx>
31 #include <memory>
33 inline OUString toOUString(const QString& s)
35 // QString stores UTF16, just like OUString
36 return OUString(reinterpret_cast<const sal_Unicode*>(s.data()), s.length());
39 inline QString toQString(const OUString& s)
41 return QString::fromUtf16(reinterpret_cast<ushort const*>(s.getStr()), s.getLength());
44 inline QRect toQRect(const tools::Rectangle& rRect)
46 return QRect(rRect.Left(), rRect.Top(), rRect.GetWidth(), rRect.GetHeight());
49 inline QSize toQSize(const Size& rSize) { return QSize(rSize.Width(), rSize.Height()); }
51 inline Size toSize(const QSize& rSize) { return Size(rSize.width(), rSize.height()); }
53 static constexpr QImage::Format Qt5_DefaultFormat32 = QImage::Format_ARGB32;
55 inline QImage::Format getBitFormat(sal_uInt16 nBitCount)
57 switch (nBitCount)
59 case 1:
60 return QImage::Format_Mono;
61 case 8:
62 return QImage::Format_Indexed8;
63 case 16:
64 return QImage::Format_RGB16;
65 case 24:
66 return QImage::Format_RGB888;
67 case 32:
68 return Qt5_DefaultFormat32;
69 default:
70 std::abort();
71 break;
73 return QImage::Format_Invalid;
76 inline sal_uInt16 getFormatBits(QImage::Format eFormat)
78 switch (eFormat)
80 case QImage::Format_Mono:
81 return 1;
82 case QImage::Format_Indexed8:
83 return 8;
84 case QImage::Format_RGB16:
85 return 16;
86 case QImage::Format_RGB888:
87 return 24;
88 case Qt5_DefaultFormat32:
89 return 32;
90 default:
91 std::abort();
92 return 0;
96 typedef struct _cairo_surface cairo_surface_t;
97 struct CairoDeleter
99 void operator()(cairo_surface_t* pSurface) const;
102 typedef std::unique_ptr<cairo_surface_t, CairoDeleter> UniqueCairoSurface;
104 sal_uInt16 GetKeyModCode(Qt::KeyboardModifiers eKeyModifiers);
105 sal_uInt16 GetMouseModCode(Qt::MouseButtons eButtons);
107 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */