| Line | Source Code | Coverage |
|---|
| 1 | /**************************************************************************** | - |
| 2 | ** | - |
| 3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
| 4 | ** Contact: http://www.qt-project.org/legal | - |
| 5 | ** | - |
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | - |
| 7 | ** | - |
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - |
| 9 | ** Commercial License Usage | - |
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - |
| 11 | ** accordance with the commercial license agreement provided with the | - |
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - |
| 13 | ** a written agreement between you and Digia. For licensing terms and | - |
| 14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
| 15 | ** use the contact form at http://qt.digia.com/contact-us. | - |
| 16 | ** | - |
| 17 | ** GNU Lesser General Public License Usage | - |
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - |
| 19 | ** General Public License version 2.1 as published by the Free Software | - |
| 20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
| 21 | ** packaging of this file. Please review the following information to | - |
| 22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
| 23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
| 24 | ** | - |
| 25 | ** In addition, as a special exception, Digia gives you certain additional | - |
| 26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
| 27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
| 28 | ** | - |
| 29 | ** GNU General Public License Usage | - |
| 30 | ** Alternatively, this file may be used under the terms of the GNU | - |
| 31 | ** General Public License version 3.0 as published by the Free Software | - |
| 32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
| 33 | ** packaging of this file. Please review the following information to | - |
| 34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
| 35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
| 36 | ** | - |
| 37 | ** | - |
| 38 | ** $QT_END_LICENSE$ | - |
| 39 | ** | - |
| 40 | ****************************************************************************/ | - |
| 41 | | - |
| 42 | #include "qfontcombobox.h" | - |
| 43 | | - |
| 44 | #ifndef QT_NO_FONTCOMBOBOX | - |
| 45 | | - |
| 46 | #include <qstringlistmodel.h> | - |
| 47 | #include <qitemdelegate.h> | - |
| 48 | #include <qlistview.h> | - |
| 49 | #include <qpainter.h> | - |
| 50 | #include <qevent.h> | - |
| 51 | #include <qapplication.h> | - |
| 52 | #include <private/qcombobox_p.h> | - |
| 53 | #include <qdebug.h> | - |
| 54 | | - |
| 55 | QT_BEGIN_NAMESPACE | - |
| 56 | | - |
| 57 | static QFontDatabase::WritingSystem writingSystemForFont(const QFont &font, bool *hasLatin) | - |
| 58 | { | - |
| 59 | *hasLatin = true; never executed (the execution status of this line is deduced): *hasLatin = true; | - |
| 60 | | - |
| 61 | QList<QFontDatabase::WritingSystem> writingSystems = QFontDatabase().writingSystems(font.family()); never executed (the execution status of this line is deduced): QList<QFontDatabase::WritingSystem> writingSystems = QFontDatabase().writingSystems(font.family()); | - |
| 62 | // qDebug() << font.family() << writingSystems; | - |
| 63 | | - |
| 64 | // this just confuses the algorithm below. Vietnamese is Latin with lots of special chars | - |
| 65 | writingSystems.removeAll(QFontDatabase::Vietnamese); never executed (the execution status of this line is deduced): writingSystems.removeAll(QFontDatabase::Vietnamese); | - |
| 66 | | - |
| 67 | QFontDatabase::WritingSystem system = QFontDatabase::Any; never executed (the execution status of this line is deduced): QFontDatabase::WritingSystem system = QFontDatabase::Any; | - |
| 68 | | - |
| 69 | if (!writingSystems.contains(QFontDatabase::Latin)) { never evaluated: !writingSystems.contains(QFontDatabase::Latin) | 0 |
| 70 | *hasLatin = false; never executed (the execution status of this line is deduced): *hasLatin = false; | - |
| 71 | // we need to show something | - |
| 72 | if (writingSystems.count()) never evaluated: writingSystems.count() | 0 |
| 73 | system = writingSystems.last(); never executed: system = writingSystems.last(); | 0 |
| 74 | } else { | 0 |
| 75 | writingSystems.removeAll(QFontDatabase::Latin); never executed (the execution status of this line is deduced): writingSystems.removeAll(QFontDatabase::Latin); | - |
| 76 | } | 0 |
| 77 | | - |
| 78 | if (writingSystems.isEmpty()) never evaluated: writingSystems.isEmpty() | 0 |
| 79 | return system; never executed: return system; | 0 |
| 80 | | - |
| 81 | if (writingSystems.count() == 1 && writingSystems.at(0) > QFontDatabase::Cyrillic) { never evaluated: writingSystems.count() == 1 never evaluated: writingSystems.at(0) > QFontDatabase::Cyrillic | 0 |
| 82 | system = writingSystems.at(0); never executed (the execution status of this line is deduced): system = writingSystems.at(0); | - |
| 83 | return system; never executed: return system; | 0 |
| 84 | } | - |
| 85 | | - |
| 86 | if (writingSystems.count() <= 2 never evaluated: writingSystems.count() <= 2 | 0 |
| 87 | && writingSystems.last() > QFontDatabase::Armenian never evaluated: writingSystems.last() > QFontDatabase::Armenian | 0 |
| 88 | && writingSystems.last() < QFontDatabase::Vietnamese) { never evaluated: writingSystems.last() < QFontDatabase::Vietnamese | 0 |
| 89 | system = writingSystems.last(); never executed (the execution status of this line is deduced): system = writingSystems.last(); | - |
| 90 | return system; never executed: return system; | 0 |
| 91 | } | - |
| 92 | | - |
| 93 | if (writingSystems.count() <= 5 never evaluated: writingSystems.count() <= 5 | 0 |
| 94 | && writingSystems.last() >= QFontDatabase::SimplifiedChinese never evaluated: writingSystems.last() >= QFontDatabase::SimplifiedChinese | 0 |
| 95 | && writingSystems.last() <= QFontDatabase::Korean) never evaluated: writingSystems.last() <= QFontDatabase::Korean | 0 |
| 96 | system = writingSystems.last(); never executed: system = writingSystems.last(); | 0 |
| 97 | | - |
| 98 | return system; never executed: return system; | 0 |
| 99 | } | - |
| 100 | | - |
| 101 | class QFontFamilyDelegate : public QAbstractItemDelegate | - |
| 102 | { | - |
| 103 | Q_OBJECT | - |
| 104 | public: | - |
| 105 | explicit QFontFamilyDelegate(QObject *parent); | - |
| 106 | | - |
| 107 | // painting | - |
| 108 | void paint(QPainter *painter, | - |
| 109 | const QStyleOptionViewItem &option, | - |
| 110 | const QModelIndex &index) const; | - |
| 111 | | - |
| 112 | QSize sizeHint(const QStyleOptionViewItem &option, | - |
| 113 | const QModelIndex &index) const; | - |
| 114 | | - |
| 115 | QIcon truetype; | - |
| 116 | QIcon bitmap; | - |
| 117 | QFontDatabase::WritingSystem writingSystem; | - |
| 118 | }; | - |
| 119 | | - |
| 120 | QFontFamilyDelegate::QFontFamilyDelegate(QObject *parent) | - |
| 121 | : QAbstractItemDelegate(parent) | - |
| 122 | { | - |
| 123 | truetype = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png")); executed (the execution status of this line is deduced): truetype = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fonttruetype-16.png")); | - |
| 124 | bitmap = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png")); executed (the execution status of this line is deduced): bitmap = QIcon(QLatin1String(":/qt-project.org/styles/commonstyle/images/fontbitmap-16.png")); | - |
| 125 | writingSystem = QFontDatabase::Any; executed (the execution status of this line is deduced): writingSystem = QFontDatabase::Any; | - |
| 126 | } executed: }Execution Count:140 | 140 |
| 127 | | - |
| 128 | void QFontFamilyDelegate::paint(QPainter *painter, | - |
| 129 | const QStyleOptionViewItem &option, | - |
| 130 | const QModelIndex &index) const | - |
| 131 | { | - |
| 132 | QString text = index.data(Qt::DisplayRole).toString(); never executed (the execution status of this line is deduced): QString text = index.data(Qt::DisplayRole).toString(); | - |
| 133 | QFont font(option.font); never executed (the execution status of this line is deduced): QFont font(option.font); | - |
| 134 | font.setPointSize(QFontInfo(font).pointSize() * 3 / 2); never executed (the execution status of this line is deduced): font.setPointSize(QFontInfo(font).pointSize() * 3 / 2); | - |
| 135 | QFont font2 = font; never executed (the execution status of this line is deduced): QFont font2 = font; | - |
| 136 | font2.setFamily(text); never executed (the execution status of this line is deduced): font2.setFamily(text); | - |
| 137 | | - |
| 138 | bool hasLatin; never executed (the execution status of this line is deduced): bool hasLatin; | - |
| 139 | QFontDatabase::WritingSystem system = writingSystemForFont(font2, &hasLatin); never executed (the execution status of this line is deduced): QFontDatabase::WritingSystem system = writingSystemForFont(font2, &hasLatin); | - |
| 140 | if (hasLatin) never evaluated: hasLatin | 0 |
| 141 | font = font2; never executed: font = font2; | 0 |
| 142 | | - |
| 143 | QRect r = option.rect; never executed (the execution status of this line is deduced): QRect r = option.rect; | - |
| 144 | | - |
| 145 | if (option.state & QStyle::State_Selected) { never evaluated: option.state & QStyle::State_Selected | 0 |
| 146 | painter->save(); never executed (the execution status of this line is deduced): painter->save(); | - |
| 147 | painter->setBrush(option.palette.highlight()); never executed (the execution status of this line is deduced): painter->setBrush(option.palette.highlight()); | - |
| 148 | painter->setPen(Qt::NoPen); never executed (the execution status of this line is deduced): painter->setPen(Qt::NoPen); | - |
| 149 | painter->drawRect(option.rect); never executed (the execution status of this line is deduced): painter->drawRect(option.rect); | - |
| 150 | painter->setPen(QPen(option.palette.highlightedText(), 0)); never executed (the execution status of this line is deduced): painter->setPen(QPen(option.palette.highlightedText(), 0)); | - |
| 151 | } | 0 |
| 152 | | - |
| 153 | const QIcon *icon = &bitmap; never executed (the execution status of this line is deduced): const QIcon *icon = &bitmap; | - |
| 154 | if (QFontDatabase().isSmoothlyScalable(text)) { never evaluated: QFontDatabase().isSmoothlyScalable(text) | 0 |
| 155 | icon = &truetype; never executed (the execution status of this line is deduced): icon = &truetype; | - |
| 156 | } | 0 |
| 157 | QSize actualSize = icon->actualSize(r.size()); never executed (the execution status of this line is deduced): QSize actualSize = icon->actualSize(r.size()); | - |
| 158 | | - |
| 159 | icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter); never executed (the execution status of this line is deduced): icon->paint(painter, r, Qt::AlignLeft|Qt::AlignVCenter); | - |
| 160 | if (option.direction == Qt::RightToLeft) never evaluated: option.direction == Qt::RightToLeft | 0 |
| 161 | r.setRight(r.right() - actualSize.width() - 4); never executed: r.setRight(r.right() - actualSize.width() - 4); | 0 |
| 162 | else | - |
| 163 | r.setLeft(r.left() + actualSize.width() + 4); never executed: r.setLeft(r.left() + actualSize.width() + 4); | 0 |
| 164 | | - |
| 165 | QFont old = painter->font(); never executed (the execution status of this line is deduced): QFont old = painter->font(); | - |
| 166 | painter->setFont(font); never executed (the execution status of this line is deduced): painter->setFont(font); | - |
| 167 | | - |
| 168 | // If the ascent of the font is larger than the height of the rect, | - |
| 169 | // we will clip the text, so it's better to align the tight bounding rect in this case | - |
| 170 | // This is specifically for fonts where the ascent is very large compared to | - |
| 171 | // the descent, like certain of the Stix family. | - |
| 172 | QFontMetricsF fontMetrics(font); never executed (the execution status of this line is deduced): QFontMetricsF fontMetrics(font); | - |
| 173 | if (fontMetrics.ascent() > r.height()) { never evaluated: fontMetrics.ascent() > r.height() | 0 |
| 174 | QRectF tbr = fontMetrics.tightBoundingRect(text); never executed (the execution status of this line is deduced): QRectF tbr = fontMetrics.tightBoundingRect(text); | - |
| 175 | painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text); never executed (the execution status of this line is deduced): painter->drawText(r.x(), r.y() + (r.height() + tbr.height()) / 2.0, text); | - |
| 176 | } else { | 0 |
| 177 | painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text); never executed (the execution status of this line is deduced): painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, text); | - |
| 178 | } | 0 |
| 179 | | - |
| 180 | if (writingSystem != QFontDatabase::Any) never evaluated: writingSystem != QFontDatabase::Any | 0 |
| 181 | system = writingSystem; never executed: system = writingSystem; | 0 |
| 182 | | - |
| 183 | if (system != QFontDatabase::Any) { never evaluated: system != QFontDatabase::Any | 0 |
| 184 | int w = painter->fontMetrics().width(text + QLatin1String(" ")); never executed (the execution status of this line is deduced): int w = painter->fontMetrics().width(text + QLatin1String(" ")); | - |
| 185 | painter->setFont(font2); never executed (the execution status of this line is deduced): painter->setFont(font2); | - |
| 186 | QString sample = QFontDatabase().writingSystemSample(system); never executed (the execution status of this line is deduced): QString sample = QFontDatabase().writingSystemSample(system); | - |
| 187 | if (option.direction == Qt::RightToLeft) never evaluated: option.direction == Qt::RightToLeft | 0 |
| 188 | r.setRight(r.right() - w); never executed: r.setRight(r.right() - w); | 0 |
| 189 | else | - |
| 190 | r.setLeft(r.left() + w); never executed: r.setLeft(r.left() + w); | 0 |
| 191 | painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, sample); never executed (the execution status of this line is deduced): painter->drawText(r, Qt::AlignVCenter|Qt::AlignLeading|Qt::TextSingleLine, sample); | - |
| 192 | } | 0 |
| 193 | painter->setFont(old); never executed (the execution status of this line is deduced): painter->setFont(old); | - |
| 194 | | - |
| 195 | if (option.state & QStyle::State_Selected) never evaluated: option.state & QStyle::State_Selected | 0 |
| 196 | painter->restore(); never executed: painter->restore(); | 0 |
| 197 | | - |
| 198 | } | 0 |
| 199 | | - |
| 200 | QSize QFontFamilyDelegate::sizeHint(const QStyleOptionViewItem &option, | - |
| 201 | const QModelIndex &index) const | - |
| 202 | { | - |
| 203 | QString text = index.data(Qt::DisplayRole).toString(); never executed (the execution status of this line is deduced): QString text = index.data(Qt::DisplayRole).toString(); | - |
| 204 | QFont font(option.font); never executed (the execution status of this line is deduced): QFont font(option.font); | - |
| 205 | // font.setFamily(text); | - |
| 206 | font.setPointSize(QFontInfo(font).pointSize() * 3/2); never executed (the execution status of this line is deduced): font.setPointSize(QFontInfo(font).pointSize() * 3/2); | - |
| 207 | QFontMetrics fontMetrics(font); never executed (the execution status of this line is deduced): QFontMetrics fontMetrics(font); | - |
| 208 | return QSize(fontMetrics.width(text), fontMetrics.height()); never executed: return QSize(fontMetrics.width(text), fontMetrics.height()); | 0 |
| 209 | } | - |
| 210 | | - |
| 211 | | - |
| 212 | class QFontComboBoxPrivate : public QComboBoxPrivate | - |
| 213 | { | - |
| 214 | public: | - |
| 215 | inline QFontComboBoxPrivate() { filters = QFontComboBox::AllFonts; } executed: }Execution Count:140 | 140 |
| 216 | | - |
| 217 | QFontComboBox::FontFilters filters; | - |
| 218 | QFont currentFont; | - |
| 219 | | - |
| 220 | void _q_updateModel(); | - |
| 221 | void _q_currentChanged(const QString &); | - |
| 222 | | - |
| 223 | Q_DECLARE_PUBLIC(QFontComboBox) | - |
| 224 | }; | - |
| 225 | | - |
| 226 | | - |
| 227 | void QFontComboBoxPrivate::_q_updateModel() | - |
| 228 | { | - |
| 229 | Q_Q(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBox * const q = q_func(); | - |
| 230 | const int scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts); executed (the execution status of this line is deduced): const int scalableMask = (QFontComboBox::ScalableFonts | QFontComboBox::NonScalableFonts); | - |
| 231 | const int spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts); executed (the execution status of this line is deduced): const int spacingMask = (QFontComboBox::ProportionalFonts | QFontComboBox::MonospacedFonts); | - |
| 232 | | - |
| 233 | QStringListModel *m = qobject_cast<QStringListModel *>(q->model()); executed (the execution status of this line is deduced): QStringListModel *m = qobject_cast<QStringListModel *>(q->model()); | - |
| 234 | if (!m) partially evaluated: !m| no Evaluation Count:0 | yes Evaluation Count:280 |
| 0-280 |
| 235 | return; | 0 |
| 236 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(q->view()->itemDelegate()); executed (the execution status of this line is deduced): QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(q->view()->itemDelegate()); | - |
| 237 | QFontDatabase::WritingSystem system = delegate ? delegate->writingSystem : QFontDatabase::Any; partially evaluated: delegate| yes Evaluation Count:280 | no Evaluation Count:0 |
| 0-280 |
| 238 | | - |
| 239 | QFontDatabase fdb; executed (the execution status of this line is deduced): QFontDatabase fdb; | - |
| 240 | QStringList list = fdb.families(system); executed (the execution status of this line is deduced): QStringList list = fdb.families(system); | - |
| 241 | QStringList result; executed (the execution status of this line is deduced): QStringList result; | - |
| 242 | | - |
| 243 | int offset = 0; executed (the execution status of this line is deduced): int offset = 0; | - |
| 244 | QFontInfo fi(currentFont); executed (the execution status of this line is deduced): QFontInfo fi(currentFont); | - |
| 245 | | - |
| 246 | for (int i = 0; i < list.size(); ++i) { evaluated: i < list.size()| yes Evaluation Count:22487 | yes Evaluation Count:280 |
| 280-22487 |
| 247 | 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 |
| 248 | 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 |
| 249 | continue; executed: continue;Execution Count:182 | 182 |
| 250 | } executed: }Execution Count:91 | 91 |
| 251 | 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 |
| 252 | 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 |
| 253 | continue; executed: continue;Execution Count:91 | 91 |
| 254 | } executed: }Execution Count:91 | 91 |
| 255 | result += list.at(i); executed (the execution status of this line is deduced): result += list.at(i); | - |
| 256 | 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 |
| 257 | offset = result.count() - 1; executed: offset = result.count() - 1;Execution Count:252 | 252 |
| 258 | } executed: }Execution Count:22214 | 22214 |
| 259 | list = result; executed (the execution status of this line is deduced): list = result; | - |
| 260 | | - |
| 261 | //we need to block the signals so that the model doesn't emit reset | - |
| 262 | //this prevents the current index from changing | - |
| 263 | //it will be updated just after this | - |
| 264 | ///TODO: we should finda way to avoid blocking signals and have a real update of the model | - |
| 265 | const bool old = m->blockSignals(true); executed (the execution status of this line is deduced): const bool old = m->blockSignals(true); | - |
| 266 | m->setStringList(list); executed (the execution status of this line is deduced): m->setStringList(list); | - |
| 267 | m->blockSignals(old); executed (the execution status of this line is deduced): m->blockSignals(old); | - |
| 268 | | - |
| 269 | if (list.isEmpty()) { evaluated: list.isEmpty()| yes Evaluation Count:23 | yes Evaluation Count:257 |
| 23-257 |
| 270 | if (currentFont != QFont()) { partially evaluated: currentFont != QFont()| no Evaluation Count:0 | yes Evaluation Count:23 |
| 0-23 |
| 271 | currentFont = QFont(); never executed (the execution status of this line is deduced): currentFont = QFont(); | - |
| 272 | emit q->currentFontChanged(currentFont); never executed (the execution status of this line is deduced): q->currentFontChanged(currentFont); | - |
| 273 | } | 0 |
| 274 | } else { executed: }Execution Count:23 | 23 |
| 275 | q->setCurrentIndex(offset); executed (the execution status of this line is deduced): q->setCurrentIndex(offset); | - |
| 276 | } executed: }Execution Count:257 | 257 |
| 277 | } | - |
| 278 | | - |
| 279 | | - |
| 280 | void QFontComboBoxPrivate::_q_currentChanged(const QString &text) | - |
| 281 | { | - |
| 282 | Q_Q(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBox * const q = q_func(); | - |
| 283 | if (currentFont.family() != text) { evaluated: currentFont.family() != text| yes Evaluation Count:24 | yes Evaluation Count:94 |
| 24-94 |
| 284 | currentFont.setFamily(text); executed (the execution status of this line is deduced): currentFont.setFamily(text); | - |
| 285 | emit q->currentFontChanged(currentFont); executed (the execution status of this line is deduced): q->currentFontChanged(currentFont); | - |
| 286 | } executed: }Execution Count:24 | 24 |
| 287 | } executed: }Execution Count:118 | 118 |
| 288 | | - |
| 289 | /*! | - |
| 290 | \class QFontComboBox | - |
| 291 | \brief The QFontComboBox widget is a combobox that lets the user | - |
| 292 | select a font family. | - |
| 293 | | - |
| 294 | \since 4.2 | - |
| 295 | \ingroup basicwidgets | - |
| 296 | \inmodule QtWidgets | - |
| 297 | | - |
| 298 | The combobox is populated with an alphabetized list of font | - |
| 299 | family names, such as Arial, Helvetica, and Times New Roman. | - |
| 300 | Family names are displayed using the actual font when possible. | - |
| 301 | For fonts such as Symbol, where the name is not representable in | - |
| 302 | the font itself, a sample of the font is displayed next to the | - |
| 303 | family name. | - |
| 304 | | - |
| 305 | QFontComboBox is often used in toolbars, in conjunction with a | - |
| 306 | QComboBox for controlling the font size and two \l{QToolButton}s | - |
| 307 | for bold and italic. | - |
| 308 | | - |
| 309 | When the user selects a new font, the currentFontChanged() signal | - |
| 310 | is emitted in addition to currentIndexChanged(). | - |
| 311 | | - |
| 312 | Call setWritingSystem() to tell QFontComboBox to show only fonts | - |
| 313 | that support a given writing system, and setFontFilters() to | - |
| 314 | filter out certain types of fonts as e.g. non scalable fonts or | - |
| 315 | monospaced fonts. | - |
| 316 | | - |
| 317 | \image windowsvista-fontcombobox.png Screenshot of QFontComboBox on Windows Vista | - |
| 318 | | - |
| 319 | \sa QComboBox, QFont, QFontInfo, QFontMetrics, QFontDatabase, {Character Map Example} | - |
| 320 | */ | - |
| 321 | | - |
| 322 | /*! | - |
| 323 | \fn void QFontComboBox::setWritingSystem(QFontDatabase::WritingSystem script) | - |
| 324 | */ | - |
| 325 | | - |
| 326 | /*! | - |
| 327 | \fn void QFontComboBox::setCurrentFont(const QFont &font); | - |
| 328 | */ | - |
| 329 | | - |
| 330 | /*! | - |
| 331 | Constructs a font combobox with the given \a parent. | - |
| 332 | */ | - |
| 333 | QFontComboBox::QFontComboBox(QWidget *parent) | - |
| 334 | : QComboBox(*new QFontComboBoxPrivate, parent) | - |
| 335 | { | - |
| 336 | Q_D(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBoxPrivate * const d = d_func(); | - |
| 337 | d->currentFont = font(); executed (the execution status of this line is deduced): d->currentFont = font(); | - |
| 338 | setEditable(true); executed (the execution status of this line is deduced): setEditable(true); | - |
| 339 | | - |
| 340 | QStringListModel *m = new QStringListModel(this); executed (the execution status of this line is deduced): QStringListModel *m = new QStringListModel(this); | - |
| 341 | setModel(m); executed (the execution status of this line is deduced): setModel(m); | - |
| 342 | setItemDelegate(new QFontFamilyDelegate(this)); executed (the execution status of this line is deduced): setItemDelegate(new QFontFamilyDelegate(this)); | - |
| 343 | QListView *lview = qobject_cast<QListView*>(view()); executed (the execution status of this line is deduced): QListView *lview = qobject_cast<QListView*>(view()); | - |
| 344 | if (lview) partially evaluated: lview| yes Evaluation Count:140 | no Evaluation Count:0 |
| 0-140 |
| 345 | lview->setUniformItemSizes(true); executed: lview->setUniformItemSizes(true);Execution Count:140 | 140 |
| 346 | setWritingSystem(QFontDatabase::Any); executed (the execution status of this line is deduced): setWritingSystem(QFontDatabase::Any); | - |
| 347 | | - |
| 348 | connect(this, SIGNAL(currentIndexChanged(QString)), executed (the execution status of this line is deduced): connect(this, "2""currentIndexChanged(QString)", | - |
| 349 | this, SLOT(_q_currentChanged(QString))); executed (the execution status of this line is deduced): this, "1""_q_currentChanged(QString)"); | - |
| 350 | | - |
| 351 | connect(qApp, SIGNAL(fontDatabaseChanged()), executed (the execution status of this line is deduced): connect((static_cast<QApplication *>(QCoreApplication::instance())), "2""fontDatabaseChanged()", | - |
| 352 | this, SLOT(_q_updateModel())); executed (the execution status of this line is deduced): this, "1""_q_updateModel()"); | - |
| 353 | } executed: }Execution Count:140 | 140 |
| 354 | | - |
| 355 | | - |
| 356 | /*! | - |
| 357 | Destroys the combobox. | - |
| 358 | */ | - |
| 359 | QFontComboBox::~QFontComboBox() | - |
| 360 | { | - |
| 361 | } | - |
| 362 | | - |
| 363 | /*! | - |
| 364 | \property QFontComboBox::writingSystem | - |
| 365 | \brief the writing system that serves as a filter for the combobox | - |
| 366 | | - |
| 367 | If \a script is QFontDatabase::Any (the default), all fonts are | - |
| 368 | listed. | - |
| 369 | | - |
| 370 | \sa fontFilters | - |
| 371 | */ | - |
| 372 | | - |
| 373 | void QFontComboBox::setWritingSystem(QFontDatabase::WritingSystem script) | - |
| 374 | { | - |
| 375 | Q_D(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBoxPrivate * const d = d_func(); | - |
| 376 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); executed (the execution status of this line is deduced): QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); | - |
| 377 | if (delegate) partially evaluated: delegate| yes Evaluation Count:178 | no Evaluation Count:0 |
| 0-178 |
| 378 | delegate->writingSystem = script; executed: delegate->writingSystem = script;Execution Count:178 | 178 |
| 379 | d->_q_updateModel(); executed (the execution status of this line is deduced): d->_q_updateModel(); | - |
| 380 | } executed: }Execution Count:178 | 178 |
| 381 | | - |
| 382 | QFontDatabase::WritingSystem QFontComboBox::writingSystem() const | - |
| 383 | { | - |
| 384 | QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); executed (the execution status of this line is deduced): QFontFamilyDelegate *delegate = qobject_cast<QFontFamilyDelegate *>(view()->itemDelegate()); | - |
| 385 | if (delegate) partially evaluated: delegate| yes Evaluation Count:38 | no Evaluation Count:0 |
| 0-38 |
| 386 | return delegate->writingSystem; executed: return delegate->writingSystem;Execution Count:38 | 38 |
| 387 | return QFontDatabase::Any; never executed: return QFontDatabase::Any; | 0 |
| 388 | } | - |
| 389 | | - |
| 390 | | - |
| 391 | /*! | - |
| 392 | \enum QFontComboBox::FontFilter | - |
| 393 | | - |
| 394 | This enum can be used to only show certain types of fonts in the font combo box. | - |
| 395 | | - |
| 396 | \value AllFonts Show all fonts | - |
| 397 | \value ScalableFonts Show scalable fonts | - |
| 398 | \value NonScalableFonts Show non scalable fonts | - |
| 399 | \value MonospacedFonts Show monospaced fonts | - |
| 400 | \value ProportionalFonts Show proportional fonts | - |
| 401 | */ | - |
| 402 | | - |
| 403 | /*! | - |
| 404 | \property QFontComboBox::fontFilters | - |
| 405 | \brief the filter for the combobox | - |
| 406 | | - |
| 407 | By default, all fonts are listed. | - |
| 408 | | - |
| 409 | \sa writingSystem | - |
| 410 | */ | - |
| 411 | void QFontComboBox::setFontFilters(FontFilters filters) | - |
| 412 | { | - |
| 413 | Q_D(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBoxPrivate * const d = d_func(); | - |
| 414 | d->filters = filters; executed (the execution status of this line is deduced): d->filters = filters; | - |
| 415 | d->_q_updateModel(); executed (the execution status of this line is deduced): d->_q_updateModel(); | - |
| 416 | } executed: }Execution Count:8 | 8 |
| 417 | | - |
| 418 | QFontComboBox::FontFilters QFontComboBox::fontFilters() const | - |
| 419 | { | - |
| 420 | Q_D(const QFontComboBox); executed (the execution status of this line is deduced): const QFontComboBoxPrivate * const d = d_func(); | - |
| 421 | return d->filters; executed: return d->filters;Execution Count:8 | 8 |
| 422 | } | - |
| 423 | | - |
| 424 | /*! | - |
| 425 | \property QFontComboBox::currentFont | - |
| 426 | \brief the currently selected font | - |
| 427 | | - |
| 428 | \sa currentIndex, currentText | - |
| 429 | */ | - |
| 430 | QFont QFontComboBox::currentFont() const | - |
| 431 | { | - |
| 432 | Q_D(const QFontComboBox); executed (the execution status of this line is deduced): const QFontComboBoxPrivate * const d = d_func(); | - |
| 433 | return d->currentFont; executed: return d->currentFont;Execution Count:577 | 577 |
| 434 | } | - |
| 435 | | - |
| 436 | void QFontComboBox::setCurrentFont(const QFont &font) | - |
| 437 | { | - |
| 438 | Q_D(QFontComboBox); executed (the execution status of this line is deduced): QFontComboBoxPrivate * const d = d_func(); | - |
| 439 | if (font != d->currentFont) { evaluated: font != d->currentFont| yes Evaluation Count:94 | yes Evaluation Count:1 |
| 1-94 |
| 440 | d->currentFont = font; executed (the execution status of this line is deduced): d->currentFont = font; | - |
| 441 | d->_q_updateModel(); executed (the execution status of this line is deduced): d->_q_updateModel(); | - |
| 442 | if (d->currentFont == font) { //else the signal has already be emitted by _q_updateModel evaluated: d->currentFont == font| yes Evaluation Count:93 | yes Evaluation Count:1 |
| 1-93 |
| 443 | emit currentFontChanged(d->currentFont); executed (the execution status of this line is deduced): currentFontChanged(d->currentFont); | - |
| 444 | } executed: }Execution Count:93 | 93 |
| 445 | } executed: }Execution Count:94 | 94 |
| 446 | } executed: }Execution Count:95 | 95 |
| 447 | | - |
| 448 | /*! | - |
| 449 | \fn QFontComboBox::currentFontChanged(const QFont &font) | - |
| 450 | | - |
| 451 | This signal is emitted whenever the current font changes, with | - |
| 452 | the new \a font. | - |
| 453 | | - |
| 454 | \sa currentFont | - |
| 455 | */ | - |
| 456 | | - |
| 457 | /*! | - |
| 458 | \reimp | - |
| 459 | */ | - |
| 460 | bool QFontComboBox::event(QEvent *e) | - |
| 461 | { | - |
| 462 | if (e->type() == QEvent::Resize) { partially evaluated: e->type() == QEvent::Resize| no Evaluation Count:0 | yes Evaluation Count:1123 |
| 0-1123 |
| 463 | QListView *lview = qobject_cast<QListView*>(view()); never executed (the execution status of this line is deduced): QListView *lview = qobject_cast<QListView*>(view()); | - |
| 464 | if (lview) | 0 |
| 465 | lview->window()->setFixedWidth(width() * 5 / 3); never executed: lview->window()->setFixedWidth(width() * 5 / 3); | 0 |
| 466 | } | 0 |
| 467 | return QComboBox::event(e); executed: return QComboBox::event(e);Execution Count:1123 | 1123 |
| 468 | } | - |
| 469 | | - |
| 470 | /*! | - |
| 471 | \reimp | - |
| 472 | */ | - |
| 473 | QSize QFontComboBox::sizeHint() const | - |
| 474 | { | - |
| 475 | QSize sz = QComboBox::sizeHint(); executed (the execution status of this line is deduced): QSize sz = QComboBox::sizeHint(); | - |
| 476 | QFontMetrics fm(font()); executed (the execution status of this line is deduced): QFontMetrics fm(font()); | - |
| 477 | sz.setWidth(fm.width(QLatin1Char('m'))*14); executed (the execution status of this line is deduced): sz.setWidth(fm.width(QLatin1Char('m'))*14); | - |
| 478 | return sz; executed: return sz;Execution Count:142 | 142 |
| 479 | } | - |
| 480 | | - |
| 481 | QT_END_NAMESPACE | - |
| 482 | | - |
| 483 | #include "qfontcombobox.moc" | - |
| 484 | #include "moc_qfontcombobox.cpp" | - |
| 485 | | - |
| 486 | #endif // QT_NO_FONTCOMBOBOX | - |
| 487 | | - |
| | |