2021-09-29 06:13 AM
When I put more graphs in a swipe container on distinct pages and try to make a swipe on the graph area, nothing happens, when i do the swipe out of the graph area, it goes to the next page. Does anybody know how can i solve this problem ?
2021-09-29 06:58 AM
The problem is that Graph widget takes all gestures for itself. This is known problem and I have seen solutions on the net. The Idea was to take control over gestures and dispatch them properly.
2021-09-29 11:05 AM
2021-09-29 11:44 PM
yeah, thanks, i already integrated this feature, i'll leave the code below
2021-09-29 11:47 PM
code for swiping withing two graphs:
void GraphsView::handleClickEvent(const ClickEvent& evt)
{
bool tempGraphAreaClicked = false;
bool humGraphAreaClicked = false;
if(TempGraph.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
{
tempGraphAreaClicked = true;
}
else if(HumGraph.getAbsoluteRect().intersect(evt.getX(), evt.getY()))
{
humGraphAreaClicked = true;
}
// Click Event occurred
if (evt.getType() == ClickEvent::PRESSED)
{
if(tempGraphAreaClicked)
{
// Click Event occurred within the graph
clickStatus = ClickStatus::CLICKED;
}
else if(humGraphAreaClicked)
{
clickStatus = ClickStatus::CLICKED;
}
GraphsViewBase::handleClickEvent(evt); // act normally
}
else if (evt.getType() == ClickEvent::RELEASED)
{
if(clickStatus == ClickStatus::CLICK_DRAGGING)
{
SwipeArea.handleClickEvent(evt);
}
else
{
// Not dragging, allow passing the event to the graph
GraphsViewBase::handleClickEvent(evt);
}
clickStatus = ClickStatus::RELEASED;
}
}
void GraphsView::handleDragEvent(const DragEvent& evt)
{
bool dragIntersect = false;
if((TempGraph.getAbsoluteRect().intersect(evt.getOldX(), evt.getOldY())) ||
( HumGraph.getAbsoluteRect().intersect(evt.getOldX(), evt.getOldY())))
{
dragIntersect = true;
}
if(dragIntersect)
{
// Drag occurred within a graph
if(abs(evt.getDeltaX()) > 2 && clickStatus == ClickStatus::CLICKED)
{
// We are now dragging, cancel any graph touch by creating a new click event
// and forwarding it to the rest of the view
ClickEvent cancelEvt(ClickEvent::CANCEL, evt.getOldX(), evt.getOldY(), 1);
GraphsViewBase::handleClickEvent(cancelEvt);
clickStatus = ClickStatus::CLICK_DRAGGING;
}
}
if(clickStatus == ClickStatus::CLICK_DRAGGING)
{
// We are dragging, forward drag events to swipe container only
SwipeArea.handleDragEvent(evt);
}
else
{
// No dragging within a graph occured, act normally
GraphsViewBase::handleDragEvent(evt);
}
}
void GraphsView::handleGestureEvent(const GestureEvent& evt)
{
if(clickStatus == ClickStatus::CLICK_DRAGGING)
{
// We are dragging, forward gesture events to swipe container only
SwipeArea.handleGestureEvent(evt);
}
else
{
// No dragging within a graph occured, act normally
GraphsViewBase::handleGestureEvent(evt);
}
}
2021-09-29 11:48 PM
Declare those in header file
void handleClickEvent(const ClickEvent& evt);
void handleDragEvent(const DragEvent& evt);
void handleGestureEvent(const GestureEvent& evt);
enum class ClickStatus {
RELEASED,
CLICKED,
CLICK_DRAGGING
};
ClickStatus clickStatus;