Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | | - |
5 | | - |
6 | | - |
7 | static QFontDatabase::WritingSystem writingSystemForFont(const QFont &font, bool *hasLatin) | - |
8 | { | - |
9 | *hasLatin = true; | - |
10 | | - |
11 | QList<QFontDatabase::WritingSystem> writingSystems = QFontDatabase().writingSystems(font.family()); | - |
12 | | - |
13 | | - |
14 | | - |
15 | writingSystems.removeAll(QFontDatabase::Vietnamese); | - |
16 | | - |
17 | QFontDatabase::WritingSystem system = QFontDatabase::Any; | - |
18 | | - |
19 | if (!writingSystems.contains(QFontDatabase::Latin)) { never evaluated: !writingSystems.contains(QFontDatabase::Latin) | 0 |
20 | *hasLatin = false; | - |
21 | | - |
22 | if (writingSystems.count()) never evaluated: writingSystems.count() | 0 |
23 | system = writingSystems.last(); never executed: system = writingSystems.last(); | 0 |
24 | } else { | 0 |
25 | writingSystems.removeAll(QFontDatabase::Latin); | - |
26 | } | 0 |
27 | | - |
28 | if (writingSystems.isEmpty()) never evaluated: writingSystems.isEmpty() | 0 |
29 | return system; never executed: return system; | 0 |
30 | | - |
31 | if (writingSystems.count() == 1 && writingSystems.at(0) > QFontDatabase::Cyrillic) { never evaluated: writingSystems.count() == 1 never evaluated: writingSystems.at(0) > QFontDatabase::Cyrillic | 0 |
32 | system = writingSystems.at(0); | - |
33 | return system; never executed: return system; | 0 |
34 | } | - |
35 | | - |
36 | if (writingSystems.count() <= 2 never evaluated: writingSystems.count() <= 2 | 0 |
37 | && writingSystems.last() > QFontDatabase::Armenian never evaluated: writingSystems.last() > QFontDatabase::Armenian | 0 |
38 | && writingSystems.last() < QFontDatabase::Vietnamese) { never evaluated: writingSystems.last() < QFontDatabase::Vietnamese | 0 |
39 | system = writingSystems.last(); | - |
40 | return system; never executed: return system; | 0 |
41 | } | - |
42 | | - |
43 | if (writingSystems.count() <= 5 never evaluated: writingSystems.count() <= 5 | 0 |
44 | && writingSystems.last() >= QFontDatabase::SimplifiedChinese never evaluated: writingSystems.last() >= QFontDatabase::SimplifiedChinese | 0 |
45 | && writingSystems.last() <= QFontDatabase::Korean) never evaluated: writingSystems.last() <= QFontDatabase::Korean | 0 |
46 | system = writingSystems.last(); never executed: system = writingSystems.last(); | 0 |
47 | | - |
48 | return system; never executed: return system; | 0 |
49 | } | - |
50 | | - |
51 | class QFontFamilyDelegate : public QAbstractItemDelegate | - |
52 | { | - |
53 | public: template <typename T> inline void qt_check_for_QOBJECT_macro(const T &_q_argument) const { int i = qYouForgotTheQ_OBJECT_Macro(this, &_q_argument); i = i + 1; } static const QMetaObject staticMetaObject; virtual const QMetaObject *metaObject() const; virtual void *qt_metacast(const char *); static inline QString tr(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } __attribute__ ((__deprecated__)) static inline QString trUtf8(const char *s, const char *c = 0, int n = -1) { return staticMetaObject.tr(s, c, n); } virtual int qt_metacall(QMetaObject::Call, int, void **); private: __attribute__((visibility("hidden"))) static void qt_static_metacall(QObject *, QMetaObject::Call, int, void **); struct QPrivateSignal {}; | - |
54 | public: | - |
55 | explicit QFontFamilyDelegate(QObject *parent); | - |
56 | | - |
57 | | - |
58 | void paint(QPainter *painter, | - |
59 | const QStyleOptionViewItem &option, | - |
60 | const QModelIndex &index) const; | - |
61 | | - |
62 | QSize sizeHint(const QStyleOptionViewItem &option, | - |
63 | const QModelIndex &index) const; | - |
64 | | - |
65 | QIcon truetype; | - |
66 | QIcon bitmap; | - |
67 | QFontDatabase::WritingSystem writingSystem; | - |
68 | }; | - |
69 | | - |
70 | QFontFamilyDelegate::QFontFamilyDelegate(QObject *parent) | - |
71 | : QAbstractItemDelegate(parent) | - |
72 | { | - |
73 | truetype = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png")); | - |
74 | bitmap = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png")); | - |
75 | writingSystem = QFontDatabase::Any; | - |
76 | } executed: } Execution Count:140 | 140 |
77 | | - |
78 | void QFontFamilyDelegate::paint(QPainter *painter, | - |
79 | const QStyleOptionViewItem &option, | - |
80 | const QModelIndex &index) const | - |
81 | { | - |
82 | QString text = index.data(Qt::DisplayRole).toString(); | - |
83 | QFont font(option.font); | - |
84 | font.setPointSize(QFontInfo(font).pointSize() * 3 / 2); | - |
85 | QFont font2 = font; | - |
86 | font2.setFamily(text); | - |
87 | | - |
88 | bool hasLatin; | - |
89 | QFontDatabase::WritingSystem system = writingSystemForFont(font2, &hasLatin); | - |
90 | if (hasLatin) never evaluated: hasLatin | 0 |
91 | font = font2; never executed: font = font2; | 0 |
92 | | - |
93 | QRect r = option.rect; | - |
94 | | - |
95 | if (option.state & QStyle::State_Selected) { never evaluated: option.state & QStyle::State_Selected | 0 |
96 | painter->save(); | - |
97 | painter->setBrush(option.palette.highlight()); | - |
98 | painter->setPen(Qt::NoPen); | - |
99 | painter->drawRect(option.rect); | - |
100 | painter->setPen(QPen(option.palette.highlightedText(), 0)); | - |
101 | } | 0 |
102 | | - |
103 | const QIcon *icon = &bitmap; | - |
104 | if (QFontDatabase().isSmoothlyScalable(text)) { never evaluated: QFontDatabase().isSmoothlyScalable(text) | 0 |
105 | icon = &truetype; | - |
106 | } | 0 |
107 | QSize actualSize = icon->actualSize(r.size()); | - |
108 | | - |
109 | icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter); | - |
110 | if (option.direction == Qt::RightToLeft) never evaluated: option.direction == Qt::RightToLeft | 0 |
111 | r.setRight(r.right() - actualSize.width() - 4); never executed: r.setRight(r.right() - actualSize.width() - 4); | 0 |
112 | else | - |
113 | r.setLeft(r.left() + actualSize.width() + 4); never executed: r.setLeft(r.left() + actualSize.width() + 4); | 0 |
114 | | - |
115 | QFont old = painter->font(); | - |
116 | painter->setFont(font); | - |
117 | | - |
118 | | - |
119 | | - |
120 | | - |
121 | | - |
122 | QFontMetricsF fontMetrics(font); | - |
123 | if (fontMetrics.ascent() > r.height()) { never evaluated: fontMetrics.ascent() > r.height() | 0 |
124 | QRectF tbr = fontMetrics.tightBoundingRect(text); | - |
125 | painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text); | - |
126 | } else { | 0 |
127 | painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text); | - |
128 | } | 0 |
129 | | - |
130 | if (writingSystem != QFontDatabase::Any) never evaluated: writingSystem != QFontDatabase::Any | 0 |
131 | system = writingSystem; never executed: system = writingSystem; | 0 |
132 | | - |
133 | if (system != QFontDatabase::Any) { never evaluated: system != QFontDatabase::Any | 0 |
134 | int w = painter->fontMetrics().width(text + QLatin1String(" ")); | - |
135 | painter->setFont(font2); | - |
136 | QString sample = QFontDatabase().writingSystemSample(system); | - |
137 | if (option.direction == Qt::RightToLeft) never evaluated: option.direction == Qt::RightToLeft | 0 |
138 | r.setRight(r.right() - w); never executed: r.setRight(r.right() - w); | 0 |
139 | else | - |
140 | r.setLeft(r.left() + w); never executed: r.setLeft(r.left() + w); | 0 |
141 | painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, sample); | - |
142 | } | 0 |
143 | painter->setFont(old); | - |
144 | | - |
145 | if (option.state & QStyle::State_Selected) never evaluated: option.state & QStyle::State_Selected | 0 |
146 | painter->restore(); never executed: painter->restore(); | 0 |
147 | | - |
148 | } | 0 |
149 | | - |
150 | QSize QFontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option, | - |
151 | const QModelIndex &index) const | - |
152 | { | - |
153 | QString text = index.data(Qt::DisplayRole).toString(); | - |
154 | QFont font(option.font); | - |
155 | | - |
156 | font.setPointSize(QFontInfo(font).pointSize() * 3/2); | - |
157 | QFontMetrics fontMetrics(font); | - |
158 | return QSize(fontMetrics.width(text), fontMetrics.height()); never executed: return QSize(fontMetrics.width(text), fontMetrics.height()); | 0 |
159 | } | - |
160 | | - |
161 | | - |
162 | class QFontComboBoxPrivate : public QComboBoxPrivate | - |
163 | { | - |
164 | public: | - |
165 | inline QFontComboBoxPrivate() { filters = QFontComboBox::AllFonts; } executed: } Execution Count:140 | 140 |
166 | | - |
167 | QFontComboBox::FontFilters filters; | - |
168 | QFont currentFont; | - |
169 | | - |
170 | void _q_updateModel(); | - |
171 | void _q_currentChanged(const QString &); | - |
172 | | - |
173 | inline QFontComboBox* q_func() { return static_cast<QFontComboBox *>(q_ptr); } inline const QFontComboBox* q_func() const { return static_cast<const QFontComboBox *>(q_ptr); } friend class QFontComboBox; | - |
174 | }; | - |
175 | | - |
176 | | - |
177 | void QFontComboBoxPrivate::_q_updateModel() | - |
178 | { | - |
179 | QFontComboBox * const q = q_func(); | - |
180 | const int scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts); | - |
181 | const int spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts); | - |
182 | | - |
183 | QStringListModel *m = qobject_cast<QStringListModel *>(q->model()); | - |
184 | if (!m) partially evaluated: !m no Evaluation Count:0 | yes Evaluation Count:280 |
| 0-280 |
185 | return; | 0 |
186 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(q->view()->itemDelegate()); | - |
187 | QFontDatabase::WritingSystem system = delegate ? delegate->writingSystem : QFontDatabase::Any; partially evaluated: delegate yes Evaluation Count:280 | no Evaluation Count:0 |
| 0-280 |
188 | | - |
189 | QFontDatabase fdb; | - |
190 | QStringList list = fdb.families(system); | - |
191 | QStringList result; | - |
192 | | - |
193 | int offset = 0; | - |
194 | QFontInfo fi(currentFont); | - |
195 | | - |
196 | for (int i = 0; i < list.size(); ++i) { evaluated: i < list.size() yes Evaluation Count:22487 | yes Evaluation Count:280 |
| 280-22487 |
197 | if ((filters & scalableMask) && (filters & scalableMask) != scalableMask) { evaluated: (filters & scalableMask) yes Evaluation Count:364 | yes Evaluation Count:22123 |
evaluated: (filters & scalableMask) != scalableMask yes Evaluation Count:273 | yes Evaluation Count:91 |
| 91-22123 |
198 | if (bool(filters & QFontComboBox::ScalableFonts) != fdb.isSmoothlyScalable(list.at(i))) evaluated: bool(filters & QFontComboBox::ScalableFonts) != fdb.isSmoothlyScalable(list.at(i)) yes Evaluation Count:182 | yes Evaluation Count:91 |
| 91-182 |
199 | continue; executed: continue; Execution Count:182 | 182 |
200 | } executed: } Execution Count:91 | 91 |
201 | if ((filters & spacingMask) && (filters & spacingMask) != spacingMask) { evaluated: (filters & spacingMask) yes Evaluation Count:182 | yes Evaluation Count:22123 |
partially evaluated: (filters & spacingMask) != spacingMask yes Evaluation Count:182 | no Evaluation Count:0 |
| 0-22123 |
202 | if (bool(filters & QFontComboBox::MonospacedFonts) != fdb.isFixedPitch(list.at(i))) evaluated: bool(filters & QFontComboBox::MonospacedFonts) != fdb.isFixedPitch(list.at(i)) yes Evaluation Count:91 | yes Evaluation Count:91 |
| 91 |
203 | continue; executed: continue; Execution Count:91 | 91 |
204 | } executed: } Execution Count:91 | 91 |
205 | result += list.at(i); | - |
206 | if (list.at(i) == fi.family() || list.at(i).startsWith(fi.family() + QLatin1String(" ["))) evaluated: list.at(i) == fi.family() yes Evaluation Count:252 | yes Evaluation Count:21962 |
partially evaluated: list.at(i).startsWith(fi.family() + QLatin1String(" [")) no Evaluation Count:0 | yes Evaluation Count:21962 |
| 0-21962 |
207 | offset = result.count() - 1; executed: offset = result.count() - 1; Execution Count:252 | 252 |
208 | } executed: } Execution Count:22214 | 22214 |
209 | list = result; | - |
210 | | - |
211 | | - |
212 | | - |
213 | | - |
214 | | - |
215 | const bool old = m->blockSignals(true); | - |
216 | m->setStringList(list); | - |
217 | m->blockSignals(old); | - |
218 | | - |
219 | if (list.isEmpty()) { evaluated: list.isEmpty() yes Evaluation Count:23 | yes Evaluation Count:257 |
| 23-257 |
220 | if (currentFont != QFont()) { partially evaluated: currentFont != QFont() no Evaluation Count:0 | yes Evaluation Count:23 |
| 0-23 |
221 | currentFont = QFont(); | - |
222 | q->currentFontChanged(currentFont); | - |
223 | } | 0 |
224 | } else { executed: } Execution Count:23 | 23 |
225 | q->setCurrentIndex(offset); | - |
226 | } executed: } Execution Count:257 | 257 |
227 | } | - |
228 | | - |
229 | | - |
230 | void QFontComboBoxPrivate::_q_currentChanged(const QString &text) | - |
231 | { | - |
232 | QFontComboBox * const q = q_func(); | - |
233 | if (currentFont.family() != text) { evaluated: currentFont.family() != text yes Evaluation Count:24 | yes Evaluation Count:94 |
| 24-94 |
234 | currentFont.setFamily(text); | - |
235 | q->currentFontChanged(currentFont); | - |
236 | } executed: } Execution Count:24 | 24 |
237 | } executed: } Execution Count:118 | 118 |
238 | QFontComboBox::QFontComboBox(QWidget *parent) | - |
239 | : QComboBox(*new QFontComboBoxPrivate, parent) | - |
240 | { | - |
241 | QFontComboBoxPrivate * const d = d_func(); | - |
242 | d->currentFont = font(); | - |
243 | setEditable(true); | - |
244 | | - |
245 | QStringListModel *m = new QStringListModel(this); | - |
246 | setModel(m); | - |
247 | setItemDelegate(new QFontFamilyDelegate(this)); | - |
248 | QListView *lview = qobject_cast<QListView*>(view()); | - |
249 | if (lview) partially evaluated: lview yes Evaluation Count:140 | no Evaluation Count:0 |
| 0-140 |
250 | lview->setUniformItemSizes(true); executed: lview->setUniformItemSizes(true); Execution Count:140 | 140 |
251 | setWritingSystem(QFontDatabase::Any); | - |
252 | | - |
253 | connect(this, "2""currentIndexChanged(QString)", | - |
254 | this, "1""_q_currentChanged(QString)"); | - |
255 | | - |
256 | connect((static_cast<QApplication *>(QCoreApplication::instance())), "2""fontDatabaseChanged()", | - |
257 | this, "1""_q_updateModel()"); | - |
258 | } executed: } Execution Count:140 | 140 |
259 | | - |
260 | | - |
261 | | - |
262 | | - |
263 | | - |
264 | QFontComboBox::~QFontComboBox() | - |
265 | { | - |
266 | } | - |
267 | void QFontComboBox::setWritingSystem(QFontDatabase::WritingSystem script) | - |
268 | { | - |
269 | QFontComboBoxPrivate * const d = d_func(); | - |
270 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); | - |
271 | if (delegate) partially evaluated: delegate yes Evaluation Count:178 | no Evaluation Count:0 |
| 0-178 |
272 | delegate->writingSystem = script; executed: delegate->writingSystem = script; Execution Count:178 | 178 |
273 | d->_q_updateModel(); | - |
274 | } executed: } Execution Count:178 | 178 |
275 | | - |
276 | QFontDatabase::WritingSystem QFontComboBox::writingSystem() const | - |
277 | { | - |
278 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); | - |
279 | if (delegate) partially evaluated: delegate yes Evaluation Count:38 | no Evaluation Count:0 |
| 0-38 |
280 | return delegate->writingSystem; executed: return delegate->writingSystem; Execution Count:38 | 38 |
281 | return QFontDatabase::Any; never executed: return QFontDatabase::Any; | 0 |
282 | } | - |
283 | void QFontComboBox::setFontFilters(FontFilters filters) | - |
284 | { | - |
285 | QFontComboBoxPrivate * const d = d_func(); | - |
286 | d->filters = filters; | - |
287 | d->_q_updateModel(); | - |
288 | } executed: } Execution Count:8 | 8 |
289 | | - |
290 | QFontComboBox::FontFilters QFontComboBox::fontFilters() const | - |
291 | { | - |
292 | const QFontComboBoxPrivate * const d = d_func(); | - |
293 | return d->filters; executed: return d->filters; Execution Count:8 | 8 |
294 | } | - |
295 | | - |
296 | | - |
297 | | - |
298 | | - |
299 | | - |
300 | | - |
301 | | - |
302 | QFont QFontComboBox::currentFont() const | - |
303 | { | - |
304 | const QFontComboBoxPrivate * const d = d_func(); | - |
305 | return d->currentFont; executed: return d->currentFont; Execution Count:577 | 577 |
306 | } | - |
307 | | - |
308 | void QFontComboBox::setCurrentFont(const QFont &font) | - |
309 | { | - |
310 | QFontComboBoxPrivate * const d = d_func(); | - |
311 | if (font != d->currentFont) { evaluated: font != d->currentFont yes Evaluation Count:94 | yes Evaluation Count:1 |
| 1-94 |
312 | d->currentFont = font; | - |
313 | d->_q_updateModel(); | - |
314 | if (d->currentFont == font) { evaluated: d->currentFont == font yes Evaluation Count:93 | yes Evaluation Count:1 |
| 1-93 |
315 | currentFontChanged(d->currentFont); | - |
316 | } executed: } Execution Count:93 | 93 |
317 | } executed: } Execution Count:94 | 94 |
318 | } executed: } Execution Count:95 | 95 |
319 | bool QFontComboBox::event(QEvent *e) | - |
320 | { | - |
321 | if (e->type() == QEvent::Resize) { partially evaluated: e->type() == QEvent::Resize no Evaluation Count:0 | yes Evaluation Count:1123 |
| 0-1123 |
322 | QListView *lview = qobject_cast<QListView*>(view()); | - |
323 | if (lview) | 0 |
324 | lview->window()->setFixedWidth(width() * 5 / 3); never executed: lview->window()->setFixedWidth(width() * 5 / 3); | 0 |
325 | } | 0 |
326 | return QComboBox::event(e); executed: return QComboBox::event(e); Execution Count:1123 | 1123 |
327 | } | - |
328 | | - |
329 | | - |
330 | | - |
331 | | - |
332 | QSize QFontComboBox::sizeHint() const | - |
333 | { | - |
334 | QSize sz = QComboBox::sizeHint(); | - |
335 | QFontMetrics fm(font()); | - |
336 | sz.setWidth(fm.width(QLatin1Char('m'))*14); | - |
337 | return sz; executed: return sz; Execution Count:142 | 142 |
338 | } | - |
339 | | - |
340 | | - |
341 | | - |
342 | | - |
| | |