summaryrefslogtreecommitdiffstats
path: root/tests/manual/qglyphruns/glyphruninspector.cpp
blob: 13a8df0181478d192e23fcf7824e37a8cb1ab1ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0

#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();
}