File indexing completed on 2024-03-24 15:27:41

0001 /*  This file is part of the KDE libraries
0002 
0003     Copyright (C) 2008 Chusslove Illich <caslav.ilic@gmx.net>
0004 
0005     This library is free software; you can redistribute it and/or
0006     modify it under the terms of the GNU Library General Public
0007     License as published by the Free Software Foundation; either
0008     version 2 of the License, or (at your option) any later version.
0009 
0010     This library is distributed in the hope that it will be useful,
0011     but WITHOUT ANY WARRANTY; without even the implied warranty of
0012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0013     Library General Public License for more details.
0014 
0015     You should have received a copy of the GNU Library General Public License
0016     along with this library; see the file COPYING.LIB.  If not, write to
0017     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0018     Boston, MA 02110-1301, USA.
0019 */
0020 #ifndef KFONTCOMBOBOX_P_H
0021 #define KFONTCOMBOBOX_P_H
0022 
0023 #include <kdelibs4support_export.h>
0024 
0025 #include <kcombobox.h>
0026 
0027 class KFontComboBoxPrivate;
0028 
0029 /**
0030  * @short A lightweight font selection widget.
0031  *
0032  * A combobox to select the font from. Lightweight counterpart to KFontChooser,
0033  * for situations where only the font family should be selected, while the
0034  * font style and size are handled by other means. Like in KFontChooser,
0035  * this widget will show the font previews in the unrolled dropdown list.
0036  *
0037  * @note The class is similar to QFontComboBox, but more tightly integrated
0038  * with KDE desktop. Use it instead of QFontComboBox by default in KDE code.
0039  *
0040  * \image html kfontcombobox.png "KDE Font Combo Box"
0041  *
0042  * @author Chusslove Illich \<caslav.ilic@gmx.net\>
0043  *
0044  * @see KFontAction
0045  * @see KFontChooser
0046  *
0047  * @since 4.1
0048  *
0049  * @deprecated Since KF 5.0, use QFontComboBox instead
0050  */
0051 class KDELIBS4SUPPORT_DEPRECATED_EXPORT KFontComboBox : public KComboBox
0052 {
0053     Q_OBJECT
0054 
0055     Q_PROPERTY(QFont currentFont READ currentFont WRITE setCurrentFont NOTIFY currentFontChanged USER true)
0056 
0057 public:
0058 
0059     /**
0060      * Constructor.
0061      *
0062      * @param parent the parent widget
0063      */
0064     KDELIBS4SUPPORT_DEPRECATED explicit KFontComboBox(QWidget *parent = nullptr);
0065 
0066     /**
0067      * Toggle selectable fonts to be only those of fixed width or all.
0068      *
0069      * @param onlyFixed only fixed width fonts when @p true,
0070      *                  all fonts when @p false
0071      *
0072      * @deprecated use QFontComboBox::setFontFilters(QFontComboBox::MonospacedFonts)
0073      */
0074     void setOnlyFixed(bool onlyFixed);
0075 
0076     /**
0077      * Set selectable fonts to be only those present in the list.
0078      *
0079      * @param fontList a list of fonts as returned by QFontDatabase::families() or
0080      *                  QFontChooser::getFontList(). If this is empty (default), then the list
0081      *                  of fonts is constructed according to the @p onlyFixed setting.
0082      * @since 4.9.2
0083      */
0084     void setFontList(const QStringList &fontList);
0085 
0086     /**
0087      * Destructor.
0088      */
0089     ~KFontComboBox() override;
0090 
0091     /**
0092      * The font currently selected from the list.
0093      *
0094      * @return the selected font
0095      */
0096     QFont currentFont() const;
0097 
0098     /**
0099      * The recommended size of the widget.
0100      * Reimplemented to make the recommended width independent
0101      * of the particular fonts installed.
0102      *
0103      * @return recommended size
0104      */
0105     QSize sizeHint() const override;
0106 
0107 public Q_SLOTS:
0108     /**
0109      * Set the font to show as selected in the combobox.
0110      *
0111      * @param font the new font
0112      */
0113     void setCurrentFont(const QFont &font);
0114 
0115 Q_SIGNALS:
0116     /**
0117      * Emitted when a new font has been selected,
0118      * either through user input or by setFont().
0119      *
0120      * @param font the new font
0121      */
0122     void currentFontChanged(const QFont &font);
0123 
0124 protected:
0125     bool event(QEvent *e) override;
0126 
0127 private:
0128 
0129     friend class KFontComboBoxPrivate;
0130     KFontComboBoxPrivate *const d;
0131 
0132     Q_DISABLE_COPY(KFontComboBox)
0133 
0134     Q_PRIVATE_SLOT(d, void _k_currentFontChanged(int))
0135 };
0136 
0137 #endif