refs #453 Refactor Input value classes

All previous Hardware classes have been refactored and moved into
the Input namespace.
This commit is contained in:
Roland Winklmeier
2015-08-14 19:35:13 +02:00
committed by Mathew Sutcliffe
parent 41e17aa0c7
commit 63c7c6be0d
22 changed files with 1388 additions and 9 deletions

View File

@@ -33,6 +33,7 @@ HEADERS += *.h \
$$PWD/math/*.h \
$$PWD/network/*.h \
$$PWD/geo/*.h \
$$PWD/input/*.h \
$$PWD/hardware/*.h \
$$PWD/audio/*.h \
$$PWD/simulation/*.h \
@@ -45,6 +46,7 @@ SOURCES += *.cpp \
$$PWD/aviation/*.cpp \
$$PWD/math/*.cpp \
$$PWD/network/*.cpp \
$$PWD/input/*.cpp \
$$PWD/hardware/*.cpp \
$$PWD/geo/*.cpp \
$$PWD/audio/*.cpp \

View File

@@ -12,6 +12,7 @@
#include "geo/geo.h"
#include "audio/audio.h"
#include "hardware/hardware.h"
#include "input/input.h"
#include "settingsblackmiscclasses.h"
#include "propertyindexlist.h"
#include "propertyindexvariantmap.h"
@@ -55,16 +56,15 @@ void BlackMisc::Audio::registerMetadata()
CVoiceRoomList::registerMetadata();
}
void BlackMisc::Hardware::registerMetadata()
void BlackMisc::Input::registerMetadata()
{
CKeyboardKey::registerMetadata();
CKeyboardKeyList::registerMetadata();
CJoystickButton::registerMetadata();
}
void BlackMisc::Event::registerMetadata()
{
CEventHotkeyFunction::registerMetadata();
CJoystickButtonList::registerMetadata();
CActionHotkey::registerMetadata();
CActionHotkeyList::registerMetadata();
CHotkeyCombination::registerMetadata();
}
void BlackMisc::registerMetadata()
@@ -101,6 +101,7 @@ void BlackMisc::registerMetadata()
Hardware::registerMetadata();
Event::registerMetadata();
Weather::registerMetadata();
Input::registerMetadata();
// needed by XBus proxy class
qRegisterMetaType<CSequence<double>>();

View File

@@ -90,9 +90,9 @@ namespace BlackMisc
BLACKMISC_EXPORT bool startWindowsMixer();
}
namespace Hardware
namespace Input
{
//! Register metadata for Hardware
//! Register metadata for Input
BLACKMISC_EXPORT void registerMetadata();
}
@@ -328,7 +328,6 @@ namespace BlackMisc
//! Merges an incremental json object into an existing one
BLACKMISC_EXPORT QJsonObject applyIncrementalObject(const QJsonObject &previousObject, const QJsonObject &incrementalObject);
} // BlackMisc
#endif // guard

View File

@@ -0,0 +1,94 @@
/* Copyright (C) 2015
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "actionhotkey.h"
#include "blackmiscfreefunctions.h"
#include "variant.h"
namespace BlackMisc
{
namespace Input
{
CActionHotkey::CActionHotkey(const QString &action) :
m_action(action)
{}
CActionHotkey::CActionHotkey(const CIdentifier &identifier, const CHotkeyCombination &combination, const QString &action) :
m_identifier(identifier), m_combination(combination), m_action(action)
{}
QString CActionHotkey::convertToQString(bool /* i18n */) const
{
QString s;
s += m_identifier.getMachineName();
s += " ";
s += m_combination.toQString();
s += " ";
s += m_action;
return s;
}
void CActionHotkey::setCombination(const CHotkeyCombination &combination)
{
m_combination = combination;
}
void CActionHotkey::setObject(const CActionHotkey &obj)
{
m_action = obj.m_action;
m_combination = obj.m_combination;
}
CVariant CActionHotkey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexIdentifier:
return CVariant::from(m_identifier);
case IndexIdentifierAsString:
return CVariant::from(m_identifier.getMachineName());
case IndexAction:
return CVariant::from(m_action);
case IndexActionAsString:
return CVariant::from(m_action);
case IndexCombination:
return CVariant::from(m_combination);
case IndexCombinationAsString:
return CVariant::from(QString(m_combination.toQString()));
default:
return CValueObject::propertyByIndex(index);
}
}
void CActionHotkey::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself()) { (*this) = variant.to<CActionHotkey>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexAction:
{
m_action = variant.to<QString>();
break;
}
case IndexCombination:
case IndexCombinationAsString:
m_combination = variant.to<CHotkeyCombination>();
case IndexObject:
this->setObject(variant.value<CActionHotkey>());
break;
default:
CValueObject::setPropertyByIndex(variant, index);
break;
}
}
}
} // BlackMisc

