behaviorsettings.cpp 4.04 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
3 4
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
7
**
hjk's avatar
hjk committed
8 9 10 11
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
12 13 14
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
15
**
16 17 18 19 20 21 22
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
con's avatar
con committed
23
**
hjk's avatar
hjk committed
24
****************************************************************************/
25 26 27

#include "behaviorsettings.h"

28 29
#include <utils/settingsutils.h>

30 31
#include <QSettings>
#include <QString>
32

33
static const char mouseHidingKey[] = "MouseHiding";
34 35
static const char mouseNavigationKey[] = "MouseNavigation";
static const char scrollWheelZoomingKey[] = "ScrollWheelZooming";
36
static const char constrainTooltips[] = "ConstrainTooltips";
37
static const char camelCaseNavigationKey[] = "CamelCaseNavigation";
38
static const char keyboardTooltips[] = "KeyboardTooltips";
39
static const char groupPostfix[] = "BehaviorSettings";
40 41 42 43

namespace TextEditor {

BehaviorSettings::BehaviorSettings() :
44
    m_mouseHiding(true),
45
    m_mouseNavigation(true),
46
    m_scrollWheelZooming(true),
47 48 49
    m_constrainHoverTooltips(false),
    m_camelCaseNavigation(true),
    m_keyboardTooltips(false)
50 51 52 53 54
{
}

void BehaviorSettings::toSettings(const QString &category, QSettings *s) const
{
55
    Utils::toSettings(QLatin1String(groupPostfix), category, s, this);
56 57 58 59
}

void BehaviorSettings::fromSettings(const QString &category, const QSettings *s)
{
60 61 62
    *this = BehaviorSettings();
    Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
63

64 65
void BehaviorSettings::toMap(const QString &prefix, QVariantMap *map) const
{
66
    map->insert(prefix + QLatin1String(mouseHidingKey), m_mouseHiding);
67 68
    map->insert(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation);
    map->insert(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming);
69
    map->insert(prefix + QLatin1String(constrainTooltips), m_constrainHoverTooltips);
70
    map->insert(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation);
71
    map->insert(prefix + QLatin1String(keyboardTooltips), m_keyboardTooltips);
72
}
73

74 75
void BehaviorSettings::fromMap(const QString &prefix, const QVariantMap &map)
{
76 77
    m_mouseHiding =
            map.value(prefix + QLatin1String(mouseHidingKey), m_mouseHiding).toBool();
78 79 80 81
    m_mouseNavigation =
        map.value(prefix + QLatin1String(mouseNavigationKey), m_mouseNavigation).toBool();
    m_scrollWheelZooming =
        map.value(prefix + QLatin1String(scrollWheelZoomingKey), m_scrollWheelZooming).toBool();
82 83
    m_constrainHoverTooltips =
        map.value(prefix + QLatin1String(constrainTooltips), m_constrainHoverTooltips).toBool();
84 85
    m_camelCaseNavigation =
        map.value(prefix + QLatin1String(camelCaseNavigationKey), m_camelCaseNavigation).toBool();
86 87
    m_keyboardTooltips =
        map.value(prefix + QLatin1String(keyboardTooltips), m_keyboardTooltips).toBool();
88 89 90 91
}

bool BehaviorSettings::equals(const BehaviorSettings &ds) const
{
92 93
    return m_mouseHiding == ds.m_mouseHiding
        && m_mouseNavigation == ds.m_mouseNavigation
94
        && m_scrollWheelZooming == ds.m_scrollWheelZooming
95
        && m_constrainHoverTooltips == ds.m_constrainHoverTooltips
96
        && m_camelCaseNavigation == ds.m_camelCaseNavigation
97
        && m_keyboardTooltips == ds.m_keyboardTooltips
98 99 100 101 102
        ;
}

} // namespace TextEditor