Example #1
0
	// Called when not in connection mode
	void
	FlowDesigner::handleNormalClick(QMouseEvent *event) {
		float x = event->x();
		float y = event->y();

		Component *comp = getComponentIntersection(x, y);

		Qt::KeyboardModifiers modifiers = QApplication::keyboardModifiers();

		if (comp != NULL) {
			Port *port = getPortIntersection(comp, x, y);
			if (port) {
				if (event->button() == Qt::RightButton) {
					// Show context menu
					QMenu menu(this);
					port->createContextMenu(&menu);
					QAction *selected = menu.exec(mapToGlobal(QPoint(x, y)));
					if (selected != NULL) {
						port->handleContextSelect(selected);
					}
				} if (event->button() == Qt::MiddleButton ||
					  modifiers.testFlag(Qt::ControlModifier)) {
					m_project->clearSelected();
					port->disconnectAll();
				} else {
					m_project->clearSelected();
					// We've clicked on an output
					// Start a new connection
					m_connectingPort = port;
					updateConnectionCoords(event);
				}

				repaint();
			} else if (event->button() == Qt::LeftButton) { // Do selecting/dragging
				
				if (!modifiers.testFlag(Qt::ControlModifier) &&
					!m_project->isSelected(comp)) m_project->clearSelected();

				m_project->addSelected(comp);

				// Assume we're dragging
				// If not, when the release comes
				// dragging will be set to false
				m_dragging = true;

				repaint();
			} else if (event->button() == Qt::RightButton) { 
				if (!modifiers.testFlag(Qt::ControlModifier) &&
					!m_project->isSelected(comp)) m_project->clearSelected();

				m_project->addSelected(comp);

                // We've right-clicked on the body of the component
				// Pop up a context window
				QMenu menu(this);
				

				comp->createContextMenu(&menu);
				menu.addSeparator();
				QAction *d = menu.addAction("Delete");

				QAction *selected = menu.exec(mapToGlobal(QPoint(x, y)));
				if (selected == d) {
					m_project->deleteSelected();
					repaint();
				} else if (selected != NULL) {
					comp->handleContextSelect(selected);
				}
			}
		} else {
			if (!modifiers.testFlag(Qt::ControlModifier)) m_project->clearSelected();
			repaint();
		} 		
	}