16 int index = metaObject()->indexOfEnumerator(
"UnicodeRange");
19 m_rangeEnum = metaObject()->enumerator(index);
21 m_workerThread.reset(
new QThread);
23 m_worker =
new DistanceFieldModelWorker;
24 m_worker->moveToThread(m_workerThread.data());
25 connect(m_workerThread.data(), &QThread::finished,
26 m_worker, &QObject::deleteLater);
28 connect(m_worker, &DistanceFieldModelWorker::fontLoaded,
29 this, &DistanceFieldModel::startGeneration);
30 connect(m_worker, &DistanceFieldModelWorker::fontLoaded,
31 this, &DistanceFieldModel::reserveSpace);
32 connect(m_worker, &DistanceFieldModelWorker::distanceFieldGenerated,
33 this, &DistanceFieldModel::addDistanceField);
34 connect(m_worker, &DistanceFieldModelWorker::fontGenerated,
35 this, &DistanceFieldModel::stopGeneration);
36 connect(m_worker, &DistanceFieldModelWorker::distanceFieldGenerated,
37 this, &DistanceFieldModel::distanceFieldGenerated);
38 connect(m_worker, &DistanceFieldModelWorker::error,
39 this, &DistanceFieldModel::error);
41 m_workerThread->start();
46 m_workerThread->quit();
47 m_workerThread->wait();
53 Q_UNUSED(orientation);
68 static QPixmap defaultImage;
69 if (defaultImage.isNull()) {
70 defaultImage = QPixmap(64, 64);
71 defaultImage.fill(Qt::white);
77 if (role == Qt::DecorationRole) {
78 if (index.row() < m_distanceFields.size()) {
79 return QPixmap::fromImage(m_distanceFields.at(index.row()).scaled(64, 64));
91 QMetaObject::invokeMethod(m_worker,
92 [
this, fileName] { m_worker->loadFont(fileName); },
93 Qt::QueuedConnection);
97 bool doubleResolution,
101 m_glyphsPerUnicodeRange.clear();
102 m_distanceFields.clear();
103 m_glyphCount = glyphCount;
105 m_distanceFields.reserve(glyphCount);
108 m_doubleGlyphResolution = doubleResolution;
109 m_pixelSize = pixelSize;
111 QMetaObject::invokeMethod(m_worker,
112 [
this] { m_worker->generateOneDistanceField(); },
113 Qt::QueuedConnection);
116DistanceFieldModel::UnicodeRange
DistanceFieldModel::unicodeRangeForUcs4(quint32 ucs4)
const
118 int index = metaObject()->indexOfEnumerator(
"UnicodeRange");
119 Q_ASSERT(index >= 0);
121 QMetaEnum range = metaObject()->enumerator(index);
122 for (
int i = 0; i < range.keyCount() - 1; ++i) {
123 int rangeStart = range.value(i);
124 int rangeEnd = range.value(i + 1);
125 if (quint32(rangeStart) <= ucs4 && quint32(rangeEnd) >= ucs4)
126 return UnicodeRange(rangeStart);
134 return m_glyphsPerUnicodeRange.uniqueKeys();
139 return m_glyphsPerUnicodeRange.values(range);
144 return QString::fromLatin1(m_rangeEnum.valueToKey(
int(range)));
148 const QPainterPath &path,
152 if (glyphId >= quint16(m_distanceFields.size()))
153 m_distanceFields.resize(glyphId + 1);
154 m_distanceFields[glyphId] = distanceField;
155 if (glyphId >= quint16(m_paths.size()))
156 m_paths.resize(glyphId + 1);
157 m_paths[glyphId] = path;
160 UnicodeRange range = unicodeRangeForUcs4(ucs4);
161 m_glyphsPerUnicodeRange.insert(range, glyphId);
162 m_glyphsPerUcs4.insert(ucs4, glyphId);
165 emit dataChanged(createIndex(glyphId, 0), createIndex(glyphId, 0));
167 QMetaObject::invokeMethod(m_worker,
168 [
this] { m_worker->generateOneDistanceField(); },
169 Qt::QueuedConnection);
174 return m_glyphsPerUcs4.value(ucs4);
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Returns the number of rows under the given parent.
void setFont(const QString &fileName)
QString nameForUnicodeRange(UnicodeRange range) const
~DistanceFieldModel() override
QList< glyph_t > glyphIndexesForUnicodeRange(UnicodeRange range) const
glyph_t glyphIndexForUcs4(quint32 ucs4) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Returns the data for the given role and section in the header with the specified orientation.
QList< UnicodeRange > unicodeRanges() const
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Returns the data stored under the given role for the item referred to by the index.
Combined button and popup list for selecting options.