Debian Codegraph @

src/shared/lomiritheme.h

raw symbols SCIP
1 /*
2 * Copyright (C) 2016-2017 Canonical, Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License version 3, as published by
6 * the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
10 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17 #include <QVariant>
18 #include <QtThemeSupport/private/qgenericunixthemes_p.h>
19 #include <QGuiApplication>
20 #include <QScreen>
21
22 class LomiriTheme : public QGenericUnixTheme
23 {
24 public:
25 LomiriTheme()
26 : mSystemFont(QStringLiteral("Ubuntu Regular"), 10),
27 mFixedFont(QStringLiteral("Ubuntu Mono Regular"), 13)
28 {
29 mSystemFont.setStyleHint(QFont::System);
30 mFixedFont.setStyleHint(QFont::TypeWriter);
31 }
32 ~LomiriTheme() = default;
33
34 QVariant themeHint(ThemeHint hint) const override
35 {
36 switch (hint) {
37 case QPlatformTheme::SystemIconThemeName: {
38 QByteArray iconTheme = qgetenv("QTUBUNTU_ICON_THEME");
39 if (iconTheme.isEmpty()) {
40 return QStringLiteral("suru");
41 } else {
42 return iconTheme;
43 }
44 }
45 case QPlatformTheme::MouseDoubleClickDistance: {
46 // Impl mostly yoinked from the QAndroidPlatformTheme
47 QScreen *screen = qGuiApp->primaryScreen();
48 if (screen) {
49 qreal dotsPerInch = screen->physicalDotsPerInch();
50 // Allow 15% of an inch between taps when double clicking
51 return qRound(dotsPerInch * 0.15);
52 } else {
53 return 5;
54 }
55 }
56 case QPlatformTheme::TouchDoubleTapDistance: {
57 bool ok = false;
58 int dist = themeHint(QPlatformTheme::MouseDoubleClickDistance).toInt(&ok) * 2;
59 return QVariant(ok ? dist : 10);
60 }
61 default:
62 break;
63 }
64 return QGenericUnixTheme::themeHint(hint);
65 }
66
67 const QFont *font(Font type) const override
68 {
69 switch (type) {
70 case QPlatformTheme::SystemFont:
71 return &mSystemFont;
72 case QPlatformTheme::FixedFont:
73 return &mFixedFont;
74 default:
75 return nullptr;
76 }
77 }
78
79 private:
80 QFont mSystemFont, mFixedFont;
81 };