| 1 |
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#ifndef DFONTSIZEMANAGER_H |
| 6 |
#define DFONTSIZEMANAGER_H |
| 7 |
#include <DObject> |
| 8 |
|
| 9 |
#include <dtkgui_global.h> |
| 10 |
|
| 11 |
#include <QFont> |
| 12 |
#include <QObject> |
| 13 |
|
| 14 |
DGUI_BEGIN_NAMESPACE |
| 15 |
|
| 16 |
class DFontManagerPrivate; |
| 17 |
class DFontManager : public QObject |
| 18 |
, public DTK_CORE_NAMESPACE::DObject |
| 19 |
{ |
| 20 |
Q_OBJECT |
| 21 |
|
| 22 |
Q_PROPERTY(QFont t1 READ t1 NOTIFY fontChanged) |
| 23 |
Q_PROPERTY(QFont t2 READ t2 NOTIFY fontChanged) |
| 24 |
Q_PROPERTY(QFont t3 READ t3 NOTIFY fontChanged) |
| 25 |
Q_PROPERTY(QFont t4 READ t4 NOTIFY fontChanged) |
| 26 |
Q_PROPERTY(QFont t5 READ t5 NOTIFY fontChanged) |
| 27 |
Q_PROPERTY(QFont t6 READ t6 NOTIFY fontChanged) |
| 28 |
Q_PROPERTY(QFont t7 READ t7 NOTIFY fontChanged) |
| 29 |
Q_PROPERTY(QFont t8 READ t8 NOTIFY fontChanged) |
| 30 |
Q_PROPERTY(QFont t9 READ t9 NOTIFY fontChanged) |
| 31 |
Q_PROPERTY(QFont t10 READ t10 NOTIFY fontChanged) |
| 32 |
|
| 33 |
Q_PROPERTY(QFont baseFont READ baseFont WRITE setBaseFont RESET resetBaseFont NOTIFY fontChanged) |
| 34 |
|
| 35 |
public: |
| 36 |
enum SizeType { |
| 37 |
T1, |
| 38 |
T2, |
| 39 |
T3, |
| 40 |
T4, |
| 41 |
T5, |
| 42 |
T6, |
| 43 |
T7, |
| 44 |
T8, |
| 45 |
T9, |
| 46 |
T10, |
| 47 |
NSizeTypes |
| 48 |
}; |
| 49 |
Q_ENUM(SizeType) |
| 50 |
|
| 51 |
DFontManager(QObject *parent = nullptr); |
| 52 |
~DFontManager() override; |
| 53 |
|
| 54 |
Q_INVOKABLE int fontPixelSize(SizeType type) const; |
| 55 |
Q_INVOKABLE void setFontPixelSize(SizeType type, int size); |
| 56 |
|
| 57 |
Q_INVOKABLE static int fontPixelSize(const QFont &font); |
| 58 |
|
| 59 |
Q_INVOKABLE static QFont get(int pixelSize, const QFont &base); |
| 60 |
inline const QFont get(SizeType type, const QFont &base) const |
| 61 |
{ |
| 62 |
return get(fontPixelSize(type), base); |
| 63 |
} |
| 64 |
inline const QFont get(SizeType type) const |
| 65 |
{ |
| 66 |
return get(type, baseFont()); |
| 67 |
} |
| 68 |
|
| 69 |
QFont baseFont() const; |
| 70 |
void setBaseFont(const QFont &font); |
| 71 |
void resetBaseFont(); |
| 72 |
|
| 73 |
inline const QFont t1() const |
| 74 |
{ |
| 75 |
return get(T1); |
| 76 |
} |
| 77 |
inline const QFont t2() const |
| 78 |
{ |
| 79 |
return get(T2); |
| 80 |
} |
| 81 |
inline const QFont t3() const |
| 82 |
{ |
| 83 |
return get(T3); |
| 84 |
} |
| 85 |
inline const QFont t4() const |
| 86 |
{ |
| 87 |
return get(T4); |
| 88 |
} |
| 89 |
inline const QFont t5() const |
| 90 |
{ |
| 91 |
return get(T5); |
| 92 |
} |
| 93 |
inline const QFont t6() const |
| 94 |
{ |
| 95 |
return get(T6); |
| 96 |
} |
| 97 |
inline const QFont t7() const |
| 98 |
{ |
| 99 |
return get(T7); |
| 100 |
} |
| 101 |
inline const QFont t8() const |
| 102 |
{ |
| 103 |
return get(T8); |
| 104 |
} |
| 105 |
inline const QFont t9() const |
| 106 |
{ |
| 107 |
return get(T9); |
| 108 |
} |
| 109 |
inline const QFont t10() const |
| 110 |
{ |
| 111 |
return get(T10); |
| 112 |
} |
| 113 |
|
| 114 |
Q_SIGNALS: |
| 115 |
void fontChanged(); |
| 116 |
|
| 117 |
private: |
| 118 |
D_DECLARE_PRIVATE(DFontManager) |
| 119 |
}; |
| 120 |
|
| 121 |
DGUI_END_NAMESPACE |
| 122 |
|
| 123 |
#endif // DFONTSIZEMANAGER_H |