View File

@@ -0,0 +1,100 @@
/* Copyright (C) 2015
* swift project community / contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_ACTIONHOTKEY_H
#define BLACKMISC_INPUT_ACTIONHOTKEY_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/input/hotkeycombination.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/identifier.h"
#include <QStringList>
namespace BlackMisc
{
namespace Input
{
//! Value object encapsulating a action hotkey
class BLACKMISC_EXPORT CActionHotkey : public CValueObject<CActionHotkey>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexIdentifier = BlackMisc::CPropertyIndex::GlobalIndexCSettingKeyboardHotkey,
IndexIdentifierAsString,
IndexCombination,
IndexCombinationAsString,
IndexAction,
IndexActionAsString,
IndexObject, // just for updates
};
//! Default constructor
CActionHotkey() = default;
//! Constructor
CActionHotkey(const QString &action);
//! Constructor
CActionHotkey(const CIdentifier &identifier, const CHotkeyCombination &combination, const QString &action);
//! Get hotkey combination
const CHotkeyCombination &getCombination() const { return m_combination; }
//! Set hotkey combination
void setCombination(const CHotkeyCombination &combination);
//! Action
QString getAction() const { return m_action; }
//! Set function
void setAction(const QString &action) { m_action = action; }
//! Set applicable machine
void setApplicableMachine(const CIdentifier &identifier) { m_identifier = identifier; }
//! Get applicable machine
CIdentifier getApplicableMachine() const { return m_identifier; }
//! Set object
void setObject(const CActionHotkey &obj);
//! Is hotkey valid?
bool isValid() const { return !m_identifier.getMachineName().isEmpty() && !m_combination.isEmpty() && !m_action.isEmpty(); }
//! \copydoc CValueObject::setPropertyByIndex
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! \copydoc CValueObject::propertyByIndex
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CActionHotkey)
CIdentifier m_identifier; //!< Identifier to which machine this hotkey belongs to
CHotkeyCombination m_combination; //!< hotkey combination
QString m_action; //!< hotkey action
};
}
}
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Input::CActionHotkey, (
attr(o.m_identifier),
attr(o.m_combination),
attr(o.m_action)
))
Q_DECLARE_METATYPE(BlackMisc::Input::CActionHotkey)
#endif // guard

View File

@@ -0,0 +1,46 @@
/* Copyright (C) 2013
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "actionhotkeylist.h"
namespace BlackMisc
{
namespace Input
{
CActionHotkeyList::CActionHotkeyList(const CSequence<CActionHotkey> &baseClass) :
CSequence<CActionHotkey>(baseClass)
{ }
CActionHotkeyList CActionHotkeyList::findSubsetsOf(const CActionHotkey &other)
{
CActionHotkeyList subsets;
for (const auto &actionHotkey : *this)
{
if (actionHotkey.getCombination().isSubsetOf(other.getCombination()))
{
subsets.push_back(actionHotkey);
}
}
return subsets;
}
CActionHotkeyList CActionHotkeyList::findSupersetsOf(const CActionHotkey &other)
{
CActionHotkeyList supersets;
for (const auto &actionHotkey : *this)
{
if (other.getCombination().isSubsetOf(actionHotkey.getCombination()))
{
supersets.push_back(actionHotkey);
}
}
return supersets;
}
}
}

View File

@@ -0,0 +1,66 @@
/* Copyright (C) 2015
* swift Project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_ACTIONHOTKEYLIST_H
#define BLACKMISC_INPUT_ACTIONHOTKEYLIST_H
#include "blackmisc/blackmiscexport.h"
#include "actionhotkey.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
namespace BlackMisc
{
namespace Input
{
//! Value object encapsulating a list of hotkeys
class BLACKMISC_EXPORT CActionHotkeyList :
public CSequence<CActionHotkey>,
public BlackMisc::Mixin::MetaType<CActionHotkeyList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CActionHotkeyList)
//! Default constructor
CActionHotkeyList() = default;
//! Construct from std::initializer_list<bool>
CActionHotkeyList(std::initializer_list<CActionHotkey> il) : CSequence<CActionHotkey>(il) {}
//! Construct from a base class object.
CActionHotkeyList(const CSequence<CActionHotkey> &baseClass);
//! Returns true if this list has a action hotkey with a combination which is a subset of other
//! Example:
//! List contains CTRL and other has combination CTRL-F
CActionHotkeyList findSubsetsOf(const CActionHotkey &other);
//! Returns true if this list has a hotkey with a combination for which other is a subset
//! Example:
//! List contains CTRL-F and other has combination CTRL
CActionHotkeyList findSupersetsOf(const CActionHotkey &other);
//! Compare two CHotkeyList
//! \todo Remove once https://dev.vatsim-germany.org/issues/459 is fixed
friend int compare(const CActionHotkeyList &a, const CActionHotkeyList &b)
{
return compare(static_cast<const CSequence<CActionHotkey> &>(a), static_cast<const CSequence<CActionHotkey> &>(b));
}
};
}
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Input::CActionHotkeyList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Input::CActionHotkey>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Input::CActionHotkey>)
#endif // guard

View File

@@ -0,0 +1,80 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/input/hotkeycombination.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/variant.h"
#include <QStringList>
namespace BlackMisc
{
namespace Input
{
void CHotkeyCombination::addKeyboardKey(const CKeyboardKey &key)
{
if (m_keyboardKeys.contains(key)) { return; }
m_keyboardKeys.push_back(key);
m_keyboardKeys.sortBy(&CKeyboardKey::getKey);
}
void CHotkeyCombination::addJoystickButton(const CJoystickButton &button)
{
if (m_joystickButtons.contains(button)) { return; }
m_joystickButtons.push_back(button);
m_joystickButtons.sortBy(&CJoystickButton::getButtonIndex);
}
void CHotkeyCombination::replaceKey(const CKeyboardKey &oldKey, const CKeyboardKey &newKey)
{
Q_ASSERT(!oldKey.isUnknown());
m_keyboardKeys.remove(oldKey);
if (!newKey.isUnknown()) { m_keyboardKeys.push_back(newKey); }
m_keyboardKeys.sortBy(&CKeyboardKey::getKey);
}
void CHotkeyCombination::replaceButton(const CJoystickButton &oldButton, const CJoystickButton &newButton)
{
m_joystickButtons.remove(oldButton);
if (newButton.isValid()) { m_joystickButtons.push_back(newButton); }
m_joystickButtons.sortBy(&CJoystickButton::getButtonIndex);
}
void CHotkeyCombination::removeKeyboardKey(const CKeyboardKey &key)
{
replaceKey(key, CKeyboardKey());
}
void CHotkeyCombination::removeJoystickButton(const CJoystickButton &button)
{
replaceButton(button, CJoystickButton());
}
bool CHotkeyCombination::isSubsetOf(const CHotkeyCombination &other) const
{
return std::all_of(m_keyboardKeys.begin(), m_keyboardKeys.end(), [&other](const CKeyboardKey &k) { return other.m_keyboardKeys.contains(k); }) &&
std::all_of(m_joystickButtons.begin(), m_joystickButtons.end(), [&other](const CJoystickButton &b) { return other.m_joystickButtons.contains(b); });
}
QString CHotkeyCombination::convertToQString(bool /* i18n */) const
{
QStringList sl;
for (const auto &key : m_keyboardKeys)
{
sl << key.toQString();
}
for (const auto &button : m_joystickButtons)
{
sl << button.toQString();
}
return sl.join('+');
}
}
}

