Krita Source Code Documentation
Loading...
Searching...
No Matches
KisPortingUtils.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2024 Halla Rempt <halla@valdyas.org>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6#ifndef KISPORTINGUTILS_H
7#define KISPORTINGUTILS_H
8
9#include <QIODevice>
10#include <QTextStream>
11#include <QWidget>
12#include <QScreen>
13#include <QGuiApplication>
14
16{
17
18inline void setUtf8OnStream(QTextStream &stream)
19{
20#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
21 stream.setCodec("UTF-8");
22#else
23 stream.setEncoding(QStringConverter::Utf8);
24#endif
25}
26
27inline int getScreenNumberForWidget(const QWidget *w)
28{
29 QList<QScreen *> screens = QGuiApplication::screens();
30 if (w) {
31 if (screens.contains(w->screen())) {
32 return screens.indexOf(w->screen());
33 }
34 }
35
36 return screens.indexOf(QGuiApplication::primaryScreen());
37}
38
39inline void stringRemoveLast(QString &str)
40{
41#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
42 str.remove(str.size() - 1, 1);
43#else
44 str.removeLast();
45#endif
46}
47
48inline void stringRemoveFirst(QString &str)
49{
50#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
51 str.remove(0, 1);
52#else
53 str.removeFirst();
54#endif
55}
56
57}
58
59#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
60#define Q_UNREACHABLE_RETURN(...) Q_UNREACHABLE(); return __VA_ARGS__
61#endif
62
63
64#endif // KISPORTINGUTILS_H
void stringRemoveFirst(QString &str)
void stringRemoveLast(QString &str)
int getScreenNumberForWidget(const QWidget *w)
void setUtf8OnStream(QTextStream &stream)