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 | * @brief Provides emoji flags as icons |
15 | * This is a special icon engine that internally paints flags using emoji fonts. |
16 | * It provides access to country and region flags from the system emoji font. |
17 | * ``` |
18 | * auto l = new QLabel; |
19 | * l->setMinimumSize(512, 512); |
20 | * l->setPixmap(QIcon(new KCountryFlagEmojiIconEngine("AT")).pixmap(512, 512)); |
21 | * ``` |
22 | * @since 6.0 |
23 | */ |
24 | class KGUIADDONS_EXPORT KCountryFlagEmojiIconEngine : public QIconEngine |
25 | { |
26 | public: |
27 | /** |
28 | * @brief Construct a new KCountryFlagEmojiIconEngine object |
29 | * Please note that regional flag support can be spotty in emoji fonts. |
30 | * @param 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) |
31 | */ |
32 | explicit KCountryFlagEmojiIconEngine(const QString ®ionOrCountry); |
33 | ~KCountryFlagEmojiIconEngine() override; |
34 | Q_DISABLE_COPY_MOVE(KCountryFlagEmojiIconEngine) |
35 | |
36 | QIconEngine *clone() const override; |
37 | QString key() const override; |
38 | void paint(QPainter *painter, const QRect &rect, QIcon::Mode mode, QIcon::State state) override; |
39 | QPixmap pixmap(const QSize &size, QIcon::Mode mode, QIcon::State state) override; |
40 | QPixmap scaledPixmap(const QSize &size, QIcon::Mode mode, QIcon::State state, qreal scale) override; |
41 | |
42 | /** |
43 | * @brief Check whether the internal emoji unicode sequence is null |
44 | * This does not necessarily mean that the pixmap output will be a valid flag - that entirely depends on the system's precise font configuration. |
45 | * @return true when the construction of the emoji string failed |
46 | * @return false when the construction of the emoji string succeeded |
47 | */ |
48 | bool isNull() override; |
49 | |
50 | /** |
51 | * @brief Set the Global Default Font object |
52 | * 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. |
53 | * 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 |
54 | * regardless of system configuration. |
55 | * @param font the default font to use |
56 | */ |
57 | static void setGlobalDefaultFont(const QFont &font); |
58 | |
59 | private: |
60 | std::unique_ptr<KCountryFlagEmojiIconEnginePrivate> const d; |
61 | }; |
62 | |
63 | #endif |
64 | |