View File

@@ -0,0 +1,90 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_HOTKEYCOMBINATION_H
#define BLACKMISC_INPUT_HOTKEYCOMBINATION_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/input/keyboardkeylist.h"
#include "blackmisc/input/joystickbuttonlist.h"
namespace BlackMisc
{
namespace Input
{
//! Value object representing hotkey sequence
class BLACKMISC_EXPORT CHotkeyCombination : public CValueObject<CHotkeyCombination>
{
public:
//! Default constructor
CHotkeyCombination() = default;
//! Set keyboard keys
void setKeyboardKeys(const CKeyboardKeyList &list) { m_keyboardKeys = list; }
//! Get keyboard keys
CKeyboardKeyList getKeyboardKeys() const { return m_keyboardKeys; }
//! Set joystick buttons
void setJoystickButtons(const CJoystickButtonList &list) { m_joystickButtons = list; }
//! Get joystick buttons
CJoystickButtonList getJoystickButtons() const { return m_joystickButtons; }
//! Add keyboard key
void addKeyboardKey(const CKeyboardKey &key);
//! Add joystick button
void addJoystickButton(const CJoystickButton &button);
//! Replace oldKey with newKey
void replaceKey(const CKeyboardKey &oldKey, const CKeyboardKey &newKey);
//! Replace oldButton with newButton
void replaceButton(const CJoystickButton &oldButton, const CJoystickButton &newButton);
//! Remove keyboard key
void removeKeyboardKey(const CKeyboardKey &key);
//! Remove joystick button
void removeJoystickButton(const CJoystickButton &button);
//! Is sequence empty?
bool isEmpty() const { return m_keyboardKeys.isEmpty() && m_joystickButtons.isEmpty(); }
//! Get size of sequence
int size() const { return m_keyboardKeys.size() + m_joystickButtons.size(); }
//! Is sequence a subset of other?
//! E.g. CTRL would be a subset of CTRL+D
bool isSubsetOf(const CHotkeyCombination &other) const;
//! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CHotkeyCombination)
CKeyboardKeyList m_keyboardKeys;
CJoystickButtonList m_joystickButtons;
};
}
}
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Input::CHotkeyCombination, (
attr(o.m_keyboardKeys),
attr(o.m_joystickButtons)
))
Q_DECLARE_METATYPE(BlackMisc::Input::CHotkeyCombination)
#endif // guard

