behaviorsettings.cpp 4.36 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
2
**
Eike Ziller's avatar
Eike Ziller committed
3 4
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://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
Eike Ziller's avatar
Eike Ziller committed
12 13
** a written agreement between you and The Qt Company.  For licensing terms and
** conditions see http://www.qt.io/terms-conditions.  For further information
Eike Ziller's avatar
Eike Ziller committed
14
** use the contact form at http://www.qt.io/contact-us.
15 16
**
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
** Alternatively, this file may be used under the terms of the GNU Lesser
Eike Ziller's avatar
Eike Ziller committed
18 19 20 21 22 23
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
hjk's avatar
hjk committed
24
**
Eike Ziller's avatar
Eike Ziller committed
25 26
** In addition, as a special exception, The Qt Company gives you certain additional
** rights.  These rights are described in The Qt Company LGPL Exception
con's avatar
con committed
27 28
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
29
****************************************************************************/
30 31 32

#include "behaviorsettings.h"

33 34
#include <utils/settingsutils.h>

35 36
#include <QSettings>
#include <QString>
37

38
static const char mouseHidingKey[] = "MouseHiding";
39 40
static const char mouseNavigationKey[] = "MouseNavigation";
static const char scrollWheelZoomingKey[] = "ScrollWheelZooming";
41
static const char constrainTooltips[] = "ConstrainTooltips";
42
static const char camelCaseNavigationKey[] = "CamelCaseNavigation";
43
static const char keyboardTooltips[] = "KeyboardTooltips";
44
static const char groupPostfix[] = "BehaviorSettings";
45 46 47 48

namespace TextEditor {

BehaviorSettings::BehaviorSettings() :
49
    m_mouseHiding(true),
50
    m_mouseNavigation(true),
51
    m_scrollWheelZooming(true),
52 53 54
    m_constrainHoverTooltips(false),
    m_camelCaseNavigation(true),
    m_keyboardTooltips(false)
55 56 57 58 59
{
}

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

void BehaviorSettings::fromSettings(const QString &category, const QSettings *s)
{
65 66 67
    *this = BehaviorSettings();
    Utils::fromSettings(QLatin1String(groupPostfix), category, s, this);
}
68

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

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

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

} // namespace TextEditor