Changeset View
Changeset View
Standalone View
Standalone View
src/kfontdialog.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@kde.org> | ||||
3 | Copyright (c) 1999 Preston Brown <pbrown@kde.org> | ||||
4 | Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org> | ||||
5 | | ||||
6 | This library is free software; you can redistribute it and/or | ||||
7 | modify it under the terms of the GNU Library General Public | ||||
8 | License as published by the Free Software Foundation; either | ||||
9 | version 2 of the License, or (at your option) any later version. | ||||
10 | | ||||
11 | This library is distributed in the hope that it will be useful, | ||||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
14 | Library General Public License for more details. | ||||
15 | | ||||
16 | You should have received a copy of the GNU Library General Public License | ||||
17 | along with this library; see the file COPYING.LIB. If not, write to | ||||
18 | the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||||
19 | Boston, MA 02110-1301, USA. | ||||
20 | */ | ||||
21 | #ifndef K_FONT_DIALOG_H | ||||
22 | #define K_FONT_DIALOG_H | ||||
23 | | ||||
24 | #include <QDialog> | ||||
25 | | ||||
26 | #include <kfontchooser.h> | ||||
27 | | ||||
28 | class QFont; | ||||
29 | class QStringList; | ||||
30 | | ||||
31 | /** | ||||
32 | * @short A font selection dialog. | ||||
33 | * | ||||
34 | * The KFontDialog provides a dialog for interactive font selection. | ||||
35 | * It is basically a thin wrapper around the KFontChooser widget, | ||||
36 | * which can also be used standalone. In most cases, the simplest | ||||
37 | * use of this class is the static method KFontDialog::getFont(), | ||||
38 | * which pops up the dialog, allows the user to select a font, and | ||||
39 | * returns when the dialog is closed. | ||||
40 | * | ||||
41 | * Example: | ||||
42 | * | ||||
43 | * \code | ||||
44 | * QFont myFont; | ||||
45 | * int result = KFontDialog::getFont(myFont); | ||||
46 | * if (result == QDialog::Accepted) { | ||||
47 | * ... | ||||
48 | * } | ||||
49 | * \endcode | ||||
50 | * | ||||
51 | * \image html kfontdialog.png "KDE Font Dialog" | ||||
52 | * | ||||
53 | * @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org> | ||||
54 | * | ||||
55 | */ | ||||
56 | class KWIDGETSADDONS_EXPORT KFontDialog : public QDialog | ||||
57 | { | ||||
58 | Q_OBJECT | ||||
59 | | ||||
60 | public: | ||||
61 | /** | ||||
62 | * Constructs a font selection dialog. | ||||
63 | * | ||||
64 | * @param parent The parent widget of the dialog, if any. | ||||
65 | * @param flags Defines how the font chooser is displayed. | ||||
66 | * @see KFontChooser::DisplayFlags | ||||
67 | * @param fontlist a list of fonts to display, in XLFD format. If | ||||
68 | * no list is formatted, the internal KDE font list is used. | ||||
69 | * If that has not been created, X is queried, and all fonts | ||||
70 | * available on the system are displayed. | ||||
71 | * | ||||
72 | */ | ||||
73 | explicit KFontDialog(QWidget *parent = nullptr, | ||||
74 | const KFontChooser::DisplayFlags &flags = KFontChooser::NoDisplayFlags, | ||||
75 | const QStringList &fontlist = QStringList()); | ||||
76 | | ||||
77 | ~KFontDialog(); | ||||
78 | | ||||
79 | /** | ||||
80 | * Sets the currently selected font in the dialog. | ||||
81 | * | ||||
82 | * @param font The font to select | ||||
83 | * @param onlyFixed If true, the font list will show only fixed width (monospace) | ||||
84 | * fonts, otherwise all available fonts are shown | ||||
85 | */ | ||||
86 | void setFont(const QFont &font, bool onlyFixed = false); | ||||
87 | | ||||
88 | /** | ||||
89 | * @return The currently selected font in the dialog. | ||||
90 | */ | ||||
91 | QFont font() const; | ||||
92 | | ||||
93 | /** | ||||
94 | * Creates a modal font dialog, lets the user choose a font, and returns when | ||||
95 | * the dialog is closed. | ||||
96 | * | ||||
97 | * @param theFont a reference to the font to write the chosen font into. | ||||
98 | * @param flags Defines how the font chooser is displayed. | ||||
99 | * @see KFontChooser::DisplayFlags | ||||
100 | * @param parent Parent widget of the dialog; the dialog will be centered in front | ||||
101 | * of it. | ||||
102 | * @return QDialog::result(). | ||||
103 | */ | ||||
104 | static int getFont(QFont &theFont, | ||||
105 | const KFontChooser::DisplayFlags &flags = KFontChooser::NoDisplayFlags, | ||||
106 | QWidget *parent = nullptr); | ||||
107 | | ||||
108 | /** | ||||
109 | * Creates a modal font difference dialog, lets the user choose a selection | ||||
110 | * of changes that should be made to a set of fonts, and returns when the | ||||
111 | * dialog is closed. Useful for choosing slight adjustments to the font set | ||||
112 | * when the user would otherwise have to manually edit a number of fonts. | ||||
113 | * | ||||
114 | * @param theFont a reference to the font to write the chosen font into. | ||||
115 | * @param flags Defines how the font chooser is displayed. | ||||
116 | * @see KFontChooser::DisplayFlags | ||||
117 | * @param diffFlags a reference to the int into which the chosen | ||||
118 | * difference selection bitmask should be written. | ||||
119 | * Check the returned bitmask like: | ||||
120 | * \code | ||||
121 | * if ( diffFlags & KFontChooser::FontDiffFamily ) { | ||||
122 | * [...] | ||||
123 | * } | ||||
124 | * if ( diffFlags & KFontChooser::FontDiffStyle ) { | ||||
125 | * [...] | ||||
126 | * } | ||||
127 | * if ( diffFlags & KFontChooser::FontDiffSize ) { | ||||
128 | * [...] | ||||
129 | * } | ||||
130 | * \endcode | ||||
131 | * @param parent Parent widget of the dialog; the dialog will be centered top of it. | ||||
132 | * | ||||
133 | * @returns QDialog::result(). | ||||
134 | */ | ||||
135 | static int getFontDiff(QFont &theFont, | ||||
136 | KFontChooser::FontDiffFlags &diffFlags, | ||||
137 | const KFontChooser::DisplayFlags &flags = KFontChooser::NoDisplayFlags, | ||||
138 | QWidget *parent = nullptr); | ||||
139 | | ||||
140 | Q_SIGNALS: | ||||
141 | /** | ||||
142 | * Emitted whenever the currently selected font changes. | ||||
143 | * Connect to this to monitor the font as it is selected if you are | ||||
144 | * not running modal. | ||||
145 | */ | ||||
146 | void fontSelected(const QFont &font); | ||||
147 | | ||||
148 | private: | ||||
149 | KFontDialogPrivate *const d; | ||||
150 | | ||||
151 | Q_DISABLE_COPY(KFontDialog) | ||||
152 | }; | ||||
153 | | ||||
154 | #endif |