View File

@@ -0,0 +1,18 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#ifndef BLACKMISC_INPUT_HOTKEY_H
#define BLACKMISC_INPUT_HOTKEY_H
#include "blackmisc/input/actionhotkeylist.h"
#include "blackmisc/input/hotkeycombination.h"
#include "blackmisc/input/keyboardkeylist.h"
#include "blackmisc/input/joystickbuttonlist.h"
#endif // guard

View File

@@ -0,0 +1,94 @@
/* Copyright (C) 2014
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/input/joystickbutton.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/variant.h"
#include <QCoreApplication>
namespace BlackMisc
{
namespace Input
{
CJoystickButton::CJoystickButton(int buttonIndex) :
m_buttonIndex(buttonIndex)
{}
void CJoystickButton::setButtonIndex(int buttonIndex)
{
m_buttonIndex = buttonIndex;
}
void CJoystickButton::setButtonObject(const CJoystickButton &button)
{
this->m_buttonIndex = button.m_buttonIndex;
}
void CJoystickButton::setPropertyByIndex(const CVariant &variant, const CPropertyIndex &index)
{
if (index.isMyself()) { (*this) = variant.to<CJoystickButton>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexButton:
case IndexButtonAsString:
this->setButtonIndex(buttonIndexFromString(variant.value<QString>()));
break;
case IndeButtonObject:
this->setButtonObject(variant.value<BlackMisc::Input::CJoystickButton>());
break;
default:
Q_ASSERT_X(false, "CJoystickButton", "index unknown (setter)");
break;
}
}
CVariant CJoystickButton::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexButton:
return CVariant::from(this->getButtonIndex());
case IndexButtonAsString:
return CVariant::from(this->getButtonAsString());
default:
break;
}
Q_ASSERT_X(false, "CJoystickButton", "index unknown");
QString m = QString("no property, index ").append(index.toQString());
return CVariant::fromValue(m);
}
QString CJoystickButton::buttonIndexToString(qint32 buttonIndex)
{
QString buttonString("Button");
return buttonString.append(QString("%1").arg(buttonIndex));
}
int CJoystickButton::buttonIndexFromString(const QString &buttonName)
{
QString name("Button");
if (!buttonName.startsWith(name)) return getInvalidIndex();
name.remove("Button");
return name.toInt();
}
QString CJoystickButton::convertToQString(bool /* i18n */) const
{
QString s = getButtonAsString();
return s.trimmed();
}
} // namespace Hardware
} // BlackMisc

