Distinguishing Simple Click from Double Click and fom Drag


#1

Hello all

I’m trying to distinguish different Mouse Events for a draggable componnent :

  1. when mouse is dragged, drag the component
  2. when mouse is Single Clicked : open a popup window
  3. when mouse is Double Clicked : open another popup window.
  • I have overriden the mouseDrag to achieve step 1.

  • I have overriden the MouseUp and checked for the number of clicks to track single clicks

void myDraggableComponent::mouseUp(const MouseEvent &e)
{
  const int nbOfClicks = e.getNumberOfClicks();
	if(nbOfClicks==1)
	{
	/// do thing here
	}
}
  • i have overriden the MouseDoubleClick in order to track double cliks. But it seems i’m never going there.
    it seems that what i’m doing in MouseUp prevents the MouseDoubleClick from being called.

am i missing something ?
thanks in advance.


#2

…or maybe it’s your use of a capital ‘M’ !?

For stuff like this I normally override mouseDown and mouseUp, and then use the MouseEvent::getNumberOfClicks() to find out what’s going on. The logic can get pretty complicated, depending on your app - maybe have a look at things like SelectedItemSet::addToSelectionOnMouseUp for inspiration.


#3

thanks for seeing that, but it was correctly written in my code. I typed it wrong in my forum post.

After “commenting parts” of the code to see what was wrong , it looks like the popup window is resetting the MouseEvent behaviour. Ha yes : it’s a modal popupWindow shown like this :


			// create the contextual popup window
			ipChangeButton ipcb(this->enigne);
			ipSelector ipS(&ipcb);
			PopupMenu m;
			OldSchoolLookAndFeel lf;
			m.setLookAndFeel(&lf);
			m.addCustomItem (1234, &ipS, 800, 400, false);
			m.showAt (this);

if i remove this part and trigger another graphical event (colour change for instance), then it works and i can distinguish between double, single clicks and drag.