forked from Sepanta/console-emulator
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
92 lines
2.8 KiB
92 lines
2.8 KiB
#ifndef PROPERTY_H
|
|
#define PROPERTY_H
|
|
|
|
#include <QObject>
|
|
#include <QDebug>
|
|
|
|
//uncrustify off
|
|
#define MVVM_PROPERTY(TYPE, NAME, DEFAULT_VALUE) \
|
|
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \
|
|
public: \
|
|
TYPE NAME() const { return _ ## NAME ; } \
|
|
void NAME(TYPE value) { \
|
|
if (_ ## NAME == value) return; \
|
|
_ ## NAME = value; \
|
|
emit NAME ## Changed(value); \
|
|
} \
|
|
Q_SIGNAL void NAME ## Changed(TYPE value);\
|
|
private: \
|
|
TYPE _ ## NAME = DEFAULT_VALUE; \
|
|
|
|
/**************************************************************************************************/
|
|
#define MVVM_PROPERTY_CUSTOM(TYPE, NAME, DEFAULT_VALUE) \
|
|
Q_PROPERTY(TYPE NAME READ NAME WRITE NAME NOTIFY NAME ## Changed ) \
|
|
public: \
|
|
TYPE NAME() const { return _ ## NAME ; } \
|
|
void NAME(TYPE value) { \
|
|
if (_ ## NAME == value) return; \
|
|
_ ## NAME = value; \
|
|
emit NAME ## Changed(value); \
|
|
NAME ## Handle(); \
|
|
} \
|
|
Q_SIGNAL void NAME ## Changed(TYPE value);\
|
|
private: \
|
|
TYPE _ ## NAME = DEFAULT_VALUE; \
|
|
|
|
/**************************************************************************************************/
|
|
#define BUTTON_LED_PROPERTY(NAME, CAP_NAME, DEFAULT_VALUE, LED_DEF_VAL) \
|
|
LED_PROPERTY(NAME, LED_DEF_VAL) \
|
|
BUTTON_PROPERTY(NAME, CAP_NAME, DEFAULT_VALUE)
|
|
|
|
/**************************************************************************************************/
|
|
#define BUTTON_PROPERTY(NAME, CAP_NAME, DEFAULT_VALUE) \
|
|
MVVM_PROPERTY_CUSTOM(bool, NAME, DEFAULT_VALUE) \
|
|
void NAME ## Handle() { \
|
|
if(_ ## NAME){ \
|
|
panel->press ## CAP_NAME(); \
|
|
} \
|
|
else { \
|
|
panel->release ## CAP_NAME(); \
|
|
} \
|
|
} \
|
|
|
|
/**************************************************************************************************/
|
|
#define LED_PROPERTY(NAME, LED_DEF_VAL) \
|
|
MVVM_PROPERTY(int, NAME ## Led, LED_DEF_VAL) \
|
|
|
|
/**************************************************************************************************/
|
|
#define JOYSTICK_PROPERTY(NAME, CAP_NAME) \
|
|
MVVM_PROPERTY_CUSTOM(bool, NAME ## Left, false) \
|
|
MVVM_PROPERTY_CUSTOM(bool, NAME ## Right, false) \
|
|
void NAME ## LeftHandle() { \
|
|
if(NAME ## Left()) \
|
|
{ \
|
|
panel->rotate ## CAP_NAME(stepDec()); \
|
|
} \
|
|
} \
|
|
void NAME ## RightHandle() { \
|
|
if(NAME ## Right()) \
|
|
{ \
|
|
panel->rotate ## CAP_NAME(stepInc()); \
|
|
} \
|
|
}
|
|
|
|
/**************************************************************************************************/
|
|
#define LED_SLOT(NAME) \
|
|
void NAME ## LedHandle(char value) { \
|
|
NAME ## Led(static_cast<int>(value)); \
|
|
} \
|
|
|
|
/**************************************************************************************************/
|
|
#define DROP_DOWN_PROPERTY(NAME, CAP_NAME, LED_DEF_VAL) \
|
|
MVVM_PROPERTY_CUSTOM(bool, NAME, false) \
|
|
void NAME ## Handle() { \
|
|
if(NAME()) \
|
|
{ \
|
|
panel->select ## CAP_NAME('stepDec()'); \
|
|
} \
|
|
} \
|
|
|
|
//uncrustify on
|
|
|
|
#endif //PROPERTY_H
|
|
|