View File

@@ -0,0 +1,87 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_JOYSTICKBUTTON_H
#define BLACKMISC_INPUT_JOYSTICKBUTTON_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/blackmiscfreefunctions.h"
namespace BlackMisc
{
namespace Input
{
//! Value object representing a joystick button
class BLACKMISC_EXPORT CJoystickButton : public CValueObject<CJoystickButton>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexButton = 0,
IndexButtonAsString,
IndeButtonObject, // just for updates
};
//! Default constructor
CJoystickButton() = default;
//! Constructor
CJoystickButton(int buttonIndex);
//! Get button index
int getButtonIndex() const { return m_buttonIndex; }
//! Get button as String
QString getButtonAsString() const { return buttonIndexToString(m_buttonIndex); }
//! Set button index
void setButtonIndex(int buttonIndex);
//! Is valid?
bool isValid() const { return m_buttonIndex >= 0 ? true : false; }
//! Set button object
void setButtonObject(const CJoystickButton &button);
//! \copydoc CValueObject::setPropertyByIndex
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! \copydoc CValueObject::propertyByIndex
CVariant propertyByIndex(const CPropertyIndex &index) const;
//! Button index to string
static QString buttonIndexToString(qint32 buttonIndex);
//! Button index from string
static int buttonIndexFromString(const QString &button);
//! Invalid button index
static int getInvalidIndex() { return m_invalidIndex; }
//! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const;
private:
BLACK_ENABLE_TUPLE_CONVERSION(CJoystickButton)
int m_buttonIndex = m_invalidIndex;
static const int m_invalidIndex = -1;
};
}
}
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Input::CJoystickButton, (o.m_buttonIndex))
Q_DECLARE_METATYPE(BlackMisc::Input::CJoystickButton)
#endif // guard

View File

@@ -0,0 +1,22 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/input/joystickbuttonlist.h"
#include "blackmisc/predicates.h"
namespace BlackMisc
{
namespace Input
{
CJoystickButtonList::CJoystickButtonList(const CSequence<CJoystickButton> &baseClass) :
CSequence<CJoystickButton>(baseClass)
{ }
} // namespace
} // namespace

View File

@@ -0,0 +1,49 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_JOYSTICKBUTTONLIST_H
#define BLACKMISC_INPUT_JOYSTICKBUTTONLIST_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/input/joystickbutton.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
namespace BlackMisc
{
namespace Input
{
//! Value object encapsulating a list of joystick buttons.
class BLACKMISC_EXPORT CJoystickButtonList :
public CSequence<CJoystickButton>,
public BlackMisc::Mixin::MetaType<CJoystickButtonList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CJoystickButtonList)
//! Default constructor
CJoystickButtonList() = default;
//! Construct from a base class object.
CJoystickButtonList(const CSequence<CJoystickButton> &baseClass);
//! Initializer list constructor.
CJoystickButtonList(std::initializer_list<CJoystickButton> il) : CSequence<CJoystickButton>(il) {}
};
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Input::CJoystickButtonList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Input::CJoystickButton>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Input::CJoystickButton>)
#endif //guard

View File

