1/****************************************************************************
2**
3** Copyright (C) 2017 The Qt Company Ltd.
4** Contact: http://www.qt.io/licensing/
5**
6** This file is part of the Qt Quick Controls 2 module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL3$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPLv3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or later as published by the Free
28** Software Foundation and appearing in the file LICENSE.GPL included in
29** the packaging of this file. Please review the following information to
30** ensure the GNU General Public License version 2.0 requirements will be
31** met: http://www.gnu.org/licenses/gpl-2.0.html.
32**
33** $QT_END_LICENSE$
34**
35****************************************************************************/
36
37#include "qquickmaterialtheme_p.h"
38#include "qquickmaterialstyle_p.h"
39
40#include <QtGui/qpa/qplatformdialoghelper.h>
41#include <QtGui/qfont.h>
42#include <QtGui/qfontinfo.h>
43#include <QtQuickTemplates2/private/qquicktheme_p.h>
44
45QT_BEGIN_NAMESPACE
46
47void QQuickMaterialTheme::initialize(QQuickTheme *theme)
48{
49 QFont systemFont;
50 QFont buttonFont;
51 QFont toolTipFont;
52 QFont itemViewFont;
53 QFont listViewFont;
54 QFont menuItemFont;
55 QFont editorFont;
56
57 QFont font;
58 font.setFamily(QLatin1String("Roboto"));
59 QString family = QFontInfo(font).family();
60
61 if (family != QLatin1String("Roboto")) {
62 font.setFamily(QLatin1String("Noto"));
63 family = QFontInfo(font).family();
64 }
65
66 if (family == QLatin1String("Roboto") || family == QLatin1String("Noto")) {
67 systemFont.setFamily(family);
68 buttonFont.setFamily(family);
69 toolTipFont.setFamily(family);
70 itemViewFont.setFamily(family);
71 listViewFont.setFamily(family);
72 menuItemFont.setFamily(family);
73 editorFont.setFamily(family);
74 }
75
76 const bool dense = QQuickMaterialStyle::variant() == QQuickMaterialStyle::Dense;
77 systemFont.setPixelSize(dense ? 13 : 14);
78 theme->setFont(scope: QQuickTheme::System, font: systemFont);
79
80 // https://material.io/guidelines/components/buttons.html#buttons-style
81 buttonFont.setPixelSize(dense ? 13 : 14);
82 buttonFont.setCapitalization(QFont::AllUppercase);
83 buttonFont.setWeight(QFont::Medium);
84 theme->setFont(scope: QQuickTheme::Button, font: buttonFont);
85 theme->setFont(scope: QQuickTheme::TabBar, font: buttonFont);
86 theme->setFont(scope: QQuickTheme::ToolBar, font: buttonFont);
87
88 // https://material.io/guidelines/components/tooltips.html
89 toolTipFont.setPixelSize(dense ? 10 : 14);
90 toolTipFont.setWeight(QFont::Medium);
91 theme->setFont(scope: QQuickTheme::ToolTip, font: toolTipFont);
92
93 itemViewFont.setPixelSize(dense ? 13 : 14);
94 itemViewFont.setWeight(QFont::Medium);
95 theme->setFont(scope: QQuickTheme::ItemView, font: itemViewFont);
96
97 // https://material.io/guidelines/components/lists.html#lists-specs
98 listViewFont.setPixelSize(dense ? 13 : 16);
99 theme->setFont(scope: QQuickTheme::ListView, font: listViewFont);
100
101 menuItemFont.setPixelSize(dense ? 13 : 16);
102 theme->setFont(scope: QQuickTheme::Menu, font: menuItemFont);
103 theme->setFont(scope: QQuickTheme::MenuBar, font: menuItemFont);
104 theme->setFont(scope: QQuickTheme::ComboBox, font: menuItemFont);
105
106 editorFont.setPixelSize(dense ? 13 : 16);
107 theme->setFont(scope: QQuickTheme::TextArea, font: editorFont);
108 theme->setFont(scope: QQuickTheme::TextField, font: editorFont);
109 theme->setFont(scope: QQuickTheme::SpinBox, font: editorFont);
110}
111
112QT_END_NAMESPACE
113

source code of qtquickcontrols2/src/imports/controls/material/qquickmaterialtheme.cpp