cancel
Showing results for 
Search instead for 
Did you mean: 

Multiple graphs in swipe container

MSecr.1
Associate II

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 ?

5 REPLIES 5
ktrofimo
Senior III

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.​

yeah, thanks, i already integrated this feature, i'll leave the code below

MSecr.1
Associate II

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);

  }

}

MSecr.1
Associate II

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;