@@ -0,0 +1,109 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/input/keyboardkey.h"
#include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/variant.h"
namespace BlackMisc
{
namespace Input
{
CKeyboardKey::CKeyboardKey() :
m_keyCode(Key_Unknown)
{}
CKeyboardKey::CKeyboardKey(KeyCode keyCode) :
m_keyCode(keyCode)
{}
QString CKeyboardKey::convertToQString(bool /* i18n */) const
{
return getKeyAsString();
}
void CKeyboardKey::setKeyObject(const CKeyboardKey &key)
{
this->m_keyCode = key.m_keyCode;
}
QString CKeyboardKey::getKeyAsString() const
{
if (m_keyCode == Key_Unknown) return QString();
static const QHash<KeyCode, QString> keyStrings =
{
{ Key_ShiftLeft, QStringLiteral("ShiftLeft") },
{ Key_ShiftRight, QStringLiteral("ShiftRight") },
{ Key_ControlLeft, QStringLiteral("CtrlLeft") },
{ Key_ControlRight, QStringLiteral("CtrlRight") },
{ Key_AltLeft, QStringLiteral("AltLeft") },
{ Key_AltRight, QStringLiteral("AltRight") }
};
if (isModifier()) { return keyStrings.value(m_keyCode); }
QChar key = QChar::fromLatin1(m_keyCode);
return key;
}
const QList<KeyCode> &CKeyboardKey::allModifiers()
{
static const QList<KeyCode> allModifiers =
{
Key_ShiftLeft,
Key_ShiftRight,
Key_ControlLeft,
Key_ControlRight,
Key_AltLeft,
Key_AltRight,
};
return allModifiers;
}
CVariant CKeyboardKey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
{
if (index.isMyself()) { return CVariant::from(*this); }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexKey:
return CVariant::from(static_cast<int>(this->m_keyCode));
case IndexKeyAsString:
return CVariant::from(getKeyAsString());
default:
break;
}
Q_ASSERT_X(false, "CKeyboardKey", "index unknown");
QString m = QString("no property, index ").append(index.toQString());
return CVariant::fromValue(m);
}
void CKeyboardKey::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
{
if (index.isMyself()) { (*this) = variant.to<CKeyboardKey>(); return; }
ColumnIndex i = index.frontCasted<ColumnIndex>();
switch (i)
{
case IndexKey:
case IndexKeyAsString:
qFatal("Not implemented");
break;
case IndexKeyObject:
this->setKeyObject(variant.value<CKeyboardKey>());
break;
default:
Q_ASSERT_X(false, "CKeyboardKey", "index unknown (setter)");
break;
}
}
} // namespace Hardware
} // BlackMisc

View File

@@ -0,0 +1,97 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_KEYBOARDKEY_H
#define BLACKMISC_INPUT_KEYBOARDKEY_H
#include "keycodes.h"
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/propertyindex.h"
#include "blackmisc/valueobject.h"
#include "blackmisc/blackmiscfreefunctions.h"
namespace BlackMisc
{
namespace Input
{
//! Value object representing a keyboard key.
class BLACKMISC_EXPORT CKeyboardKey : public CValueObject<CKeyboardKey>
{
public:
//! Properties by index
enum ColumnIndex
{
IndexKey = 0,
IndexKeyAsString,
IndexKeyObject, // just for updates
};
//! Default constructor
CKeyboardKey();
//! Constructor
CKeyboardKey(BlackMisc::Input::KeyCode keyCode);
//! Get key code
KeyCode getKey() const { return this->m_keyCode; }
//! Get key code
QString getKeyAsString() const;
//! Set key code
void setKey(const KeyCode key) { this->m_keyCode = key; }
//! Set key code
void setKey(int key) { this->m_keyCode = static_cast<KeyCode>(key); }
//! Set key code
void setKey(char key) { this->m_keyCode = static_cast<KeyCode>(key); }
//! Is unknown?
bool isUnknown() const { return !this->hasKey(); }
//! Modifier?
bool isModifier() const
{
return allModifiers().contains(m_keyCode);
}
//! with key?
bool hasKey() const
{
return !(this->m_keyCode == KeyCode::Key_Unknown);
}
//! Set key object
void setKeyObject(const CKeyboardKey &key);
//! \copydoc CValueObject::setPropertyByIndex
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
//! \copydoc CValueObject::propertyByIndex
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
//! \copydoc CValueObject::convertToQString
QString convertToQString(bool i18n = false) const;
private:
static const QList<KeyCode> &allModifiers();
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
KeyCode m_keyCode; //!< Key code
};
}
}
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Input::CKeyboardKey, (o.m_keyCode))
Q_DECLARE_METATYPE(BlackMisc::Input::CKeyboardKey)
#endif // guard

View File

