File indexing completed on 2024-04-21 14:55:54

0001 /*
0002     Requires the Qt widget libraries, available at no cost at
0003     http://www.troll.no
0004 
0005     Copyright (C) 1997 Bernd Johannes Wuebben <wuebben@kde.org>
0006     Copyright (c) 1999 Preston Brown <pbrown@kde.org>
0007     Copyright (c) 1999 Mario Weilguni <mweilguni@kde.org>
0008 
0009     This library is free software; you can redistribute it and/or
0010     modify it under the terms of the GNU Library General Public
0011     License as published by the Free Software Foundation; either
0012     version 2 of the License, or (at your option) any later version.
0013 
0014     This library is distributed in the hope that it will be useful,
0015     but WITHOUT ANY WARRANTY; without even the implied warranty of
0016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0017     Library General Public License for more details.
0018 
0019     You should have received a copy of the GNU Library General Public License
0020     along with this library; see the file COPYING.LIB.  If not, write to
0021     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0022     Boston, MA 02110-1301, USA.
0023 */
0024 #ifndef K_FONT_DIALOG_H
0025 #define K_FONT_DIALOG_H
0026 
0027 #include <kdialog.h>
0028 #include <kfontchooser.h>
0029 #include <kdelibs4support_export.h>
0030 
0031 class QFont;
0032 class QStringList;
0033 
0034 /**
0035  * @short A font selection dialog.
0036  *
0037  * The KFontDialog provides a dialog for interactive font selection.
0038  * It is basically a thin wrapper around the KFontChooser widget,
0039  * which can also be used standalone. In most cases, the simplest
0040  * use of this class is the static method KFontDialog::getFont(),
0041  * which pops up the dialog, allows the user to select a font, and
0042  * returns when the dialog is closed.
0043  *
0044  * Example:
0045  *
0046  * \code
0047  *      QFont myFont;
0048  *      int result = KFontDialog::getFont( myFont );
0049  *      if ( result == KFontDialog::Accepted )
0050  *            ...
0051  * \endcode
0052  *
0053  * \image html kfontdialog.png "KDE Font Dialog"
0054  *
0055  * @author Preston Brown <pbrown@kde.org>, Bernd Wuebben <wuebben@kde.org>
0056  *
0057  * @deprecated since 5.0, use QFontDialog instead
0058  */
0059 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KFontDialog : public KDialog
0060 {
0061     Q_OBJECT
0062 
0063 public:
0064     /**
0065      * Constructs a font selection dialog.
0066      *
0067      * @param parent The parent widget of the dialog, if any.
0068      * @param flags Defines how the font chooser is displayed.
0069      *        @see KFontChooser::DisplayFlags
0070      * @param fontlist a list of fonts to display, in XLFD format.  If
0071      *        no list is formatted, the internal KDE font list is used.
0072      *        If that has not been created, X is queried, and all fonts
0073      *        available on the system are displayed.
0074      * @param sizeIsRelativeState If not zero the widget will show a
0075      *        checkbox where the user may choose whether the font size
0076      *        is to be interpreted as relative size.
0077      *        Initial state of this checkbox will be set according to
0078      *        *sizeIsRelativeState, user choice may be retrieved by
0079      *        calling sizeIsRelative().
0080      *
0081      */
0082     KDELIBS4SUPPORT_DEPRECATED explicit KFontDialog(QWidget *parent = nullptr,
0083                          const KFontChooser::DisplayFlags &flags =
0084                              KFontChooser::NoDisplayFlags,
0085                          const QStringList &fontlist = QStringList(),
0086                          Qt::CheckState *sizeIsRelativeState = nullptr);
0087 
0088     ~KFontDialog() override;
0089     /**
0090      * Sets the currently selected font in the dialog.
0091      *
0092      * @param font The font to select.
0093      * @param onlyFixed readjust the font list to display only fixed
0094      *        width fonts if true, or vice-versa
0095      */
0096     void setFont(const QFont &font, bool onlyFixed = false);
0097 
0098     /**
0099      * @return The currently selected font in the dialog.
0100      */
0101     QFont font() const;
0102 
0103     /**
0104      * Sets the state of the checkbox indicating whether the font size
0105      * is to be interpreted as relative size.
0106      * NOTE: If parameter sizeIsRelative was not set in the constructor
0107      *       of the dialog this setting will be ignored.
0108      */
0109     void setSizeIsRelative(Qt::CheckState relative);
0110 
0111     /**
0112      * @return Whether the font size is to be interpreted as relative size
0113      *         (default: false)
0114      */
0115     Qt::CheckState sizeIsRelative() const;
0116 
0117     /**
0118      * Creates a modal font dialog, lets the user choose a font,
0119      * and returns when the dialog is closed.
0120      *
0121      * @param theFont a reference to the font to write the chosen font
0122      *        into.
0123      * @param flags Defines how the font chooser is displayed.
0124      *        @see KFontChooser::DisplayFlags
0125      * @param parent Parent widget of the dialog. Specifying a widget different
0126      *        from 0 (Null) improves centering (looks better).
0127      * @param makeFrame Draws a frame with titles around the contents.
0128      * @param sizeIsRelativeState If not zero the widget will show a
0129      *        checkbox where the user may choose whether the font size
0130      *        is to be interpreted as relative size.
0131      *        Initial state of this checkbox will be set according to
0132      *        *sizeIsRelativeState and user choice will be returned
0133      *        therein.
0134      *
0135      * @return QDialog::result().
0136      */
0137     static int getFont(QFont &theFont,
0138                        const KFontChooser::DisplayFlags &flags =
0139                            KFontChooser::NoDisplayFlags,
0140                        QWidget *parent = nullptr,
0141                        Qt::CheckState *sizeIsRelativeState = nullptr);
0142 
0143     /**
0144      * Creates a modal font difference dialog, lets the user choose a selection
0145      * of changes that should be made to a set of fonts, and returns when the
0146      * dialog is closed. Useful for choosing slight adjustments to the font set
0147      * when the user would otherwise have to manually edit a number of fonts.
0148      *
0149      * @param theFont a reference to the font to write the chosen font
0150      *        into.
0151      * @param flags  Defines how the font chooser is displayed.
0152      *        @see KFontChooser::DisplayFlags
0153      * @param diffFlags a reference to the int into which the chosen
0154      *        difference selection bitmask should be written.
0155      *        Check the returned bitmask like:
0156      *        \code
0157      *        if ( diffFlags & KFontChooser::FontDiffFamily )
0158      *            [...]
0159      *        if ( diffFlags & KFontChooser::FontDiffStyle )
0160      *            [...]
0161      *        if ( diffFlags & KFontChooser::FontDiffSize )
0162      *            [...]
0163      *        \endcode
0164      * @param parent Parent widget of the dialog. Specifying a widget different
0165      *        from 0 (Null) improves centering (looks better).
0166      * @param sizeIsRelativeState If not zero the widget will show a
0167      *        checkbox where the user may choose whether the font size
0168      *        is to be interpreted as relative size.
0169      *        Initial state of this checkbox will be set according to
0170      *        *sizeIsRelativeState and user choice will be returned
0171      *        therein.
0172      *
0173      * @returns QDialog::result().
0174      */
0175     static int getFontDiff(QFont &theFont,
0176                            KFontChooser::FontDiffFlags &diffFlags,
0177                            const KFontChooser::DisplayFlags &flags =
0178                                KFontChooser::NoDisplayFlags,
0179                            QWidget *parent = nullptr,
0180                            Qt::CheckState *sizeIsRelativeState = nullptr);
0181 
0182     /**
0183      * When you are not only interested in the font selected, but also
0184      * in the example string typed in, you can call this method.
0185      *
0186      * @param theFont a reference to the font to write the chosen font
0187      *        into.
0188      * @param theString a reference to the example text that was typed.
0189      * @param flags  Defines how the font chooser is displayed.
0190      *        @see KFontChooser::DisplayFlags
0191      * @param parent Parent widget of the dialog. Specifying a widget different
0192      *        from 0 (Null) improves centering (looks better).
0193      * @param sizeIsRelativeState If not zero the widget will show a
0194      *        checkbox where the user may choose whether the font size
0195      *        is to be interpreted as relative size.
0196      *        Initial state of this checkbox will be set according to
0197      *        *sizeIsRelativeState and user choice will be returned
0198      *        therein.
0199      * @return The result of the dialog.
0200      */
0201     static int getFontAndText(QFont &theFont, QString &theString,
0202                               const KFontChooser::DisplayFlags &flags =
0203                                   KFontChooser::NoDisplayFlags,
0204                               QWidget *parent = nullptr,
0205                               Qt::CheckState *sizeIsRelativeState = nullptr);
0206 
0207 Q_SIGNALS:
0208     /**
0209      * Emitted whenever the currently selected font changes.
0210      * Connect to this to monitor the font as it is selected if you are
0211      * not running modal.
0212      */
0213     void fontSelected(const QFont &font);
0214 
0215 private:
0216     class Private;
0217     Private *const d;
0218 
0219     Q_DISABLE_COPY(KFontDialog)
0220 };
0221 
0222 #endif