aboutsummaryrefslogtreecommitdiff
path: root/lib/configuration/qt_specialization.cpp
blob: 8487e628dca2710343b7f41a0ac31ca48f27cfcd (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
#include "configuration.h"
#include <stdexcept>

template <>
callable_when(unconsumed) [[nodiscard]] std::optional<QString> Configuration::value(const char *path) const
{
    const auto v = value<std::string>(path);
    return v ? std::make_optional(QString::fromStdString(v.value())) : std::nullopt;
}

template <>
callable_when(unconsumed) [[nodiscard]] std::optional<QStringList> Configuration::value(const char *path) const
{
    const auto v = value<std::string>(path);
    return v ? std::make_optional(QString::fromStdString(v.value()).split(';')) : std::nullopt;
}

template <>
callable_when(unconsumed) QAction &Configuration::shortcut(QAction &action, const char *name) const
{
    if(const auto shortcut = value<QString>(name)) {
        const QString old_tooltip = action.toolTip();
        action.setShortcut(QKeySequence::fromString(shortcut.value()));
        action.setToolTip(QString("%1 (%2)").arg(old_tooltip, shortcut.value()));
    }
    return action;
}

template <>
callable_when(unconsumed) QKeySequence &Configuration::shortcut(QKeySequence &sequence, const char *name) const
{
    if(const auto shortcut = value<QString>(name)) {
        sequence = QKeySequence::fromString(shortcut.value());
    }
    return sequence;
}