KGuiAddons
kcountryflagemojiiconengine.cpp
21 // The way this was set up by unicode is actually pretty smart. Country flags are based on their two character
22 // country codes within a given range of code points. And even better, the offset inside the range is the same
23 // as the offset inside ASCII. Meaning the offset of 'A' from 0 is the same as the offset of π¦ in the
24 // flag codepoint range. The way a flag is then denoted is e.g. <SURROGATEPAIR>π¦<SURROGATEPAIR>πΉ resulting in
30 static constexpr auto offsetCodePointA = 'A'_L1.unicode(); // offset from 0, the flag code points have the same offsets
50 // Region flags work much the same as country flags but with a slightly different format in a slightly different
51 // code point region. Specifically they use ISO 3166-2 as input (e.g. GB-SCT for Scotland). It all happens in
52 // the Unicode Block βTagsβ (starting at U+E0000) wherein it functions the same as the country codes do in their
53 // block. The offsets inside the block are the same as the ascii offsets and the emoji is constructed by combining
54 // the off set code points of the incoming region tag. They are prefixed with U+1F3F4 π΄ WAVING BLACK FLAG
62 static constexpr auto flagCodePointStart = 0xDC41; // U+E0041 (Tag Latin Capital Letter A) - NB: we are in UTF-16
63 static constexpr auto offsetCodePointA = 'A'_L1.unicode(); // offset from 0, the flag code points have the same offsets
72 static const auto cancelTag = QString().append(QChar(surrogatePairCodePoint)).append(QChar(0xDC7F));
83 , m_emoji(regionOrCountry.contains("-"_L1) ? makeRegionEmoji(regionOrCountry) : makeCountryEmoji(regionOrCountry))
108void KCountryFlagEmojiIconEngine::paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state)
122 const auto ratio = std::max({1.0, tightRect.width() / rect.width(), tightRect.height() / rect.height()});
128 painter->setPen(qGuiApp->palette().color(QPalette::WindowText)); // in case we render the letters in absence of a flag
131 // Confusingly the pixelSize for drawing must actually be without DPR but the rect calculation above
142QPixmap KCountryFlagEmojiIconEngine::pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state)
147QPixmap KCountryFlagEmojiIconEngine::scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale)
bool isNull() override
Check whether the internal emoji unicode sequence is null This does not necessarily mean that the pix...
Definition kcountryflagemojiiconengine.cpp:159
static void setGlobalDefaultFont(const QFont &font)
Set the Global Default Font object This is primarily useful for platform themes that wish to force a ...
Definition kcountryflagemojiiconengine.cpp:164
KCountryFlagEmojiIconEngine(const QString ®ionOrCountry)
Construct a new KCountryFlagEmojiIconEngine object Please note that regional flag support can be spot...
Definition kcountryflagemojiiconengine.cpp:91
KI18NLOCALEDATA_EXPORT KCountry country(const char *ianaId)
Mode
State
void append(QList< T > &&value)
void reserve(qsizetype size)
qreal devicePixelRatioF() const const
QPaintDevice * device() const const
void drawText(const QPoint &position, const QString &text)
void setFont(const QFont &font)
void setPen(Qt::PenStyle style)
WindowText
void fill(const QColor &color)
void setDevicePixelRatio(qreal scaleFactor)
int height() const const
int width() const const
qreal height() const const
void moveTopLeft(const QPointF &position)
QPointF topLeft() const const
qreal width() const const
QString & append(QChar ch)
QString & remove(QChar ch, Qt::CaseSensitivity cs)
const QChar * unicode() const const
QString join(QChar separator) const const
AlignCenter
transparent
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.