1 | // SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
2 | // SPDX-FileCopyrightText: 2022-2023 Harald Sitter <sitter@kde.org> |
3 | |
4 | #ifndef KCOUNTRYFLAGEMOJIICONENGINE_H |
5 | #define KCOUNTRYFLAGEMOJIICONENGINE_H |
6 | |
7 | #include <QIconEngine> |
8 | |
9 | #include <kguiaddons_export.h> |
10 | |
11 | class KCountryFlagEmojiIconEnginePrivate; |
12 | |
13 | /*! |
14 | * \class KCountryFlagEmojiIconEngine |
15 | * \inmodule KGuiAddons |
16 | * |
17 | * \brief Provides emoji flags as icons |
18 | * This is a special icon engine that internally paints flags using emoji fonts. |
19 | * It provides access to country and region flags from the system emoji font. |
20 | * \code |
21 | * auto l = new QLabel; |
22 | * l->setMinimumSize(512, 512); |
23 | * l->setPixmap(QIcon(new KCountryFlagEmojiIconEngine("AT")).pixmap(512, 512)); |
24 | * \endcode |
25 | * \since 6.0 |
26 | */ |
27 | class KGUIADDONS_EXPORT KCountryFlagEmojiIconEngine : public QIconEngine |
28 | { |
29 | public: |
30 | /*! |
31 | * \brief Construct a new KCountryFlagEmojiIconEngine object |
32 | * Please note that regional flag support can be spotty in emoji fonts. |
33 | * |
34 | * \a regionOrCountry either a ISO 3166-1 alpha-2 country code or a ISO 3166-2 region code (e.g. AT for Austria or GB-SCT for Scotland) |
35 | */ |
36 | explicit KCountryFlagEmojiIconEngine(const QString ®ionOrCountry); |
37 | ~KCountryFlagEmojiIconEngine() override; |
38 | Q_DISABLE_COPY_MOVE(KCountryFlagEmojiIconEngine) |
39 | |
40 | QIconEngine *clone() const override; |
41 | QString key() const override; |
42 | void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; |
43 | QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; |
44 | QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override; |
45 | |
46 | /*! |
47 | * \reimp |
48 | * |
49 | * \brief Check whether the internal emoji unicode sequence is null |
50 | * This does not necessarily mean that the pixmap output will be a valid flag - that entirely depends on the system's precise font configuration. |
51 | * Returns \c true when the construction of the emoji string failed |
52 | * Returns \c false when the construction of the emoji string succeeded |
53 | */ |
54 | bool isNull() override; |
55 | |
56 | /*! |
57 | * \brief Set the Global Default Font object |
58 | * This is primarily useful for platform themes that wish to force a specific font being used. By default the "emoji" font family will be used. |
59 | * Forcing a specific font and making sure it is available as runtime requirement is the most reliable way to ensure that flag support is working |
60 | * regardless of system configuration. |
61 | * |
62 | * \a font the default font to use |
63 | */ |
64 | static void setGlobalDefaultFont(const QFont &font); |
65 | |
66 | private: |
67 | std::unique_ptr<KCountryFlagEmojiIconEnginePrivate> const d; |
68 | }; |
69 | |
70 | #endif |
71 | |