#ifndef PROPERTY_H #define PROPERTY_H #include #include //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(value)); \ } \ //uncrustify on #endif //PROPERTY_H