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" },
|
|
|
|
|
{ StyleHelper::UiElementCaptionStrong, "Caption strong" },
|
|
|
|
|
{ StyleHelper::UiElementCaption, "Caption" },
|
|
|
|
|
};
|
|
|
|
|
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());
|
|
|
|
|
fontLabels.addItems({uiElementLabel, sampleLabel, st, font.toString(), 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>");
|
|
|
|
|
|
2023-12-06 20:29:27 +01:00
|
|
|
Column {
|
|
|
|
|
windowTitle("Utils::StyleHelper::uiFont"),
|
|
|
|
|
Group {
|
|
|
|
|
title("As QFont in QLabel"),
|
|
|
|
|
fontLabels,
|
|
|
|
|
},
|
2023-12-07 17:05:47 +01:00
|
|
|
Group {
|
|
|
|
|
title("As inline CSS in HTML elements"),
|
|
|
|
|
Row { html },
|
|
|
|
|
},
|
|
|
|
|
st,
|
2023-12-06 20:29:27 +01:00
|
|
|
}.emerge()->show();
|
|
|
|
|
|
|
|
|
|
return app.exec();
|
|
|
|
|
}
|