2023-12-06 20:29:27 +01:00
|
|
|
// 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 <utils/layoutbuilder.h>
|
|
|
|
|
#include <utils/stylehelper.h>
|
|
|
|
|
|
|
|
|
|
#include <QApplication>
|
|
|
|
|
#include <QLabel>
|
|
|
|
|
#include <QWidget>
|
|
|
|
|
|
|
|
|
|
using namespace Utils;
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
|
{
|
|
|
|
|
QApplication app(argc, argv);
|
|
|
|
|
|
|
|
|
|
static const struct {
|
|
|
|
|
StyleHelper::UiElement uiElement;
|
|
|
|
|
const QString name;
|
|
|
|
|
} uiElements[] = {
|
|
|
|
|
{ StyleHelper::UiElementH1, "H1" },
|
|
|
|
|
{ StyleHelper::UiElementH2, "H2" },
|
|
|
|
|
{ StyleHelper::UiElementH3, "H3" },
|
|
|
|
|
{ StyleHelper::UiElementH4, "H4" },
|
2023-11-13 16:35:01 +01:00
|
|
|
{ StyleHelper::UiElementH5, "H5" },
|
|
|
|
|
{ StyleHelper::UiElementH6, "H6" },
|
|
|
|
|
{ StyleHelper::UiElementH6Capital, "H6 CAPITAL" },
|
2024-02-12 17:19:41 +01:00
|
|
|
{ StyleHelper::UiElementBody1, "Body-01" },
|
|
|
|
|
{ StyleHelper::UiElementBody2, "Body-02" },
|
|
|
|
|
{ StyleHelper::UiElementButtonMedium, "Button Medium" },
|
|
|
|
|
{ StyleHelper::UiElementButtonSmall, "Button Small" },
|
2024-06-05 13:50:19 +02:00
|
|
|
{ StyleHelper::UiElementLabelMedium, "Label Medium" },
|
|
|
|
|
{ StyleHelper::UiElementLabelSmall, "Label Small" },
|
2023-12-06 20:29:27 +01:00
|
|
|
{ StyleHelper::UiElementCaptionStrong, "Caption strong" },
|
|
|
|
|
{ StyleHelper::UiElementCaption, "Caption" },
|
2024-02-12 17:19:41 +01:00
|
|
|
{ StyleHelper::UiElementIconStandard, "Icon Standard" },
|
|
|
|
|
{ StyleHelper::UiElementIconActive, "Icon Active" },
|
2023-12-06 20:29:27 +01:00
|
|
|
};
|
|
|
|
|
static const QString textSample("AaBbCcXxYyZz123");
|
|
|
|
|
|
|
|
|
|
using namespace Layouting;
|
2023-12-07 17:05:47 +01:00
|
|
|
Grid fontLabels;
|
2023-12-06 20:29:27 +01:00
|
|
|
for (auto uiElement : uiElements) {
|
|
|
|
|
const QFont font = StyleHelper::uiFont(uiElement.uiElement);
|
|
|
|
|
auto *uiElementLabel = new QLabel(uiElement.name);
|
|
|
|
|
uiElementLabel->setFont(font);
|
2023-12-07 17:05:47 +01:00
|
|
|
uiElementLabel->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Preferred);
|
2023-12-06 20:29:27 +01:00
|
|
|
auto *sampleLabel = new QLabel(textSample);
|
|
|
|
|
sampleLabel->setFont(font);
|
2023-12-07 17:05:47 +01:00
|
|
|
sampleLabel->setSizePolicy(uiElementLabel->sizePolicy());
|
2024-01-28 23:35:15 +01:00
|
|
|
QFontInfo fontInfo(font);
|
2024-01-28 23:39:17 +01:00
|
|
|
const QString pixelMetrics = QString::fromLatin1("Pixel size: %1, line height: %2")
|
|
|
|
|
.arg(fontInfo.pixelSize())
|
|
|
|
|
.arg(StyleHelper::uiFontLineHeight(uiElement.uiElement));
|
2024-01-28 23:35:15 +01:00
|
|
|
auto *metricsLabel = new QLabel(pixelMetrics);
|
|
|
|
|
fontLabels.addItems({uiElementLabel, sampleLabel, st, font.toString(), metricsLabel, br});
|
2023-12-06 20:29:27 +01:00
|
|
|
}
|
|
|
|
|
|
2023-12-07 17:05:47 +01:00
|
|
|
QString html("<html><body><table>");
|
|
|
|
|
for (auto uiElement : uiElements) {
|
|
|
|
|
const QFont font = StyleHelper::uiFont(uiElement.uiElement);
|
|
|
|
|
html.append(QString(R"(
|
|
|
|
|
<tr>
|
|
|
|
|
<td style="%1">%2</td>
|
|
|
|
|
<td style="%1">%3</td>
|
|
|
|
|
<td>%1</td>
|
|
|
|
|
</tr>
|
|
|
|
|
)").arg(StyleHelper::fontToCssProperties(font)).arg(uiElement.name).arg(textSample));
|
|
|
|
|
}
|
|
|
|
|
html.append("</table></body></html>");
|
|
|
|
|
|
2024-05-14 10:33:01 +02:00
|
|
|
Widget {
|
|
|
|
|
windowTitle(QString("Utils::StyleHelper::uiFont")),
|
|
|
|
|
Column {
|
|
|
|
|
Group {
|
|
|
|
|
title(QString("As QFont in QLabel")),
|
|
|
|
|
fontLabels,
|
|
|
|
|
},
|
|
|
|
|
Group {
|
|
|
|
|
title(QString("As inline CSS in HTML elements")),
|
|
|
|
|
Row { html },
|
|
|
|
|
},
|
|
|
|
|
st,
|
|
|
|
|
}
|
|
|
|
|
}.show();
|
2023-12-06 20:29:27 +01:00
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|