mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-07 11:05:33 +08:00
committed by
Mathew Sutcliffe
parent
be7ac1aa74
commit
08a1de995a
@@ -34,7 +34,6 @@ HEADERS += *.h \
|
||||
$$PWD/network/*.h \
|
||||
$$PWD/geo/*.h \
|
||||
$$PWD/input/*.h \
|
||||
$$PWD/hardware/*.h \
|
||||
$$PWD/audio/*.h \
|
||||
$$PWD/simulation/*.h \
|
||||
$$PWD/simulation/fscommon/*.h \
|
||||
@@ -47,7 +46,6 @@ SOURCES += *.cpp \
|
||||
$$PWD/math/*.cpp \
|
||||
$$PWD/network/*.cpp \
|
||||
$$PWD/input/*.cpp \
|
||||
$$PWD/hardware/*.cpp \
|
||||
$$PWD/geo/*.cpp \
|
||||
$$PWD/audio/*.cpp \
|
||||
$$PWD/simulation/*.cpp \
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
#include "math/math.h"
|
||||
#include "geo/geo.h"
|
||||
#include "audio/audio.h"
|
||||
#include "hardware/hardware.h"
|
||||
#include "input/input.h"
|
||||
#include "settingsblackmiscclasses.h"
|
||||
#include "propertyindexlist.h"
|
||||
@@ -23,7 +22,6 @@
|
||||
#include "pixmap.h"
|
||||
#include "iconlist.h"
|
||||
#include "identifierlist.h"
|
||||
#include "eventallclasses.h"
|
||||
#include <QtNetwork/QHostInfo>
|
||||
#include <QProcessEnvironment>
|
||||
#include <QSysInfo>
|
||||
@@ -44,8 +42,6 @@ void BlackMisc::Geo::registerMetadata()
|
||||
void BlackMisc::Settings::registerMetadata()
|
||||
{
|
||||
CSettingsAudio::registerMetadata();
|
||||
CSettingKeyboardHotkey::registerMetadata();
|
||||
CSettingKeyboardHotkeyList::registerMetadata();
|
||||
}
|
||||
|
||||
void BlackMisc::Audio::registerMetadata()
|
||||
@@ -82,7 +78,6 @@ void BlackMisc::registerMetadata()
|
||||
CStatusMessageList::registerMetadata();
|
||||
CIcon::registerMetadata();
|
||||
CIconList::registerMetadata();
|
||||
CHotkeyFunction::registerMetadata();
|
||||
CLogCategory::registerMetadata();
|
||||
CLogCategoryList::registerMetadata();
|
||||
CPixmap::registerMetadata();
|
||||
@@ -98,8 +93,6 @@ void BlackMisc::registerMetadata()
|
||||
Settings::registerMetadata();
|
||||
Simulation::registerMetadata();
|
||||
Audio::registerMetadata();
|
||||
Hardware::registerMetadata();
|
||||
Event::registerMetadata();
|
||||
Weather::registerMetadata();
|
||||
Input::registerMetadata();
|
||||
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_EVENT_ALLCLASSES_H
|
||||
#define BLACKMISC_EVENT_ALLCLASSES_H
|
||||
|
||||
#include "blackmisc/eveventhotkeyfunction.h"
|
||||
|
||||
#endif // guard
|
||||
@@ -1,32 +0,0 @@
|
||||
/* 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 "eveventhotkeyfunction.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Event
|
||||
{
|
||||
CEventHotkeyFunction::CEventHotkeyFunction(CHotkeyFunction func, bool argument)
|
||||
: m_hotkeyFunc(func), m_hotkeyFuncArgument(argument)
|
||||
{
|
||||
}
|
||||
|
||||
/*
|
||||
* Convert to string
|
||||
*/
|
||||
QString CEventHotkeyFunction::convertToQString(bool i18n) const
|
||||
{
|
||||
QString s;
|
||||
s.append(m_eventOriginator.toQString(i18n));
|
||||
s.append(" ").append(m_hotkeyFunc.toQString(i18n));
|
||||
return s;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_EVENT_HOTKEYFUNCTION_H
|
||||
#define BLACKMISC_EVENT_HOTKEYFUNCTION_H
|
||||
|
||||
//! \file
|
||||
|
||||
#include "blackmiscexport.h"
|
||||
#include "valueobject.h"
|
||||
#include "identifier.h"
|
||||
#include "hotkeyfunction.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Event
|
||||
{
|
||||
//! Value object encapsulating a hotkey function for distribution
|
||||
class BLACKMISC_EXPORT CEventHotkeyFunction : public CValueObject<CEventHotkeyFunction>
|
||||
{
|
||||
public:
|
||||
//! Default constructor.
|
||||
CEventHotkeyFunction() = default;
|
||||
|
||||
//! Constructor.
|
||||
CEventHotkeyFunction(CHotkeyFunction func, bool argument);
|
||||
|
||||
//! Get the event originator
|
||||
const CIdentifier &getEventOriginator() const {return m_eventOriginator;}
|
||||
|
||||
//! Get the event key
|
||||
const BlackMisc::CHotkeyFunction &getFunction() const {return m_hotkeyFunc;}
|
||||
|
||||
//! Get boolean hotkey function argument
|
||||
bool getFunctionArgument() const { return m_hotkeyFuncArgument; }
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CEventHotkeyFunction)
|
||||
CIdentifier m_eventOriginator;
|
||||
CHotkeyFunction m_hotkeyFunc;
|
||||
|
||||
// This is the required argument to call a registered function per CHotkeyFunction
|
||||
bool m_hotkeyFuncArgument = false;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Event::CEventHotkeyFunction, (attr(o.m_eventOriginator, flags<DisabledForJson>()), o.m_hotkeyFunc))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Event::CEventHotkeyFunction)
|
||||
|
||||
#endif // BLACKMISC_EVENTHOTKEY_H
|
||||
@@ -1,16 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
#ifndef BLACKMISC_HARDWARE_HARDWAREALL_H
|
||||
#define BLACKMISC_HARDWARE_HARDWAREALL_H
|
||||
|
||||
#include "blackmisc/hardware/keyboardkeylist.h"
|
||||
#include "blackmisc/hardware/joystickbutton.h"
|
||||
|
||||
#endif // guard
|
||||
@@ -1,94 +0,0 @@
|
||||
/* 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/hardware/joystickbutton.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
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::Hardware::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));
|
||||
}
|
||||
|
||||
qint32 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
|
||||
@@ -1,87 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_HARDWARE_JOYSTICKBUTTON_H
|
||||
#define BLACKMISC_HARDWARE_JOYSTICKBUTTON_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
//! 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 BlackMisc::Hardware::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 qint32 buttonIndexFromString(const QString &button);
|
||||
|
||||
//! Invalid button index
|
||||
static qint32 getInvalidIndex() { return m_invalidIndex; }
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CJoystickButton)
|
||||
int m_buttonIndex = m_invalidIndex; //!< code similar to Qt::Key
|
||||
|
||||
static const int m_invalidIndex = -1;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CJoystickButton, (o.m_buttonIndex))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Hardware::CJoystickButton)
|
||||
|
||||
#endif // guard
|
||||
@@ -1,310 +0,0 @@
|
||||
/* 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/hardware/keyboardkey.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
CKeyboardKey::CKeyboardKey() :
|
||||
m_qtKey(Qt::Key_unknown), m_modifier1(ModifierNone), m_modifier2(ModifierNone)
|
||||
{}
|
||||
|
||||
CKeyboardKey::CKeyboardKey(Qt::Key keyCode, Modifier modifier1, Modifier modifier2) :
|
||||
m_qtKey(keyCode), m_modifier1(modifier1), m_modifier2(modifier2)
|
||||
{}
|
||||
|
||||
QString CKeyboardKey::convertToQString(bool /* i18n */) const
|
||||
{
|
||||
QString s = this->getModifier1AsString();
|
||||
s.append(" ").append(this->getModifier2AsString()).append(" ");
|
||||
if (this->m_qtKey != 0) s.append(" ").append(this->getKeyAsStringRepresentation());
|
||||
return s.trimmed();
|
||||
}
|
||||
|
||||
QString CKeyboardKey::modifierToString(CKeyboardKey::Modifier modifier)
|
||||
{
|
||||
switch (modifier)
|
||||
{
|
||||
case ModifierNone: return "";
|
||||
case ModifierAltAny: return "Alt";
|
||||
case ModifierAltLeft: return "Alt Left";
|
||||
case ModifierAltRight: return "Alt Right";
|
||||
case ModifierShiftAny: return "Shift";
|
||||
case ModifierShiftLeft: return "Shift Left";
|
||||
case ModifierShiftRight: return "Shift Right";
|
||||
case ModifierCtrlAny: return "Ctrl";
|
||||
case ModifierCtrlLeft: return "Ctrl Left";
|
||||
case ModifierCtrlRight: return "Ctrl Right";
|
||||
case ModifierMeta: return "Meta";
|
||||
default:
|
||||
qFatal("Wrong modifier");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
CKeyboardKey::Modifier CKeyboardKey::modifierFromString(const QString &modifier)
|
||||
{
|
||||
QString mod = modifier.toLower().replace('&', ' ');
|
||||
if (mod == "ctrl" || mod == "ctl") return ModifierCtrlAny;
|
||||
if (mod.startsWith("ctrl l") || mod.startsWith("ctl l")) return ModifierCtrlLeft;
|
||||
if (mod.startsWith("ctrl r") || mod.startsWith("ctl r")) return ModifierCtrlRight;
|
||||
|
||||
if (mod == "shift") return ModifierShiftAny;
|
||||
if (mod.startsWith("shift l")) return ModifierShiftLeft;
|
||||
if (mod.startsWith("shift r")) return ModifierShiftRight;
|
||||
|
||||
if (mod == "alt") return ModifierAltAny;
|
||||
if (mod.startsWith("alt l")) return ModifierAltLeft;
|
||||
if (mod.startsWith("alt r")) return ModifierAltRight;
|
||||
|
||||
if (mod == "meta") return ModifierMeta;
|
||||
|
||||
return ModifierNone;
|
||||
}
|
||||
|
||||
CKeyboardKey::Modifier CKeyboardKey::modifierFromQtModifier(Qt::Modifier qtModifier)
|
||||
{
|
||||
switch (qtModifier)
|
||||
{
|
||||
case Qt::META : return ModifierMeta;
|
||||
case Qt::SHIFT : return ModifierShiftAny;
|
||||
case Qt::CTRL: return ModifierShiftAny;
|
||||
case Qt::ALT: return ModifierAltAny;
|
||||
default:
|
||||
return ModifierNone;
|
||||
}
|
||||
}
|
||||
|
||||
const QStringList &CKeyboardKey::modifiers()
|
||||
{
|
||||
static QStringList modifiers;
|
||||
if (modifiers.isEmpty())
|
||||
{
|
||||
modifiers << modifierToString(ModifierNone);
|
||||
modifiers << modifierToString(ModifierCtrlAny);
|
||||
modifiers << modifierToString(ModifierCtrlLeft);
|
||||
modifiers << modifierToString(ModifierCtrlRight);
|
||||
modifiers << modifierToString(ModifierShiftAny);
|
||||
modifiers << modifierToString(ModifierShiftLeft);
|
||||
modifiers << modifierToString(ModifierShiftRight);
|
||||
modifiers << modifierToString(ModifierAltAny);
|
||||
modifiers << modifierToString(ModifierAltLeft);
|
||||
modifiers << modifierToString(ModifierAltRight);
|
||||
modifiers << modifierToString(ModifierMeta);
|
||||
}
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
void CKeyboardKey::cleanup()
|
||||
{
|
||||
if (!this->hasModifier()) return;
|
||||
if (this->m_modifier1 == ModifierNone) qSwap(this->m_modifier1, this->m_modifier2);
|
||||
if (this->numberOfModifiers() == 1) return;
|
||||
if (this->m_modifier1 == this->m_modifier2)
|
||||
{
|
||||
// redundant
|
||||
this->m_modifier2 = ModifierNone;
|
||||
return;
|
||||
}
|
||||
|
||||
// order
|
||||
if (static_cast<uint>(this->m_modifier1) < static_cast<uint>(this->m_modifier2))
|
||||
qSwap(this->m_modifier1, this->m_modifier2);
|
||||
}
|
||||
|
||||
int CKeyboardKey::numberOfModifiers() const
|
||||
{
|
||||
if (!this->hasModifier()) return 0;
|
||||
if (this->m_modifier1 == ModifierNone || this->m_modifier2 == ModifierNone) return 1;
|
||||
return 2;
|
||||
}
|
||||
|
||||
void CKeyboardKey::setKey(const QString &key)
|
||||
{
|
||||
if (key.isEmpty())
|
||||
this->m_qtKey = Qt::Key_unknown;
|
||||
|
||||
QKeySequence sequence(key);
|
||||
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||
}
|
||||
|
||||
void CKeyboardKey::setKey(const QChar &key)
|
||||
{
|
||||
if (key.isNull())
|
||||
this->m_qtKey = Qt::Key_unknown;
|
||||
else
|
||||
{
|
||||
QKeySequence sequence(key);
|
||||
m_qtKey = static_cast<Qt::Key>(sequence[0]);
|
||||
}
|
||||
}
|
||||
|
||||
bool CKeyboardKey::addModifier(const Modifier &modifier)
|
||||
{
|
||||
bool added = false;
|
||||
|
||||
// Don't add the same modifier twice
|
||||
if (hasModifier(modifier))
|
||||
return false;
|
||||
|
||||
if (m_modifier1 == ModifierNone)
|
||||
{
|
||||
m_modifier1 = modifier;
|
||||
added = true;
|
||||
}
|
||||
else if (m_modifier2 == ModifierNone)
|
||||
{
|
||||
m_modifier2 = modifier;
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (added) this->cleanup();
|
||||
return added;
|
||||
}
|
||||
|
||||
bool CKeyboardKey::addModifier(const QString &modifier)
|
||||
{
|
||||
return addModifier(modifierFromString(modifier));
|
||||
}
|
||||
|
||||
bool CKeyboardKey::removeModifier(const Modifier &modifier)
|
||||
{
|
||||
bool removed = false;
|
||||
|
||||
if (m_modifier1 == modifier)
|
||||
{
|
||||
m_modifier1 = ModifierNone;
|
||||
removed = true;
|
||||
}
|
||||
if (m_modifier2 == modifier)
|
||||
{
|
||||
m_modifier2 = ModifierNone;
|
||||
removed = true;
|
||||
}
|
||||
cleanup();
|
||||
return removed;
|
||||
}
|
||||
|
||||
bool CKeyboardKey::removeModifier(const QString &modifier)
|
||||
{
|
||||
return removeModifier(modifierFromString(modifier));
|
||||
}
|
||||
|
||||
bool CKeyboardKey::equalsModifierReleaxed(CKeyboardKey::Modifier m1, CKeyboardKey::Modifier m2)
|
||||
{
|
||||
if (m1 == m2) return true;
|
||||
if (m1 == ModifierAltAny && (m2 == ModifierAltLeft || m2 == ModifierAltRight)) return true;
|
||||
if (m1 == ModifierCtrlAny && (m2 == ModifierCtrlLeft || m2 == ModifierCtrlRight)) return true;
|
||||
if (m1 == ModifierShiftAny && (m2 == ModifierShiftLeft || m2 == ModifierShiftRight)) return true;
|
||||
|
||||
if (m2 == ModifierAltAny && (m1 == ModifierAltLeft || m1 == ModifierAltRight)) return true;
|
||||
if (m2 == ModifierCtrlAny && (m1 == ModifierCtrlLeft || m1 == ModifierCtrlRight)) return true;
|
||||
if (m2 == ModifierShiftAny && (m1 == ModifierShiftLeft || m1 == ModifierShiftRight)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void CKeyboardKey::setKeyObject(const CKeyboardKey &key)
|
||||
{
|
||||
this->m_modifier1 = key.m_modifier1;
|
||||
this->m_modifier2 = key.m_modifier2;
|
||||
this->m_qtKey = key.m_qtKey;
|
||||
}
|
||||
|
||||
bool CKeyboardKey::equalsWithRelaxedModifiers(const CKeyboardKey &key) const
|
||||
{
|
||||
if (key == (*this)) return true; // fully equal, not need to bother
|
||||
|
||||
// this can never be true
|
||||
if (key.m_qtKey != this->m_qtKey) return false;
|
||||
if (this->numberOfModifiers() != key.numberOfModifiers()) return false;
|
||||
|
||||
// special modifiers
|
||||
if (this->getModifier1() != key.getModifier1())
|
||||
{
|
||||
if (!CKeyboardKey::equalsModifierReleaxed(this->getModifier1(), key.getModifier1())) return false;
|
||||
}
|
||||
return CKeyboardKey::equalsModifierReleaxed(this->getModifier1(), key.getModifier1());
|
||||
}
|
||||
|
||||
QString CKeyboardKey::toStringRepresentation(int key)
|
||||
{
|
||||
if (key == 0) return "";
|
||||
QString ks = QKeySequence(key).toString();
|
||||
return ks;
|
||||
}
|
||||
|
||||
CVariant CKeyboardKey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexModifier1:
|
||||
return CVariant::from(static_cast<uint>(this->m_modifier1));
|
||||
case IndexModifier2:
|
||||
return CVariant::from(static_cast<uint>(this->m_modifier2));
|
||||
case IndexModifier1AsString:
|
||||
return CVariant::from(this->getModifier1AsString());
|
||||
case IndexModifier2AsString:
|
||||
return CVariant::from(this->getModifier2AsString());
|
||||
case IndexKey:
|
||||
return CVariant::from(static_cast<int>(this->m_qtKey));
|
||||
case IndexKeyAsString:
|
||||
return CVariant::from(QString(QChar(this->m_qtKey)));
|
||||
case IndexKeyAsStringRepresentation:
|
||||
return CVariant::from(this->getKeyAsStringRepresentation());
|
||||
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:
|
||||
case IndexKeyAsStringRepresentation:
|
||||
{
|
||||
// static_cast see docu of variant.type()
|
||||
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QChar)
|
||||
this->setKey(variant.value<QChar>());
|
||||
else
|
||||
this->setKey(variant.value<QString>());
|
||||
break;
|
||||
}
|
||||
case IndexModifier1AsString:
|
||||
this->setModifier1(variant.value<QString>());
|
||||
break;
|
||||
case IndexModifier2AsString:
|
||||
this->setModifier2(variant.value<QString>());
|
||||
break;
|
||||
case IndexKeyObject:
|
||||
this->setKeyObject(variant.value<BlackMisc::Hardware::CKeyboardKey>());
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT_X(false, "CKeyboardKey", "index unknown (setter)");
|
||||
break;
|
||||
}
|
||||
}
|
||||
} // namespace Hardware
|
||||
} // BlackMisc
|
||||
@@ -1,222 +0,0 @@
|
||||
/* 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_HARDWARE_KEYBOARDKEY_H
|
||||
#define BLACKMISC_HARDWARE_KEYBOARDKEY_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/propertyindex.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include <QStringList>
|
||||
#include <QKeySequence>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
//! Value object representing a keyboard key.
|
||||
class BLACKMISC_EXPORT CKeyboardKey : public CValueObject<CKeyboardKey>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexKey = 0,
|
||||
IndexKeyAsString,
|
||||
IndexKeyAsStringRepresentation,
|
||||
IndexModifier1,
|
||||
IndexModifier2,
|
||||
IndexModifier1AsString,
|
||||
IndexModifier2AsString,
|
||||
IndexKeyObject, // just for updates
|
||||
};
|
||||
|
||||
//! Modifier
|
||||
enum Modifier
|
||||
{
|
||||
ModifierNone,
|
||||
ModifierCtrlLeft,
|
||||
ModifierCtrlRight,
|
||||
ModifierCtrlAny,
|
||||
ModifierAltLeft,
|
||||
ModifierAltRight,
|
||||
ModifierAltAny,
|
||||
ModifierShiftLeft,
|
||||
ModifierShiftRight,
|
||||
ModifierShiftAny,
|
||||
ModifierMeta,
|
||||
ModifierNum
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CKeyboardKey();
|
||||
|
||||
//! Constructor
|
||||
CKeyboardKey(Qt::Key keyCode, Modifier modifier1 = ModifierNone, Modifier modifier2 = ModifierNone);
|
||||
|
||||
//! Get key code
|
||||
Qt::Key getKey() const { return this->m_qtKey; }
|
||||
|
||||
//! Get key code
|
||||
QString getKeyAsString() const { return QString(this->getKey()); }
|
||||
|
||||
//! Get key code
|
||||
QString getKeyAsStringRepresentation() const { return CKeyboardKey::toStringRepresentation(this->m_qtKey); }
|
||||
|
||||
//! As Qt::Key
|
||||
Qt::Key getKeyAsQtKey() const { return static_cast<Qt::Key>(this->m_qtKey);}
|
||||
|
||||
//! Set key code
|
||||
void setKey(const QString &key);
|
||||
|
||||
//! Set key code
|
||||
void setKey(const QChar &key);
|
||||
|
||||
//! Set key code
|
||||
void setKey(const Qt::Key key) { this->m_qtKey = key; }
|
||||
|
||||
//! Set key code
|
||||
void setKey(int key) { this->m_qtKey = static_cast<Qt::Key>(key); }
|
||||
|
||||
/*!
|
||||
* Add modifier
|
||||
* \param modifier
|
||||
* \return True if modifier was added
|
||||
*/
|
||||
bool addModifier(const Modifier &modifier);
|
||||
|
||||
/*!
|
||||
* add modifier
|
||||
* \param modifier
|
||||
* \return True if modifier was added
|
||||
*/
|
||||
bool addModifier(const QString &modifier);
|
||||
|
||||
//! number of modifiers
|
||||
int numberOfModifiers() const;
|
||||
|
||||
//! Modifier 1
|
||||
Modifier getModifier1() const { return this->m_modifier1; }
|
||||
|
||||
//! Modifier 2
|
||||
Modifier getModifier2() const { return this->m_modifier2; }
|
||||
|
||||
//! Modifier 1
|
||||
QString getModifier1AsString() const { return modifierToString(this->m_modifier1); }
|
||||
|
||||
//! Modifier 2
|
||||
QString getModifier2AsString() const { return modifierToString(this->m_modifier2); }
|
||||
|
||||
/*!
|
||||
* Remove modifier from key
|
||||
* \param modifier
|
||||
* \return True if modifier was removed
|
||||
*/
|
||||
bool removeModifier(const Modifier &modifier);
|
||||
|
||||
/*!
|
||||
* Remove modifier from key
|
||||
* \param modifier
|
||||
* \return True if modifier was removed
|
||||
*/
|
||||
bool removeModifier(const QString &modifier);
|
||||
|
||||
//! Set modifier 1
|
||||
void setModifier1(const QString &modifier) { this->m_modifier1 = modifierFromString(modifier); }
|
||||
|
||||
//! Set modifier 1
|
||||
void setModifier1(const Modifier &modifier) { this->m_modifier1 = modifier; }
|
||||
|
||||
//! Set modifier 2
|
||||
void setModifier2(const QString &modifier) { this->m_modifier2 = modifierFromString(modifier); }
|
||||
|
||||
//! Set modifier 2
|
||||
void setModifier2(const Modifier &modifier) { this->m_modifier2 = modifier; }
|
||||
|
||||
//! Is empty, (no key, no modifier)?
|
||||
bool isEmpty() const { return !this->hasModifier() && !this->hasKey(); }
|
||||
|
||||
//! Modifier?
|
||||
bool hasModifier() const
|
||||
{
|
||||
return this->m_modifier1 != ModifierNone || this->m_modifier2 != ModifierNone;
|
||||
}
|
||||
|
||||
//! Do we have this modifier?
|
||||
bool hasModifier(Modifier modifier) const
|
||||
{
|
||||
return m_modifier1 == modifier || m_modifier2 == modifier;
|
||||
}
|
||||
|
||||
//! ALT = ALT/R or ALT/L, CTRL = CTRL/R or left, ...
|
||||
static bool equalsModifierReleaxed(Modifier m1, Modifier m2);
|
||||
|
||||
//! with key?
|
||||
bool hasKey() const
|
||||
{
|
||||
return !(this->m_qtKey == Qt::Key_unknown);
|
||||
}
|
||||
|
||||
//! Key + modifier?
|
||||
bool hasKeyAndModifier() const
|
||||
{
|
||||
return this->hasKey() && this->hasModifier();
|
||||
}
|
||||
|
||||
//! Order Modifiers
|
||||
void cleanup();
|
||||
|
||||
//! Set key object
|
||||
void setKeyObject(const BlackMisc::Hardware::CKeyboardKey &key);
|
||||
|
||||
//! CTRL will be consider equal CTRL-left/reigt, ALT = ALT-left/right ..
|
||||
bool equalsWithRelaxedModifiers(const CKeyboardKey &key) const;
|
||||
|
||||
//! \copydoc CValueObject::setPropertyByIndex
|
||||
void setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index);
|
||||
|
||||
//! \copydoc CValueObject::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! Modifier to string
|
||||
static QString modifierToString(Modifier modifier);
|
||||
|
||||
//! Modifier from string
|
||||
static Modifier modifierFromString(const QString &modifier);
|
||||
|
||||
//! Modifier from Qt::Modifier
|
||||
static Modifier modifierFromQtModifier(Qt::Modifier qtModifier);
|
||||
|
||||
//! all modifiers
|
||||
static const QStringList &modifiers();
|
||||
|
||||
/*!
|
||||
* CKeyboardKey::toStringRepresentation
|
||||
*/
|
||||
static QString toStringRepresentation(int key);
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CKeyboardKey)
|
||||
Qt::Key m_qtKey; //!< code similar to Qt::Key
|
||||
Modifier m_modifier1;
|
||||
Modifier m_modifier2;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Hardware::CKeyboardKey, (o.m_qtKey, o.m_modifier1, o.m_modifier2))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKey)
|
||||
|
||||
#endif // guard
|
||||
@@ -1,25 +0,0 @@
|
||||
/* 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/hardware/keyboardkeylist.h"
|
||||
#include "blackmisc/predicates.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
|
||||
CKeyboardKeyList::CKeyboardKeyList() { }
|
||||
|
||||
CKeyboardKeyList::CKeyboardKeyList(const CSequence<CKeyboardKey> &baseClass) :
|
||||
CSequence<CKeyboardKey>(baseClass)
|
||||
{ }
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -1,48 +0,0 @@
|
||||
/* 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_HARDWARE_KEYBOARDKEYLIST_H
|
||||
#define BLACKMISC_HARDWARE_KEYBOARDKEYLIST_H
|
||||
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
#include "blackmisc/hardware/keyboardkey.h"
|
||||
#include "blackmisc/collection.h"
|
||||
#include "blackmisc/sequence.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Hardware
|
||||
{
|
||||
//! 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);
|
||||
|
||||
};
|
||||
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Hardware::CKeyboardKeyList)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Hardware::CKeyboardKey>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Hardware::CKeyboardKey>)
|
||||
|
||||
#endif //guard
|
||||
@@ -1,46 +0,0 @@
|
||||
/* 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 "hotkeyfunction.h"
|
||||
#include "QCoreApplication"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
CHotkeyFunction::CHotkeyFunction()
|
||||
: m_function(HotkeyNone)
|
||||
{
|
||||
}
|
||||
|
||||
CHotkeyFunction::CHotkeyFunction(Function function)
|
||||
: m_function(function)
|
||||
{
|
||||
}
|
||||
|
||||
QString CHotkeyFunction::getFunctionAsString() const
|
||||
{
|
||||
switch (m_function)
|
||||
{
|
||||
case HotkeyNone: return "";
|
||||
case HotkeyPtt: return qApp->translate("CHotkeyFunction", "PTT");
|
||||
case HotkeyOpacity50: return qApp->translate("CHotkeyFunction", "Opacity 50%");
|
||||
case HotkeyOpacity100: return qApp->translate("CHotkeyFunction", "Opacity 100%");
|
||||
case HotkeyToggleCom1: return qApp->translate("CHotkeyFunction", "Toggle COM1");
|
||||
case HotkeyToggleCom2: return qApp->translate("CHotkeyFunction", "Toggle COM2");
|
||||
case HotkeyToogleWindowsStayOnTop: return qApp->translate("CHotkeyFunction", "Toogle Window on top");
|
||||
default:
|
||||
qFatal("Wrong function");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
QString CHotkeyFunction::convertToQString(bool /* i18n */) const
|
||||
{
|
||||
return getFunctionAsString();
|
||||
}
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_HOTKEYFUNCTION_H
|
||||
#define BLACKMISC_HOTKEYFUNCTION_H
|
||||
|
||||
#include "blackmiscexport.h"
|
||||
#include "propertyindex.h"
|
||||
#include "valueobject.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
//! Value object representing a hotkey function.
|
||||
class BLACKMISC_EXPORT CHotkeyFunction : public CValueObject<CHotkeyFunction>
|
||||
{
|
||||
public:
|
||||
//! Function type
|
||||
enum Function
|
||||
{
|
||||
HotkeyNone,
|
||||
HotkeyPtt,
|
||||
HotkeyToggleCom1,
|
||||
HotkeyToggleCom2,
|
||||
HotkeyOpacity50,
|
||||
HotkeyOpacity100,
|
||||
HotkeyToogleWindowsStayOnTop
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CHotkeyFunction();
|
||||
|
||||
//! Constructor by function
|
||||
CHotkeyFunction(Function function);
|
||||
|
||||
//! Get function as string
|
||||
QString getFunctionAsString() const;
|
||||
|
||||
//! Function
|
||||
Function getFunction() const { return m_function; }
|
||||
|
||||
//! Set function
|
||||
void setFunction(const Function &function) { m_function = function; }
|
||||
|
||||
//! Hotkey function is Ptt
|
||||
static const CHotkeyFunction &Ptt()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyPtt);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! Hotkey function is toggle Com1
|
||||
static const CHotkeyFunction &ToggleCom1()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyToggleCom1);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! Hotkey function is toggle Com2
|
||||
static const CHotkeyFunction &ToggleCom2()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyToggleCom2);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! Hotkey function is opacity 50
|
||||
static const CHotkeyFunction &Opacity50()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyOpacity50);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! Hotkey function is opacity 100
|
||||
static const CHotkeyFunction &Opacity100()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyOpacity100);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! Hotkey function is toggle windows on top
|
||||
static const CHotkeyFunction &ToogleWindowsStayOnTop()
|
||||
{
|
||||
static CHotkeyFunction hotkeyFunction(HotkeyToogleWindowsStayOnTop);
|
||||
return hotkeyFunction;
|
||||
}
|
||||
|
||||
//! \copydoc CValueObject::convertToQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
private:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CHotkeyFunction)
|
||||
Function m_function;
|
||||
};
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::CHotkeyFunction, (o.m_function))
|
||||
Q_DECLARE_METATYPE(BlackMisc::CHotkeyFunction)
|
||||
|
||||
#endif //BLACKMISC_HOTKEYFUNCTION_H
|
||||
@@ -1,111 +0,0 @@
|
||||
/* 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 "setkeyboardhotkey.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include "variant.h"
|
||||
#include <QCoreApplication>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CSettingKeyboardHotkey::CSettingKeyboardHotkey(const CHotkeyFunction &function) :
|
||||
m_hotkeyFunction(function)
|
||||
{}
|
||||
|
||||
CSettingKeyboardHotkey::CSettingKeyboardHotkey(const Hardware::CKeyboardKey &key, const CHotkeyFunction &function) :
|
||||
m_key(key), m_hotkeyFunction(function)
|
||||
{}
|
||||
|
||||
QString CSettingKeyboardHotkey::convertToQString(bool /* i18n */) const
|
||||
{
|
||||
return m_key.toQString();
|
||||
}
|
||||
|
||||
void CSettingKeyboardHotkey::setKey(const Hardware::CKeyboardKey &key)
|
||||
{
|
||||
m_key = key;
|
||||
}
|
||||
|
||||
void CSettingKeyboardHotkey::setObject(const CSettingKeyboardHotkey &obj)
|
||||
{
|
||||
m_hotkeyFunction = obj.m_hotkeyFunction;
|
||||
m_key = obj.m_key;
|
||||
}
|
||||
|
||||
CVariant CSettingKeyboardHotkey::propertyByIndex(const BlackMisc::CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexFunction:
|
||||
return CVariant::from(static_cast<uint>(m_hotkeyFunction.getFunction()));
|
||||
case IndexFunctionAsString:
|
||||
return CVariant::from(m_hotkeyFunction.getFunctionAsString());
|
||||
case IndexModifier1:
|
||||
return CVariant::from(static_cast<uint>(m_key.getModifier1()));
|
||||
case IndexModifier2:
|
||||
return CVariant::from(static_cast<uint>(m_key.getModifier2()));
|
||||
case IndexModifier1AsString:
|
||||
return CVariant::from(m_key.getModifier1AsString());
|
||||
case IndexModifier2AsString:
|
||||
return CVariant::from(m_key.getModifier2AsString());
|
||||
case IndexKey:
|
||||
return CVariant::from(static_cast<int>(m_key.getKeyAsQtKey()));
|
||||
case IndexKeyAsString:
|
||||
return CVariant::from(QString(QChar(m_key.getKeyAsQtKey())));
|
||||
case IndexKeyAsStringRepresentation:
|
||||
return CVariant::from(m_key.getKeyAsStringRepresentation());
|
||||
default:
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
void CSettingKeyboardHotkey::setPropertyByIndex(const CVariant &variant, const BlackMisc::CPropertyIndex &index)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CSettingKeyboardHotkey>(); return; }
|
||||
ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexFunction:
|
||||
{
|
||||
uint f = variant.value<uint>();
|
||||
m_hotkeyFunction.setFunction(static_cast<CHotkeyFunction::Function>(f));
|
||||
break;
|
||||
}
|
||||
case IndexKey:
|
||||
case IndexKeyAsString:
|
||||
case IndexKeyAsStringRepresentation:
|
||||
{
|
||||
// static_cast see docu of variant.type()
|
||||
if (static_cast<QMetaType::Type>(variant.type()) == QMetaType::QChar)
|
||||
m_key.setKey(variant.value<QChar>());
|
||||
else
|
||||
m_key.setKey(variant.value<QString>());
|
||||
break;
|
||||
}
|
||||
case IndexModifier1AsString:
|
||||
m_key.setModifier1(variant.value<QString>());
|
||||
break;
|
||||
case IndexModifier2AsString:
|
||||
m_key.setModifier2(variant.value<QString>());
|
||||
break;
|
||||
case IndexObject:
|
||||
this->setObject(variant.value<BlackMisc::Settings::CSettingKeyboardHotkey>());
|
||||
break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(variant, index);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Hardware
|
||||
} // BlackMisc
|
||||
@@ -1,105 +0,0 @@
|
||||
/* 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.
|
||||
*/
|
||||
|
||||
//! \file
|
||||
|
||||
#ifndef BLACKMISC_SETTINGS_KEYBOARDHOTKEY_H
|
||||
#define BLACKMISC_SETTINGS_KEYBOARDHOTKEY_H
|
||||
|
||||
#include "blackmiscexport.h"
|
||||
#include "propertyindex.h"
|
||||
#include "hardware/keyboardkey.h"
|
||||
#include "hotkeyfunction.h"
|
||||
#include "blackmiscfreefunctions.h"
|
||||
#include <QStringList>
|
||||
#include <QKeySequence>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Value object encapsulating the keyboard hotkey assignment
|
||||
class BLACKMISC_EXPORT CSettingKeyboardHotkey : public CValueObject<CSettingKeyboardHotkey>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexKey = BlackMisc::CPropertyIndex::GlobalIndexCSettingKeyboardHotkey,
|
||||
IndexKeyAsString,
|
||||
IndexKeyAsStringRepresentation,
|
||||
IndexModifier1,
|
||||
IndexModifier2,
|
||||
IndexModifier1AsString,
|
||||
IndexModifier2AsString,
|
||||
IndexFunction,
|
||||
IndexFunctionAsString,
|
||||
IndexObject, // just for updates
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CSettingKeyboardHotkey() = default;
|
||||
|
||||
//! Constructor
|
||||
CSettingKeyboardHotkey(const CHotkeyFunction &function);
|
||||
|
||||
//! Constructor
|
||||
CSettingKeyboardHotkey(const Hardware::CKeyboardKey &key, const CHotkeyFunction &function);
|
||||
|
||||
//! Get key code
|
||||
const Hardware::CKeyboardKey &getKey() const { return m_key; }
|
||||
|
||||
//! Set key code
|
||||
void setKey(const Hardware::CKeyboardKey &key);
|
||||
|
||||
//! Function
|
||||
CHotkeyFunction getFunction() const { return m_hotkeyFunction; }
|
||||
|
||||
//! Set function
|
||||
void setFunction(const CHotkeyFunction &function) { this->m_hotkeyFunction = function; }
|
||||
|
||||
//! Set object
|
||||
void setObject(const CSettingKeyboardHotkey &obj);
|
||||
|
||||
//! Cleanup key
|
||||
void cleanup() { m_key.cleanup(); }
|
||||
|
||||
//! Get modifier1 as string
|
||||
QString getModifier1AsString() const { return m_key.getModifier1AsString(); }
|
||||
|
||||
//! Get modifier2 as string
|
||||
QString getModifier2AsString() const { return m_key.getModifier1AsString(); }
|
||||
|
||||
//! Modifiers
|
||||
static QStringList modifiers() { return Hardware::CKeyboardKey::modifiers(); }
|
||||
|
||||
//! Create string representation
|
||||
static QString toStringRepresentation(int key) { return Hardware::CKeyboardKey::toStringRepresentation(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:
|
||||
BLACK_ENABLE_TUPLE_CONVERSION(CSettingKeyboardHotkey)
|
||||
Hardware::CKeyboardKey m_key; //!< code similar to Qt::Key
|
||||
CHotkeyFunction m_hotkeyFunction; //!< hotkey function
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
BLACK_DECLARE_TUPLE_CONVERSION(BlackMisc::Settings::CSettingKeyboardHotkey, (o.m_key, o.m_hotkeyFunction))
|
||||
Q_DECLARE_METATYPE(BlackMisc::Settings::CSettingKeyboardHotkey)
|
||||
|
||||
#endif // guard
|
||||
@@ -1,62 +0,0 @@
|
||||
/* 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 "setkeyboardhotkeylist.h"
|
||||
#include "predicates.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
using namespace Hardware;
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
/*
|
||||
* Constructor
|
||||
*/
|
||||
CSettingKeyboardHotkeyList::CSettingKeyboardHotkeyList() { }
|
||||
|
||||
/*
|
||||
* Construct from base class object
|
||||
*/
|
||||
CSettingKeyboardHotkeyList::CSettingKeyboardHotkeyList(const CSequence<CSettingKeyboardHotkey> &baseClass) :
|
||||
CSequence<CSettingKeyboardHotkey>(baseClass)
|
||||
{ }
|
||||
|
||||
/*
|
||||
* Contains this hotkey function?
|
||||
*/
|
||||
bool CSettingKeyboardHotkeyList::containsFunction(const CHotkeyFunction &function) const
|
||||
{
|
||||
return CSequence::contains(&CSettingKeyboardHotkey::getFunction, function);
|
||||
}
|
||||
|
||||
/*
|
||||
* Key for function
|
||||
*/
|
||||
CSettingKeyboardHotkey CSettingKeyboardHotkeyList::keyForFunction(const CHotkeyFunction &function) const
|
||||
{
|
||||
return this->findBy(&CSettingKeyboardHotkey::getFunction, function).frontOrDefault();
|
||||
}
|
||||
|
||||
/*
|
||||
* Hotkey list
|
||||
*/
|
||||
void CSettingKeyboardHotkeyList::initAsHotkeyList(bool reset)
|
||||
{
|
||||
if (reset) this->clear();
|
||||
if (!this->containsFunction(CHotkeyFunction::Ptt())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::Ptt()));
|
||||
if (!this->containsFunction(CHotkeyFunction::ToggleCom1())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::ToggleCom1()));
|
||||
if (!this->containsFunction(CHotkeyFunction::ToggleCom2())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::ToggleCom2()));
|
||||
if (!this->containsFunction(CHotkeyFunction::Opacity50())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::Opacity50()));
|
||||
if (!this->containsFunction(CHotkeyFunction::Opacity100())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::Opacity100()));
|
||||
if (!this->containsFunction(CHotkeyFunction::ToogleWindowsStayOnTop())) push_back(CSettingKeyboardHotkey(CHotkeyFunction::ToogleWindowsStayOnTop()));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
} // namespace
|
||||
@@ -1,59 +0,0 @@
|
||||
/* 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_SETTINGS_KEYBOARDHOTKEYLIST_H
|
||||
#define BLACKMISC_SETTINGS_KEYBOARDHOTKEYLIST_H
|
||||
|
||||
#include "blackmiscexport.h"
|
||||
#include "hardware/keyboardkey.h"
|
||||
#include "setkeyboardhotkey.h"
|
||||
#include "collection.h"
|
||||
#include "sequence.h"
|
||||
#include <QObject>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! Value object encapsulating a list of keyboard keys.
|
||||
class BLACKMISC_EXPORT CSettingKeyboardHotkeyList :
|
||||
public CSequence<CSettingKeyboardHotkey>,
|
||||
public BlackMisc::Mixin::MetaType<CSettingKeyboardHotkeyList>
|
||||
{
|
||||
public:
|
||||
BLACKMISC_DECLARE_USING_MIXIN_METATYPE(CSettingKeyboardHotkeyList)
|
||||
|
||||
//! Default constructor
|
||||
CSettingKeyboardHotkeyList();
|
||||
|
||||
//! Construct from a base class object.
|
||||
CSettingKeyboardHotkeyList(const CSequence<CSettingKeyboardHotkey> &baseClass);
|
||||
|
||||
//! Contains given hotkey function?
|
||||
bool containsFunction(const CHotkeyFunction &function) const;
|
||||
|
||||
//! Key for given function
|
||||
BlackMisc::Settings::CSettingKeyboardHotkey keyForFunction(const CHotkeyFunction &function) const;
|
||||
|
||||
//! Fill the list with hotkeys
|
||||
//! \param reset true, list will be be reset, otherwise values will not be overridde
|
||||
void initAsHotkeyList(bool reset = true);
|
||||
|
||||
};
|
||||
|
||||
} //namespace
|
||||
} // namespace
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Settings::CSettingKeyboardHotkeyList)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CCollection<BlackMisc::Settings::CSettingKeyboardHotkey>)
|
||||
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Settings::CSettingKeyboardHotkey>)
|
||||
|
||||
#endif //guard
|
||||
@@ -2,6 +2,5 @@
|
||||
#define BLACKMISC_SETTINGSBLACKMISCCLASSES_H
|
||||
|
||||
#include "blackmisc/setaudio.h"
|
||||
#include "blackmisc/setkeyboardhotkeylist.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user