~openmw/openmw/openmw-packaging2

« back to all changes in this revision

Viewing changes to apps/opencs/model/prefs/shortcut.cpp

  • Committer: Scott Howard
  • Date: 2016-09-15 20:56:29 UTC
  • Revision ID: showard@debian.org-20160915205629-3tvfxe47zrb41a91
Cron update. Git hash: 37278b5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "shortcut.hpp"
 
2
 
 
3
#include <cassert>
 
4
 
 
5
#include <QAction>
 
6
#include <QWidget>
 
7
 
 
8
#include "state.hpp"
 
9
#include "shortcutmanager.hpp"
 
10
 
 
11
namespace CSMPrefs
 
12
{
 
13
    Shortcut::Shortcut(const std::string& name, QWidget* parent)
 
14
        : QObject(parent)
 
15
        , mEnabled(true)
 
16
        , mName(name)
 
17
        , mModName("")
 
18
        , mSecondaryMode(SM_Ignore)
 
19
        , mModifier(0)
 
20
        , mCurrentPos(0)
 
21
        , mLastPos(0)
 
22
        , mActivationStatus(AS_Inactive)
 
23
        , mModifierStatus(false)
 
24
        , mAction(0)
 
25
    {
 
26
        assert (parent);
 
27
 
 
28
        State::get().getShortcutManager().addShortcut(this);
 
29
        State::get().getShortcutManager().getSequence(name, mSequence);
 
30
    }
 
31
 
 
32
    Shortcut::Shortcut(const std::string& name, const std::string& modName, QWidget* parent)
 
33
        : QObject(parent)
 
34
        , mEnabled(true)
 
35
        , mName(name)
 
36
        , mModName(modName)
 
37
        , mSecondaryMode(SM_Ignore)
 
38
        , mModifier(0)
 
39
        , mCurrentPos(0)
 
40
        , mLastPos(0)
 
41
        , mActivationStatus(AS_Inactive)
 
42
        , mModifierStatus(false)
 
43
        , mAction(0)
 
44
    {
 
45
        assert (parent);
 
46
 
 
47
        State::get().getShortcutManager().addShortcut(this);
 
48
        State::get().getShortcutManager().getSequence(name, mSequence);
 
49
        State::get().getShortcutManager().getModifier(modName, mModifier);
 
50
    }
 
51
 
 
52
    Shortcut::Shortcut(const std::string& name, const std::string& modName, SecondaryMode secMode, QWidget* parent)
 
53
        : QObject(parent)
 
54
        , mEnabled(true)
 
55
        , mName(name)
 
56
        , mModName(modName)
 
57
        , mSecondaryMode(secMode)
 
58
        , mModifier(0)
 
59
        , mCurrentPos(0)
 
60
        , mLastPos(0)
 
61
        , mActivationStatus(AS_Inactive)
 
62
        , mModifierStatus(false)
 
63
        , mAction(0)
 
64
    {
 
65
        assert (parent);
 
66
 
 
67
        State::get().getShortcutManager().addShortcut(this);
 
68
        State::get().getShortcutManager().getSequence(name, mSequence);
 
69
        State::get().getShortcutManager().getModifier(modName, mModifier);
 
70
    }
 
71
 
 
72
    Shortcut::~Shortcut()
 
73
    {
 
74
        State::get().getShortcutManager().removeShortcut(this);
 
75
    }
 
76
 
 
77
    bool Shortcut::isEnabled() const
 
78
    {
 
79
        return mEnabled;
 
80
    }
 
81
 
 
82
    const std::string& Shortcut::getName() const
 
83
    {
 
84
        return mName;
 
85
    }
 
86
 
 
87
    const std::string& Shortcut::getModifierName() const
 
88
    {
 
89
        return mModName;
 
90
    }
 
91
 
 
92
    Shortcut::SecondaryMode Shortcut::getSecondaryMode() const
 
93
    {
 
94
        return mSecondaryMode;
 
95
    }
 
96
 
 
97
    const QKeySequence& Shortcut::getSequence() const
 
98
    {
 
99
        return mSequence;
 
100
    }
 
101
 
 
102
    int Shortcut::getModifier() const
 
103
    {
 
104
        return mModifier;
 
105
    }
 
106
 
 
107
    int Shortcut::getPosition() const
 
108
    {
 
109
        return mCurrentPos;
 
110
    }
 
111
 
 
112
    int Shortcut::getLastPosition() const
 
113
    {
 
114
        return mLastPos;
 
115
    }
 
116
 
 
117
    Shortcut::ActivationStatus Shortcut::getActivationStatus() const
 
118
    {
 
119
        return mActivationStatus;
 
120
    }
 
121
 
 
122
    bool Shortcut::getModifierStatus() const
 
123
    {
 
124
        return mModifierStatus;
 
125
    }
 
126
 
 
127
    void Shortcut::enable(bool state)
 
128
    {
 
129
        mEnabled = state;
 
130
    }
 
131
 
 
132
    void Shortcut::setSequence(const QKeySequence& sequence)
 
133
    {
 
134
        mSequence = sequence;
 
135
        mCurrentPos = 0;
 
136
        mLastPos = sequence.count() - 1;
 
137
 
 
138
        if (mAction)
 
139
        {
 
140
            mAction->setText(mActionText + "\t" + State::get().getShortcutManager().convertToString(mSequence).data());
 
141
        }
 
142
    }
 
143
 
 
144
    void Shortcut::setModifier(int modifier)
 
145
    {
 
146
        mModifier = modifier;
 
147
    }
 
148
 
 
149
    void Shortcut::setPosition(int pos)
 
150
    {
 
151
        mCurrentPos = pos;
 
152
    }
 
153
 
 
154
    void Shortcut::setActivationStatus(ActivationStatus status)
 
155
    {
 
156
        mActivationStatus = status;
 
157
    }
 
158
 
 
159
    void Shortcut::setModifierStatus(bool status)
 
160
    {
 
161
        mModifierStatus = status;
 
162
    }
 
163
 
 
164
    void Shortcut::associateAction(QAction* action)
 
165
    {
 
166
        if (mAction)
 
167
        {
 
168
            mAction->setText(mActionText);
 
169
 
 
170
            disconnect(this, SIGNAL(activated()), mAction, SLOT(trigger()));
 
171
            disconnect(mAction, SIGNAL(destroyed()), this, SLOT(actionDeleted()));
 
172
        }
 
173
 
 
174
        mAction = action;
 
175
 
 
176
        if (mAction)
 
177
        {
 
178
            mActionText = mAction->text();
 
179
            mAction->setText(mActionText + "\t" + State::get().getShortcutManager().convertToString(mSequence).data());
 
180
 
 
181
            connect(this, SIGNAL(activated()), mAction, SLOT(trigger()));
 
182
            connect(mAction, SIGNAL(destroyed()), this, SLOT(actionDeleted()));
 
183
        }
 
184
    }
 
185
 
 
186
    void Shortcut::signalActivated(bool state)
 
187
    {
 
188
        emit activated(state);
 
189
    }
 
190
 
 
191
    void Shortcut::signalActivated()
 
192
    {
 
193
        emit activated();
 
194
    }
 
195
 
 
196
    void Shortcut::signalSecondary(bool state)
 
197
    {
 
198
        emit secondary(state);
 
199
    }
 
200
    void Shortcut::signalSecondary()
 
201
    {
 
202
        emit secondary();
 
203
    }
 
204
 
 
205
    QString Shortcut::toString() const
 
206
    {
 
207
        return QString(State::get().getShortcutManager().convertToString(mSequence, mModifier).data());
 
208
    }
 
209
 
 
210
    void Shortcut::actionDeleted()
 
211
    {
 
212
        mAction = 0;
 
213
    }
 
214
}