00001
00025
00026 #include <qkeysequence.h>
00027
00028
00029 #include "action.h"
00030
00041 Action::Action(const QString &description, const QString &keys)
00042 : m_description(description),
00043 m_keys(QStringList::split(", ", QString(QKeySequence(keys))))
00044 {
00045 }
00046
00053 bool Action::HasKey(const QString &key) const
00054 {
00055 for (size_t i = 0; i < GetKeys().count(); i++)
00056 {
00057 if (GetKeys()[i] == key)
00058 return true;
00059 }
00060
00061 return false;
00062 }
00063
00075 bool Action::AddKey(const QString &key)
00076 {
00077 if (key.isEmpty() ||
00078 (GetKeys().size() >= kMaximumNumberOfBindings) ||
00079 (GetKeys().contains(key)))
00080 {
00081 return false;
00082 }
00083
00084 m_keys.push_back(key);
00085 return true;
00086 }
00087
00093 bool Action::ReplaceKey(const QString &newkey, const QString &oldkey)
00094 {
00095
00096 if (GetKeys().contains(newkey) != 0)
00097 return false;
00098
00099 for (size_t i = 0; i < GetKeys().size(); i++)
00100 {
00101 if (GetKeys()[i] == oldkey)
00102 {
00103 m_keys[i] = newkey;
00104 return true;
00105 }
00106 }
00107
00108 return false;
00109 }