‎2019-10-09 01:44 AM
‎2019-10-14 01:46 AM
​Oh, I misunderstood - I thought it was for a Click Event for a Button and not a view. The code should be the same - Except you don't have to register as a timer widget to receive ticks and keep track of time. You're already receiving ticks in your view through the handleTickEvent() method.
So, instead of just looking at evt.getType(), start a timer when you receive the first clickEvent (manage some state through the handleTickEvent() method. Once your time-threshold has been reached and the user has NOT released yet, then do whatever you want to do for your "long press". Does that make sense?
Some quick pesudo code to explain:
void Screen1View::handleClickEvent(ClickEvent& evt)
{
if(evt.pressed)
{
evaluate_long_press = true;
}
else if(evt.released)
{
evaluate_long_press = false;
counter = 0;
}
}
void Screen1View::handleTickEvent()
{
if(evaluate_long_press)
{
counter++;
if(counter == 1000)
{
execute_long_press_action();
evaluate_long_press = false;
}
}
}
‎2019-10-09 03:52 AM
Hi,
Check the RepeatButton class, it's open souce to you. It already supports part of what you want, and you can modify it to your liking =) It counts ticks and determines when to fire (continuously). You just want to set the tick threshhold higher before activation (long press), and then never activate again.
I'm sure you'll be able to figure it out - otherwise let me know.
/Martin
‎2019-10-13 10:58 PM
Hi Martin,
Thanks for your help. Do you mean setDelay() function? But I am not going to click a button. I want to click a whole screenview. The code like below:
void Screen1View::handleClickEvent(const ClickEvent& evt)
{
if(evt.getType()==ClickEvent::RELEASED) // When "long press", the dialog show.
{
if(!modalDialog.isVisible())
{
clickX=evt.getX();
clickY=evt.getY();
modalDialog.setXY(clickX, clickY);
modalDialog.setVisible(true);
modalDialog.invalidate();
}
else
{
background.invalidate();
modalDialog.setVisible(false);
}
}
View::handleClickEvent(evt);
}
‎2019-10-14 01:46 AM
​Oh, I misunderstood - I thought it was for a Click Event for a Button and not a view. The code should be the same - Except you don't have to register as a timer widget to receive ticks and keep track of time. You're already receiving ticks in your view through the handleTickEvent() method.
So, instead of just looking at evt.getType(), start a timer when you receive the first clickEvent (manage some state through the handleTickEvent() method. Once your time-threshold has been reached and the user has NOT released yet, then do whatever you want to do for your "long press". Does that make sense?
Some quick pesudo code to explain:
void Screen1View::handleClickEvent(ClickEvent& evt)
{
if(evt.pressed)
{
evaluate_long_press = true;
}
else if(evt.released)
{
evaluate_long_press = false;
counter = 0;
}
}
void Screen1View::handleTickEvent()
{
if(evaluate_long_press)
{
counter++;
if(counter == 1000)
{
execute_long_press_action();
evaluate_long_press = false;
}
}
}
‎2019-10-14 06:15 PM
Hi Martin,
​
It's work, thanks a lot !
‎2019-10-15 12:00 AM
Nice! :) No problem.
/Martin
‎2021-02-02 02:24 PM
Hi Martin, I added
void Screen1View::handleClickEvent(ClickEvent& evt)
{
amount++; // just some code to be able to put breakpoint here
}
to Screen1View.cpp, but after inserting breakpoint into it that line, it does not stop there in debug mode, therefore it does not actually execute the contents of handleClickEvent().
Is there anything else that I need to include or declare in .cpp or .hpp. file? I have dificulties with implementing event handlers :\
Thanks
‎2022-05-16 01:35 AM
Hi @Martin KJELDSEN​
How do we know which button was pressed? For example, When button2 pressed, get evaluate_long_press = true
void Screen1View::handleClickEvent(ClickEvent& evt)
{
if(evt.pressed)
{
evaluate_long_press = true;
}
else if(evt.released)
{
evaluate_long_press = false;
counter = 0;
}
}