Qt 4.8
|
#include <qcoloroutput_p.h>
Public Types | |
typedef QFlags< ColorCodeComponent > | ColorCode |
enum | ColorCodeComponent { BlackForeground = 1 << ForegroundShift, BlueForeground = 2 << ForegroundShift, GreenForeground = 3 << ForegroundShift, CyanForeground = 4 << ForegroundShift, RedForeground = 5 << ForegroundShift, PurpleForeground = 6 << ForegroundShift, BrownForeground = 7 << ForegroundShift, LightGrayForeground = 8 << ForegroundShift, DarkGrayForeground = 9 << ForegroundShift, LightBlueForeground = 10 << ForegroundShift, LightGreenForeground = 11 << ForegroundShift, LightCyanForeground = 12 << ForegroundShift, LightRedForeground = 13 << ForegroundShift, LightPurpleForeground = 14 << ForegroundShift, YellowForeground = 15 << ForegroundShift, WhiteForeground = 16 << ForegroundShift, BlackBackground = 1 << BackgroundShift, BlueBackground = 2 << BackgroundShift, GreenBackground = 3 << BackgroundShift, CyanBackground = 4 << BackgroundShift, RedBackground = 5 << BackgroundShift, PurpleBackground = 6 << BackgroundShift, BrownBackground = 7 << BackgroundShift, DefaultColor = 1 << SpecialShift } |
typedef QHash< int, ColorCode > | ColorMapping |
Public Functions | |
QString | colorify (const QString &message, int color=-1) const |
Treats message and colorID identically to write(), but instead of writing message to stderr , it is prepared for being written to stderr , but is then returned. More... | |
ColorMapping | colorMapping () const |
Returns the color mappings in use. More... | |
ColorOutput () | |
Constructs a ColorOutput instance, ready for use. More... | |
void | insertMapping (int colorID, const ColorCode colorCode) |
Adds a color mapping from colorID to colorCode, for this ColorOutput instance. More... | |
void | setColorMapping (const ColorMapping &cMapping) |
Sets the color mapping to be cMapping. More... | |
void | write (const QString &message, int color=-1) |
Sends message to stderr , using the color looked up in colorMapping() using colorID. More... | |
void | writeUncolored (const QString &message) |
Writes message to stderr as if for instance QTextStream would have been used, and adds a line ending at the end. More... | |
~ColorOutput () | |
Destructs this ColorOutput instance. More... | |
Private Types | |
enum | { ForegroundShift = 10, BackgroundShift = 20, SpecialShift = 20, ForegroundMask = ((1 << ForegroundShift) - 1) << ForegroundShift, BackgroundMask = ((1 << BackgroundShift) - 1) << BackgroundShift } |
Properties | |
ColorOutputPrivate * | d |
Definition at line 66 of file qcoloroutput_p.h.
Definition at line 107 of file qcoloroutput_p.h.
typedef QHash<int, ColorCode> QPatternist::ColorOutput::ColorMapping |
Definition at line 108 of file qcoloroutput_p.h.
|
private |
Enumerator | |
---|---|
ForegroundShift | |
BackgroundShift | |
SpecialShift | |
ForegroundMask | |
BackgroundMask |
Definition at line 68 of file qcoloroutput_p.h.
Definition at line 78 of file qcoloroutput_p.h.
ColorOutput::ColorOutput | ( | ) |
ColorOutput::~ColorOutput | ( | ) |
Treats message and colorID identically to write(), but instead of writing message to stderr
, it is prepared for being written to stderr
, but is then returned.
This is useful when the colored string is inserted into a translated string(dividing the string into several small strings prevents proper translation).
Definition at line 319 of file qcoloroutput.cpp.
Referenced by QPatternist::ColoringMessageHandler::colorifyDescription(), QPatternist::ColoringMessageHandler::handleMessage(), and write().
ColorOutput::ColorMapping ColorOutput::colorMapping | ( | ) | const |
Returns the color mappings in use.
Definition at line 263 of file qcoloroutput.cpp.
void ColorOutput::insertMapping | ( | int | colorID, |
const ColorCode | colorCode | ||
) |
Adds a color mapping from colorID to colorCode, for this ColorOutput instance.
This is a convenience function for creating a ColorOutput::ColorMapping instance and calling setColorMapping().
Definition at line 375 of file qcoloroutput.cpp.
Referenced by QPatternist::ColoringMessageHandler::ColoringMessageHandler().
void ColorOutput::setColorMapping | ( | const ColorMapping & | cMapping | ) |
Sets the color mapping to be cMapping.
Negative values are disallowed.
Definition at line 253 of file qcoloroutput.cpp.
void ColorOutput::write | ( | const QString & | message, |
int | colorID = -1 |
||
) |
Sends message to stderr
, using the color looked up in colorMapping() using colorID.
If color isn't available in colorMapping(), result and behavior is undefined.
If colorID is 0, which is the default value, the previously used coloring is used. ColorOutput is initialized to not color at all.
If message is empty, effects are undefined.
message will be printed as is. For instance, no line endings will be inserted.
Definition at line 295 of file qcoloroutput.cpp.
void ColorOutput::writeUncolored | ( | const QString & | message | ) |
Writes message to stderr
as if for instance QTextStream would have been used, and adds a line ending at the end.
This function can be practical to use such that one can use ColorOutput for all forms of writing.
Definition at line 306 of file qcoloroutput.cpp.
Referenced by QPatternist::ColoringMessageHandler::handleMessage().
|
private |
Definition at line 122 of file qcoloroutput_p.h.
Referenced by colorify(), insertMapping(), write(), writeUncolored(), and ~ColorOutput().