summaryrefslogtreecommitdiffstats
path: root/tests/manual/qglyphruns/glyphruninspector.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/manual/qglyphruns/glyphruninspector.cpp')
-rw-r--r--tests/manual/qglyphruns/glyphruninspector.cpp48
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/manual/qglyphruns/glyphruninspector.cpp b/tests/manual/qglyphruns/glyphruninspector.cpp
new file mode 100644
index 0000000000..0e35a1f94b
--- /dev/null
+++ b/tests/manual/qglyphruns/glyphruninspector.cpp
@@ -0,0 +1,48 @@
+// Copyright (C) 2022 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include "glyphruninspector.h"
+#include "singleglyphrun.h"
+
+#include <QTextLayout>
+#include <QtWidgets>
+
+GlyphRunInspector::GlyphRunInspector(QWidget *parent)
+ : QWidget{parent}
+{
+ QHBoxLayout *layout = new QHBoxLayout(this);
+
+ m_tabWidget = new QTabWidget;
+ layout->addWidget(m_tabWidget);
+
+ connect(m_tabWidget,
+ &QTabWidget::currentChanged,
+ this,
+ &GlyphRunInspector::updateVisualizationForTab);
+}
+
+void GlyphRunInspector::updateVisualizationForTab()
+{
+ int currentTab = m_tabWidget->currentIndex();
+ SingleGlyphRun *gr = currentTab >= 0 && currentTab < m_content.size() ? m_content.at(currentTab) : nullptr;
+ if (gr != nullptr)
+ emit updateBounds(gr->bounds());
+}
+
+void GlyphRunInspector::updateLayout(QTextLayout *layout, int start, int length)
+{
+ QList<QGlyphRun> glyphRuns = layout->glyphRuns(start, length, QTextLayout::RetrieveAll);
+
+ m_tabWidget->clear();
+ qDeleteAll(m_content);
+ m_content.clear();
+ for (int i = 0; i < glyphRuns.size(); ++i) {
+ SingleGlyphRun *w = new SingleGlyphRun(m_tabWidget);
+ w->updateGlyphRun(glyphRuns.at(i));
+
+ m_tabWidget->addTab(w, QStringLiteral("%1").arg(glyphRuns.at(i).rawFont().familyName()));
+ m_content.append(w);
+ }
+
+ updateVisualizationForTab();
+}