You can add a ClickListener mixin to any element*. An element with a ClickListener will fire a callback with a "ClickEvent" type - these types include "pressed", "released" or "cancel" (was pressed, but the finger was slid off rather than lifted).
* Including a button! The callbacks emitted by the standard button widgets don't seem to differentiate between the events and only fire when the button was pressed and then released, so you need the clicklistener mixin to receive a callback when the state is changed. I've not tested this though.
Example implementation:
- Follow this Mixin Guide (starting at Clicklistener halfway down the page)
- Where it says //Implement what should happen when 'box' is touched/clicked here, place the code below
if (evt.getType() == ClickEvent::PRESSED) {
// do what you need to do when the button is held down
} else if(evt.getType() == ClickEvent::RELEASED){
// do what you need when the button is released
} else {
// here the button was cancelled (finger slid off the button)
}
If you follow the MVP design pattern, your code for handling each event could call a method in the Presenter (such as presenter->buttonDown(), or presenter->buttonUp()) which would then call functions in the model that actually deal with the hardware (e.g. Model::setPumpStatus() ).
Alternately, you could probably extend the AbstractButton class, which will allow you to override AbstractButton::handleClickEvent(const ClickEvent & event). In this method you would check the event as the above, except instead of calling code directly, you would fire a callback with a parameter that passes the ClickEvent, but unless you have a bunch of buttons like this it might not be worth it. You also wouldn't be able to place them using the Designer.