@@ -0,0 +1,75 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "blackmisc/input//keyboardkeylist.h"
#include "blackmisc/predicates.h"
namespace BlackMisc
{
namespace Input
{
CKeyboardKeyList::CKeyboardKeyList() { }
CKeyboardKeyList::CKeyboardKeyList(const CSequence<CKeyboardKey> &baseClass) :
CSequence<CKeyboardKey>(baseClass)
{ }
const CKeyboardKeyList &CKeyboardKeyList::allSupportedKeys()
{
static CKeyboardKeyList allKeys = {
CKeyboardKey(Key_ControlLeft),
CKeyboardKey(Key_ControlRight),
CKeyboardKey(Key_AltLeft),
CKeyboardKey(Key_AltRight),
CKeyboardKey(Key_ShiftLeft),
CKeyboardKey(Key_ShiftRight),
CKeyboardKey(Key_A),
CKeyboardKey(Key_B),
CKeyboardKey(Key_C),
CKeyboardKey(Key_D),
CKeyboardKey(Key_E),
CKeyboardKey(Key_F),
CKeyboardKey(Key_G),
CKeyboardKey(Key_H),
CKeyboardKey(Key_I),
CKeyboardKey(Key_J),
CKeyboardKey(Key_K),
CKeyboardKey(Key_L),
CKeyboardKey(Key_M),
CKeyboardKey(Key_N),
CKeyboardKey(Key_O),
CKeyboardKey(Key_P),
CKeyboardKey(Key_Q),
CKeyboardKey(Key_R),
CKeyboardKey(Key_S),
CKeyboardKey(Key_T),
CKeyboardKey(Key_U),
CKeyboardKey(Key_V),
CKeyboardKey(Key_W),
CKeyboardKey(Key_X),
CKeyboardKey(Key_Y),
CKeyboardKey(Key_Z),
CKeyboardKey(Key_0),
CKeyboardKey(Key_1),
CKeyboardKey(Key_2),
CKeyboardKey(Key_3),
CKeyboardKey(Key_4),
CKeyboardKey(Key_5),
CKeyboardKey(Key_6),
CKeyboardKey(Key_7),
CKeyboardKey(Key_8),
CKeyboardKey(Key_9),
};
return allKeys;
}
} // namespace
} // namespace

View File

@@ -0,0 +1,54 @@
/* Copyright (C) 2013
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_KEYBOARDKEYLIST_H
#define BLACKMISC_INPUT_KEYBOARDKEYLIST_H
#include "blackmisc/blackmiscexport.h"
#include "blackmisc/input/keyboardkey.h"
#include "blackmisc/collection.h"
#include "blackmisc/sequence.h"
#include <QObject>
namespace BlackMisc
{
namespace Input
{
//! Value object encapsulating a list of keyboard keys.
class BLACKMISC_EXPORT CKeyboardKeyList :
public CSequence<CKeyboardKey>,
public BlackMisc::Mixin::MetaType<CKeyboardKeyList>
{
public:
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CKeyboardKeyList)
//! Default constructor
CKeyboardKeyList();
//! Construct from a base class object.
CKeyboardKeyList(const CSequence<CKeyboardKey> &baseClass);
//! Initializer list constructor.
CKeyboardKeyList(std::initializer_list<CKeyboardKey> il) : CSequence<CKeyboardKey>(il) {}
//! Get all supported keys
static const CKeyboardKeyList &allSupportedKeys();
};
} //namespace
} // namespace
Q_DECLARE_METATYPE(BlackMisc::Input::CKeyboardKeyList)
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Input::CKeyboardKey>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Input::CKeyboardKey>)
#endif //guard

View File

@@ -0,0 +1,73 @@
/* Copyright (C) 2015
* swift project Community / Contributors
*
* This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKMISC_INPUT_KEYCODES_H
#define BLACKMISC_INPUT_KEYCODES_H
namespace BlackMisc
{
namespace Input
{
//! Key code
enum KeyCode
{
Key_Unknown,
// Modifiers
Key_ShiftLeft,
Key_ShiftRight,
Key_ControlLeft,
Key_ControlRight,
Key_AltLeft,
Key_AltRight,
// 0 - 9
Key_0 = 0x30,
Key_1,
Key_2,
Key_3,
Key_4,
Key_5,
Key_6,
Key_7,
Key_8,
Key_9,
// A - Z
Key_A = 0x41,
Key_B,
Key_C,
Key_D,
Key_E,
Key_F,
Key_G,
Key_H,
Key_I,
Key_J,
Key_K,
Key_L,
Key_M,
Key_N,
Key_O,
Key_P,
Key_Q,
Key_R,
Key_S,
Key_T,
Key_U,
Key_V,
Key_W,
Key_X,
Key_Y,
Key_Z,
};
} //namespace
} // namespace
#endif //guard