| 93 | } |
| 94 | |
| 95 | QVariant FontModel::data(const QModelIndex &index, int role) const |
| 96 | { |
| 97 | if (index.column() == 0) { |
| 98 | if (role == Qt::DisplayRole) |
| 99 | return m_fonts.at(index.row()).family(); |
| 100 | } else if (index.column() == 1) { |
| 101 | if (role == Qt::DisplayRole) |
| 102 | return m_fonts.at(index.row()).styleName(); |
| 103 | } else if (index.column() == 2) { |
| 104 | if (role == Qt::DecorationRole || role == Qt::SizeHintRole) { |
| 105 | const QFont &font = m_fonts.at(index.row()); |
| 106 | QFontMetrics metrics(font); |
| 107 | const QString text = m_text.isEmpty() ? tr("<no text>") : m_text; |
| 108 | const QRect rect = metrics.boundingRect(text.left(100)); |
| 109 | if (role == Qt::SizeHintRole) |
| 110 | return rect.size(); |
| 111 | QPixmap pixmap(rect.size()); |
| 112 | pixmap.fill(m_background); |
| 113 | QPainter painter(&pixmap); |
| 114 | painter.setPen(m_foreground); |
| 115 | painter.setFont(font); |
| 116 | painter.drawText(0, -rect.y(), text); |
| 117 | return pixmap; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | return QVariant(); |
| 122 | } |
| 123 | |
| 124 | void FontModel::setPointSize(int size) |
| 125 | { |
no test coverage detected