1 | /* |
2 | SPDX-FileCopyrightText: 2003 Nadeem Hasan <nhasan@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #ifndef KFONTREQUESTER_H |
8 | #define KFONTREQUESTER_H |
9 | |
10 | #include <QFont> |
11 | #include <QString> |
12 | #include <QWidget> |
13 | #include <memory> |
14 | |
15 | #include <kwidgetsaddons_export.h> |
16 | |
17 | class QLabel; |
18 | class QPushButton; |
19 | |
20 | /*! |
21 | * \class KFontRequester |
22 | * \inmodule KWidgetsAddons |
23 | * |
24 | * \brief This class provides a widget with a lineedit and a button, which invokes |
25 | * a font dialog (KFontChooserDialog). |
26 | * |
27 | * The lineedit provides a preview of the selected font. The preview text can |
28 | * be customized. You can also have the font dialog show only the fixed fonts. |
29 | * |
30 | * \image kfontrequester.png "KFontRequester" |
31 | */ |
32 | class KWIDGETSADDONS_EXPORT KFontRequester : public QWidget |
33 | { |
34 | Q_OBJECT |
35 | |
36 | /*! |
37 | * \property KFontRequester::title |
38 | */ |
39 | Q_PROPERTY(QString title READ title WRITE setTitle) |
40 | |
41 | /*! |
42 | * \property KFontRequester::sampleText |
43 | */ |
44 | Q_PROPERTY(QString sampleText READ sampleText WRITE setSampleText) |
45 | |
46 | /*! |
47 | * \property KFontRequester::font |
48 | */ |
49 | Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontSelected USER true) |
50 | |
51 | public: |
52 | /*! |
53 | * Constructs a font requester widget. |
54 | * |
55 | * \a parent The parent widget. |
56 | * |
57 | * \a onlyFixed Only display fonts which have fixed-width character |
58 | * sizes. |
59 | */ |
60 | explicit KFontRequester(QWidget *parent = nullptr, bool onlyFixed = false); |
61 | |
62 | ~KFontRequester() override; |
63 | |
64 | /*! |
65 | * Returns the currently selected font in the requester. |
66 | */ |
67 | QFont font() const; |
68 | |
69 | /*! |
70 | * Returns \c true if only fixed fonts are displayed. |
71 | */ |
72 | bool isFixedOnly() const; |
73 | |
74 | /*! |
75 | * Returns the current text in the sample text input area. |
76 | */ |
77 | QString sampleText() const; |
78 | |
79 | /*! |
80 | * Returns the current title of the widget. |
81 | */ |
82 | QString title() const; |
83 | |
84 | /*! |
85 | * Returns pointer to the label used for preview. |
86 | */ |
87 | QLabel *label() const; |
88 | |
89 | /*! |
90 | * Returns pointer to the pushbutton in the widget. |
91 | */ |
92 | QPushButton *button() const; |
93 | |
94 | /*! |
95 | * Sets the currently selected font in the requester. |
96 | * |
97 | * \a font The font to select. |
98 | * |
99 | * \a onlyFixed Display only fixed-width fonts in the font dialog |
100 | * if \c true, or vice-versa. |
101 | */ |
102 | virtual void setFont(const QFont &font, bool onlyFixed = false); |
103 | |
104 | /*! |
105 | * Sets the sample text. |
106 | * |
107 | * Normally you should not change this |
108 | * text, but it can be better to do this if the default text is |
109 | * too large for the edit area when using the default font of your |
110 | * application. Default text is current font name and size. Setting |
111 | * the text to QString() will restore the default. |
112 | * |
113 | * \a text The new sample text. The current will be removed. |
114 | */ |
115 | virtual void setSampleText(const QString &text); |
116 | |
117 | /*! |
118 | * Set the title for the widget that will be used in the tooltip and |
119 | * what's this text. |
120 | * |
121 | * \a title The title to be set. |
122 | */ |
123 | virtual void setTitle(const QString &title); |
124 | |
125 | Q_SIGNALS: |
126 | /*! |
127 | * Emitted when a new \a font has been selected in the underlying dialog |
128 | */ |
129 | void fontSelected(const QFont &font); |
130 | |
131 | protected: |
132 | bool eventFilter(QObject *watched, QEvent *event) override; |
133 | |
134 | private: |
135 | friend class KFontRequesterPrivate; |
136 | std::unique_ptr<class KFontRequesterPrivate> const d; |
137 | |
138 | Q_DISABLE_COPY(KFontRequester) |
139 | }; |
140 | |
141 | #endif // KFONTREQUESTER_H |
142 | |