Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcoloroutput_p.h
Go to the documentation of this file.
1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QCOLOROUTPUT_H
6#define QCOLOROUTPUT_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <qtqmlcompilerexports.h>
19
20#include <QtCore/private/qglobal_p.h>
21#include <QtCore/qscopedpointer.h>
22#include <QtCore/qstring.h>
23
24QT_BEGIN_NAMESPACE
25
26class QColorOutputPrivate;
27
28class Q_QMLCOMPILER_EXPORT QColorOutput
29{
30 enum
31 {
32 ForegroundShift = 10,
33 BackgroundShift = 20,
34 SpecialShift = 20,
35 ForegroundMask = 0x1f << ForegroundShift,
36 BackgroundMask = 0x7 << BackgroundShift
37 };
38
39public:
40 enum ColorCodeComponent
41 {
42 BlackForeground = 1 << ForegroundShift,
43 BlueForeground = 2 << ForegroundShift,
44 GreenForeground = 3 << ForegroundShift,
45 CyanForeground = 4 << ForegroundShift,
46 RedForeground = 5 << ForegroundShift,
47 PurpleForeground = 6 << ForegroundShift,
48 BrownForeground = 7 << ForegroundShift,
49 LightGrayForeground = 8 << ForegroundShift,
50 DarkGrayForeground = 9 << ForegroundShift,
51 LightBlueForeground = 10 << ForegroundShift,
52 LightGreenForeground = 11 << ForegroundShift,
53 LightCyanForeground = 12 << ForegroundShift,
54 LightRedForeground = 13 << ForegroundShift,
55 LightPurpleForeground = 14 << ForegroundShift,
56 YellowForeground = 15 << ForegroundShift,
57 WhiteForeground = 16 << ForegroundShift,
58
59 BlackBackground = 1 << BackgroundShift,
60 BlueBackground = 2 << BackgroundShift,
61 GreenBackground = 3 << BackgroundShift,
62 CyanBackground = 4 << BackgroundShift,
63 RedBackground = 5 << BackgroundShift,
64 PurpleBackground = 6 << BackgroundShift,
65 BrownBackground = 7 << BackgroundShift,
66 DefaultColor = 1 << SpecialShift
67 };
68
69 using ColorCode = QFlags<ColorCodeComponent>;
70 using ColorMapping = QHash<int, ColorCode>;
71
72 QColorOutput();
73 ~QColorOutput();
74
75 bool isSilent() const;
76 void setSilent(bool silent);
77
78 void insertMapping(int colorID, ColorCode colorCode);
79
80 void writeUncolored(const QString &message);
81 void write(const QStringView message, int color = -1);
82 // handle QStringBuilder case
83 Q_WEAK_OVERLOAD void write(const QString &message, int color = -1) { write(QStringView(message), color); }
84 void writePrefixedMessage(const QString &message, QtMsgType type,
85 const QString &prefix = QString());
86 QString colorify(QStringView message, int color = -1) const;
87
88 void flushBuffer();
89 void discardBuffer();
90
91private:
92 QScopedPointer<QColorOutputPrivate> d;
93 Q_DISABLE_COPY_MOVE(QColorOutput)
94};
95
96Q_DECLARE_OPERATORS_FOR_FLAGS(QColorOutput::ColorCode)
97
98QT_END_NAMESPACE
99
100#endif // QCOLOROUTPUT_H
\nonreentrant