KWidgetsAddons

kfontrequester.h
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
17class QLabel;
18class QPushButton;
19
20/**
21 * @class KFontRequester kfontrequester.h KFontRequester
22 *
23 * This class provides a widget with a lineedit and a button, which invokes
24 * a font dialog (KFontChooserDialog).
25 *
26 * The lineedit provides a preview of the selected font. The preview text can
27 * be customized. You can also have the font dialog show only the fixed fonts.
28 *
29 * \image html kfontrequester.png "KFontRequester"
30 *
31 * @author Nadeem Hasan <nhasan@kde.org>
32 */
33class KWIDGETSADDONS_EXPORT KFontRequester : public QWidget
34{
35 Q_OBJECT
36
37 Q_PROPERTY(QString title READ title WRITE setTitle)
38 Q_PROPERTY(QString sampleText READ sampleText WRITE setSampleText)
39 Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontSelected USER true)
40
41public:
42 /**
43 * Constructs a font requester widget.
44 *
45 * @param parent The parent widget.
46 * @param onlyFixed Only display fonts which have fixed-width character
47 * sizes.
48 */
49 explicit KFontRequester(QWidget *parent = nullptr, bool onlyFixed = false);
50
51 ~KFontRequester() override;
52
53 /**
54 * @return The currently selected font in the requester.
55 */
56 QFont font() const;
57
58 /**
59 * @return Returns true if only fixed fonts are displayed.
60 */
61 bool isFixedOnly() const;
62
63 /**
64 * @return The current text in the sample text input area.
65 */
66 QString sampleText() const;
67
68 /**
69 * @return The current title of the widget.
70 */
71 QString title() const;
72
73 /**
74 * @return Pointer to the label used for preview.
75 */
76 QLabel *label() const;
77
78 /**
79 * @return Pointer to the pushbutton in the widget.
80 */
81 QPushButton *button() const;
82
83 /**
84 * Sets the currently selected font in the requester.
85 *
86 * @param font The font to select.
87 * @param onlyFixed Display only fixed-width fonts in the font dialog
88 * if @p true, or vice-versa.
89 */
90 virtual void setFont(const QFont &font, bool onlyFixed = false);
91
92 /**
93 * Sets the sample text.
94 *
95 * Normally you should not change this
96 * text, but it can be better to do this if the default text is
97 * too large for the edit area when using the default font of your
98 * application. Default text is current font name and size. Setting
99 * the text to QString() will restore the default.
100 *
101 * @param text The new sample text. The current will be removed.
102 */
103 virtual void setSampleText(const QString &text);
104
105 /**
106 * Set the title for the widget that will be used in the tooltip and
107 * what's this text.
108 *
109 * @param title The title to be set.
110 */
111 virtual void setTitle(const QString &title);
112
114 /**
115 * Emitted when a new @p font has been selected in the underlying dialog
116 */
117 void fontSelected(const QFont &font);
118
119protected:
120 bool eventFilter(QObject *watched, QEvent *event) override;
121
122private:
123 friend class KFontRequesterPrivate;
124 std::unique_ptr<class KFontRequesterPrivate> const d;
125
127};
128
129#endif // KFONTREQUESTER_H
This class provides a widget with a lineedit and a button, which invokes a font dialog (KFontChooserD...
void fontSelected(const QFont &font)
Emitted when a new font has been selected in the underlying dialog.
Q_PROPERTY(...)
Q_SIGNALSQ_SIGNALS
virtual bool eventFilter(QObject *watched, QEvent *event)
T qobject_cast(QObject *object)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:14:43 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.