1// Copyright (C) 2017 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qquickmaterialtheme_p.h"
5#include "qquickmaterialstyle_p.h"
6
7#include <QtGui/qpa/qplatformdialoghelper.h>
8#include <QtGui/qfont.h>
9#include <QtGui/qfontinfo.h>
10#include <QtQuickTemplates2/private/qquicktheme_p.h>
11
12QT_BEGIN_NAMESPACE
13
14void QQuickMaterialTheme::initialize(QQuickTheme *theme)
15{
16 QFont systemFont;
17 QFont buttonFont;
18 QFont toolTipFont;
19 QFont itemViewFont;
20 QFont listViewFont;
21 QFont menuItemFont;
22 QFont editorFont;
23
24 QFont font;
25 font.setFamilies(QStringList{QLatin1String("Roboto")});
26 QString family = QFontInfo(font).family();
27
28 if (family != QLatin1String("Roboto")) {
29 font.setFamilies(QStringList{QLatin1String("Noto")});
30 family = QFontInfo(font).family();
31 }
32
33 if (family == QLatin1String("Roboto") || family == QLatin1String("Noto")) {
34 const QStringList families{family};
35 systemFont.setFamilies(families);
36 buttonFont.setFamilies(families);
37 toolTipFont.setFamilies(families);
38 itemViewFont.setFamilies(families);
39 listViewFont.setFamilies(families);
40 menuItemFont.setFamilies(families);
41 editorFont.setFamilies(families);
42 }
43
44 const bool dense = QQuickMaterialStyle::variant() == QQuickMaterialStyle::Dense;
45 systemFont.setPixelSize(dense ? 13 : 14);
46 theme->setFont(scope: QQuickTheme::System, font: systemFont);
47
48 // https://material.io/guidelines/components/buttons.html#buttons-style
49 buttonFont.setPixelSize(dense ? 13 : 14);
50 buttonFont.setWeight(QFont::Medium);
51 theme->setFont(scope: QQuickTheme::Button, font: buttonFont);
52 theme->setFont(scope: QQuickTheme::TabBar, font: buttonFont);
53 theme->setFont(scope: QQuickTheme::ToolBar, font: buttonFont);
54
55 // https://material.io/guidelines/components/tooltips.html
56 toolTipFont.setPixelSize(dense ? 10 : 14);
57 toolTipFont.setWeight(QFont::Medium);
58 theme->setFont(scope: QQuickTheme::ToolTip, font: toolTipFont);
59
60 itemViewFont.setPixelSize(dense ? 13 : 14);
61 itemViewFont.setWeight(QFont::Medium);
62 theme->setFont(scope: QQuickTheme::ItemView, font: itemViewFont);
63
64 // https://material.io/guidelines/components/lists.html#lists-specs
65 listViewFont.setPixelSize(dense ? 13 : 16);
66 theme->setFont(scope: QQuickTheme::ListView, font: listViewFont);
67
68 menuItemFont.setPixelSize(dense ? 13 : 16);
69 theme->setFont(scope: QQuickTheme::Menu, font: menuItemFont);
70 theme->setFont(scope: QQuickTheme::MenuBar, font: menuItemFont);
71 theme->setFont(scope: QQuickTheme::ComboBox, font: menuItemFont);
72
73 editorFont.setPixelSize(dense ? 13 : 16);
74 theme->setFont(scope: QQuickTheme::TextArea, font: editorFont);
75 theme->setFont(scope: QQuickTheme::TextField, font: editorFont);
76 theme->setFont(scope: QQuickTheme::SpinBox, font: editorFont);
77}
78
79QT_END_NAMESPACE
80

source code of qtdeclarative/src/quickcontrols/material/qquickmaterialtheme.cpp