summaryrefslogtreecommitdiff
path: root/src/settings/helpers.hpp
blob: d7fcda4fc61d605b5fe93955532957ea6362aba9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/* ============================================================
 *     The rekonq project
 * ============================================================
 * SPDX-License-Identifier: GPL-3.0-only
 * Copyright (C) 2022 aqua <aqua@iserlohn-fortress.net>
 * ============================================================
 * Description: Settings helpers
 * ============================================================ */

#pragma once

#include <QFont>
#include <QFontDatabase>

[[nodiscard]] static QFont getFont(QFont::StyleHint hint)
{
  switch (hint) {
  case QFont::Helvetica: { // sans serif
    QFont font("sans serif");
    font.setStyleHint(hint);
    return font;
  }
  case QFont::Times: { // serif
    QFont font("serif");
    font.setStyleHint(hint);
    return font;
  }

  case QFont::Monospace:
  case QFont::Courier: { // typewriter
    auto font = QFontDatabase::systemFont(QFontDatabase::FixedFont);
    font.setStyleHint(hint);
    return font;
  }

  case QFont::OldEnglish: { // decorative
    auto font = QFont("decorative");
    font.setStyleHint(hint);
    return font;
  }

  case QFont::System:
  case QFont::AnyStyle:
    return QFontDatabase::systemFont(QFontDatabase::GeneralFont);

  case QFont::Cursive: {
    QFont font("cursive");
    font.setStyleHint(hint);
    return font;
  }

  case QFont::Fantasy: {
    QFont font("fantasy");
    font.setStyleHint(hint);
    return font;
  }
  }

  __builtin_unreachable();
}