Debian Codegraph @

libs/widgetutils/kis_font_family_combo_box.h

raw symbols SCIP
1 /* This file is part of the KDE project
2 *
3 * SPDX-FileCopyrightText: 2017 Wolthera van Hövell tot Westerflier <[email protected]>
4 *
5 * SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 #ifndef KIS_FONT_FAMILY_COMBO_BOX_H
8 #define KIS_FONT_FAMILY_COMBO_BOX_H
9
10 #include <QObject>
11 #include <KisSqueezedComboBox.h>
12 #include <QFont>
13 #include <QFontDatabase>
14 #include <QStyledItemDelegate>
15
16 #include "kritawidgetutils_export.h"
17
18 /**
19 * @brief The KisFontComboBoxes class
20 * This is a little widget with two comboboxes.
21 * One is for the font family, and the other for the style, using the power of QFontDataBase.
22 * This allows us to limit the amount of fonts visible in the fonts drop down,
23 * as that can be a quite intense number when you have several 'style complete' fonts.
24 */
25 class KRITAWIDGETUTILS_EXPORT KisFontComboBoxes : public QWidget
26 {
27 Q_OBJECT
28 public:
29 KisFontComboBoxes(QWidget *parent = 0);
30
31 /**
32 * @brief setCurrentFont
33 * sets the style and font comboboxes appropriately.
34 * @param font the QFont to set.
35 */
36 void setCurrentFont(QFont font);
37
38 void setCurrentFamily(const QString family);
39 void setCurrentStyle(QString style);
40
41 // Current family name.
42 QString currentFamily() const;
43 // Current style
44 QString currentStyle() const;
45
46 /**
47 * @brief currentFont the current QFont from both family and style combinations
48 * @param pointSize as this widget has no idea about point size, input desired point size.
49 * @return
50 */
51 QFont currentFont(int pointSize = 10) const;
52
53 void refillComboBox(QVector<QFontDatabase::WritingSystem> writingSystems = QVector<QFontDatabase::WritingSystem>());
54 void setInitialized();
55
56 Q_SIGNALS:
57 void fontChanged(QString);
58 private Q_SLOTS:
59 void fontFamilyChanged();
60 void fontChange();
61 private:
62 QComboBox *m_family;
63 QComboBox *m_styles;
64 };
65
66 class KRITAWIDGETUTILS_EXPORT PinnedFontsSeparator : public QStyledItemDelegate {
67 public:
68 PinnedFontsSeparator(QAbstractItemDelegate *_default, QWidget *parent = nullptr);
69 void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
70 void setSeparatorIndex(int index);
71 void setSeparatorAdded();
72 QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
73
74 private:
75 int m_separatorIndex;
76 bool m_separatorAdded;
77 QAbstractItemDelegate *m_defaultDelegate;
78 };
79
80 /**
81 * @brief The KisFontFamilyComboBox class
82 * A QCombobox that limits the amount of fonts it contains.
83 * Amongst others it blacklists certain fonts, it also filters
84 * out 'style' fonts, like those used for Bold and Italic,
85 * and it allows you to limit the amount of fonts to certain writing systems
86 */
87 class KRITAWIDGETUTILS_EXPORT KisFontFamilyComboBox : public QComboBox
88 {
89 Q_OBJECT
90 public:
91 KisFontFamilyComboBox(QWidget *parent = 0);
92
93 // List of writing systems to use. If empty will default to "all"
94 void refillComboBox(QVector<QFontDatabase::WritingSystem> writingSystems = QVector<QFontDatabase::WritingSystem>());
95 void setTopFont(const QString &family);
96 void setInitialized();
97
98 private Q_SLOTS:
99 void slotTextChanged(const QString &input);
100
101 private:
102 QStringList m_pinnedFonts;
103 QStringList m_blacklistedFonts;
104 bool m_initialized {false};
105 bool m_initializeFromConfig;
106 int m_separatorIndex;
107 PinnedFontsSeparator *m_fontSeparator;
108 };
109
110 #endif // KIS_FONT_FAMILY_COMBO_BOX_H