behaviorsettings.cpp 4.44 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
static const char smartSelectionChanging[] = "SmartSelectionChanging";
41 42 43 44

namespace TextEditor {

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

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

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

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

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

bool BehaviorSettings::equals(const BehaviorSettings &ds) const
{
98 99
    return m_mouseHiding == ds.m_mouseHiding
        && m_mouseNavigation == ds.m_mouseNavigation
100
        && m_scrollWheelZooming == ds.m_scrollWheelZooming
101
        && m_constrainHoverTooltips == ds.m_constrainHoverTooltips
102
        && m_camelCaseNavigation == ds.m_camelCaseNavigation
103
        && m_keyboardTooltips == ds.m_keyboardTooltips
104
        && m_smartSelectionChanging == ds.m_smartSelectionChanging
105 106 107 108 109
        ;
}

} // namespace TextEditor