Exemplo n.º 1
0
/**
 * Garbage collector for actions.
 */
void RS_EventHandler::cleanUp() {
    RS_DEBUG->print("RS_EventHandler::cleanUp");

    for (auto it=currentActions.begin(); it != currentActions.end();)
    {
        if( (*it)->isFinished())
        {
            if (right_click_quits)
            {
                real_action->setChecked(false);
                right_click_quits = false;
            }
            delete *it;
            it= currentActions.erase(it);
        }else{
            ++it;
        }
    }
    if(hasAction()){
        currentActions.last()->resume();
        currentActions.last()->showOptions();
    } else {
		if (defaultAction) {
            defaultAction->resume();
            defaultAction->showOptions();
        }
    }
    RS_DEBUG->print("RS_EventHandler::cleanUp: OK");
}
Exemplo n.º 2
0
/**
 * @return Current action.
 */
RS_ActionInterface* RS_EventHandler::getCurrentAction(){
    if(hasAction()){
        return currentActions.last();
    } else {
        return defaultAction;
    }
}
Exemplo n.º 3
0
/**
 * Called by QG_GraphicView
 */
void RS_EventHandler::mouseMoveEvent(QMouseEvent* e)
{
    if(hasAction())
        currentActions.last()->mouseMoveEvent(e);

    else if (defaultAction)
        defaultAction->mouseMoveEvent(e);
}
Exemplo n.º 4
0
/**
 * Called by RS_GraphicView
 */
void RS_EventHandler::mouseEnterEvent() {

    if(hasAction()){
        currentActions.last()->resume();
    } else {
        if (defaultAction) {
            defaultAction->resume();
        }
    }
}
Exemplo n.º 5
0
/**
 * Called by RS_GraphicView
 */
void RS_EventHandler::mouseLeaveEvent() {

    if(hasAction()){
        currentActions.last()->suspend();
    } else {
        if (defaultAction) {
            defaultAction->suspend();
        }
        //RS_DEBUG->print("currently no action defined");
    }
}
Exemplo n.º 6
0
		bool keyboard::simulateAction()
		{
			if (!hasAction())
				return false;

			simulateAction(actionQueue.front());

			// Pop this action off of the queue.
			actionQueue.pop_front();

			return actionQueue.empty();
		}
	void ActionPerformer::addAction(const String&name, Action*action, bool destruct)
	{
		if(hasAction(name))
		{
			throw IllegalArgumentException("name", "duplicate action name");
		}
		
		ActionInfo actInfo;
		actInfo.name = name;
		actInfo.action = action;
		actInfo.destruct = destruct;
		actions.add(actInfo);
	}
Exemplo n.º 8
0
/**
 * Called by RS_GraphicView
 */
void RS_EventHandler::mousePressEvent(QMouseEvent* e) {
    if(hasAction()){
        currentActions.last()->mousePressEvent(e);
        e->accept();
    } else {
        if (defaultAction) {
            defaultAction->mousePressEvent(e);
            e->accept();
        } else {
            RS_DEBUG->print("currently no action defined");
            e->ignore();
        }
    }
}
Exemplo n.º 9
0
/**
 * Called by RS_GraphicView
 */
void RS_EventHandler::keyReleaseEvent(QKeyEvent* e) {

    if(hasAction()){
        currentActions.last()->keyReleaseEvent(e);
    } else {
        if (defaultAction) {
            defaultAction->keyReleaseEvent(e);
        }
        else {
            e->ignore();
        }
        //RS_DEBUG->print("currently no action defined");
    }
}
QAction* ActionManager::addSeparator(const QString &id)
{
    if (hasAction(id))
        return nullptr;

    const auto inserted = m_actions.insert(
                              std::make_pair(id, std14_stl::make_unique<QAction>(m_pMainWindow)));

    if (inserted.second) {
        auto pAction = inserted.first->second.get();
        pAction->setSeparator(true);
        return pAction;
    }

    return nullptr;
}
Exemplo n.º 11
0
/**
 * Called by RS_GraphicView
 */
void RS_EventHandler::mouseReleaseEvent(QMouseEvent* e) {
    if(hasAction()){
        //    if (actionIndex>=0 && currentActions[actionIndex] &&
        //            !currentActions[actionIndex]->isFinished()) {
        RS_DEBUG->print("call action %s",
                        currentActions.last()->getName().toLatin1().data());

        currentActions.last()->mouseReleaseEvent(e);

        // Clean up actions - one might be finished now
        cleanUp();
        e->accept();
    } else {
        if (defaultAction) {
            defaultAction->mouseReleaseEvent(e);
        } else {
            e->ignore();
        }
    }
}
Exemplo n.º 12
0
/**
 * Garbage collector for actions.
 */
void RS_EventHandler::cleanUp() {
    RS_DEBUG->print("RS_EventHandler::cleanUp");

    for (auto it=currentActions.begin();it != currentActions.end();){

        if( (*it)->isFinished()){
//            (*it)->finish();
            delete *it;
            it= currentActions.erase(it);
        }else{
            ++it;
        }
    }
    if(hasAction()){
        currentActions.last()->resume();
        currentActions.last()->showOptions();
    } else {
		if (defaultAction) {
            defaultAction->resume();
            defaultAction->showOptions();
        }
    }
    RS_DEBUG->print("RS_EventHandler::cleanUp: OK");
}
QAction* ActionManager::addAction(const QString      &id,
                                  const QString      &text,
                                  const QKeySequence &shortcut,
                                  const QIcon        &icon,
                                  const QString      &tooltip,
                                  const QString      &statustip)
{
    if (hasAction(id))
        return nullptr;

    const auto inserted = m_actions.insert(
                              std::make_pair(id, std14_stl::make_unique<QAction>(text, m_pMainWindow)));

    if (inserted.second) {
        auto pAction = inserted.first->second.get();
        pAction->setShortcut(shortcut);
        pAction->setIcon(icon);
        pAction->setToolTip(tooltip);
        pAction->setStatusTip(statustip);
        return pAction;
    }

    return nullptr;
}
Exemplo n.º 14
0
/**
 * Sets the current action.
 */
void RS_EventHandler::setCurrentAction(RS_ActionInterface* action) {
    RS_DEBUG->print("RS_EventHandler::setCurrentAction");
    if (action==NULL) {
        return;
    }

    // Predecessor of the new action or NULL:
    RS_ActionInterface* predecessor = NULL;

    // Suspend current action:
    if(hasAction()){
        predecessor = currentActions.last();
        predecessor->suspend();
        predecessor->hideOptions();
    }
    else {
        if (defaultAction) {
            predecessor = defaultAction;
            predecessor->suspend();
            predecessor->hideOptions();
        }
    }

    //    // Forget about the oldest action and make space for the new action:
    //    if (actionIndex==RS_MAXACTIONS-1) {
    //        // delete oldest action if necessary (usually never happens):
    //        if (currentActions[0]) {
    //            currentActions[0]->finish();
    //            delete currentActions[0];
    //            currentActions[0] = NULL;
    //        }
    //        // Move up actionstack (optimize):
    //        for (int i=0; i<RS_MAXACTIONS-1; ++i) {
    //            currentActions[i] = currentActions[i+1];
    //        }
    //    } else if (actionIndex<RS_MAXACTIONS-1) {
    //        actionIndex++;
    //    }

    // Set current action:
    currentActions.push_back(action);
    RS_DEBUG->print("RS_EventHandler::setCurrentAction: current action is: %s",
                    currentActions.last()->getName().toLatin1().data());

    // Initialisation of our new action:
    RS_DEBUG->print("RS_EventHandler::setCurrentAction: init current action");
    action->init();
    // ## new:
    if (action->isFinished()==false) {
        RS_DEBUG->print("RS_EventHandler::setCurrentAction: show options");
        currentActions.last()->showOptions();
        RS_DEBUG->print("RS_EventHandler::setCurrentAction: set predecessor");
        action->setPredecessor(predecessor);
    }

    RS_DEBUG->print("RS_EventHandler::setCurrentAction: cleaning up..");
    cleanUp();

    RS_DEBUG->print("RS_EventHandler::setCurrentAction: debugging actions");
    debugActions();
    RS_DEBUG->print("RS_GraphicView::setCurrentAction: OK");
}
Exemplo n.º 15
0
/**
 * Handles command line events.
 */
void RS_EventHandler::commandEvent(RS_CommandEvent* e) {
    RS_DEBUG->print("RS_EventHandler::commandEvent");
    QString cmd = e->getCommand();

    // allow using command line as a calculator
    if (!e->isAccepted())  {
        if(cliCalculator(cmd)) {
            e->accept();
            return;
        }
    }

    if (coordinateInputEnabled) {
        if (!e->isAccepted()) {

            if(hasAction()){
                // handle absolute cartesian coordinate input:
                if (cmd.contains(',') && cmd.at(0)!='@') {

                    int commaPos = cmd.indexOf(',');
                    RS_DEBUG->print("RS_EventHandler::commandEvent: 001");
                    bool ok1, ok2;
                    RS_DEBUG->print("RS_EventHandler::commandEvent: 002");
                    double x = RS_Math::eval(cmd.left(commaPos), &ok1);
                    RS_DEBUG->print("RS_EventHandler::commandEvent: 003a");
                    double y = RS_Math::eval(cmd.mid(commaPos+1), &ok2);
                    RS_DEBUG->print("RS_EventHandler::commandEvent: 004");

                    if (ok1 && ok2) {
                        RS_DEBUG->print("RS_EventHandler::commandEvent: 005");
                        RS_CoordinateEvent ce(RS_Vector(x,y));
                        RS_DEBUG->print("RS_EventHandler::commandEvent: 006");
                        currentActions.last()->coordinateEvent(&ce);
                    } else {
                        if (RS_DIALOGFACTORY) {
                            RS_DIALOGFACTORY->commandMessage(
                                        "Expression Syntax Error");
                        }
                    }
                    e->accept();
                }

                // handle relative cartesian coordinate input:
                if (!e->isAccepted()) {
                    if (cmd.contains(',') && cmd.at(0)=='@') {
                        int commaPos = cmd.indexOf(',');
                        bool ok1, ok2;
                        double x = RS_Math::eval(cmd.mid(1, commaPos-1), &ok1);
                        double y = RS_Math::eval(cmd.mid(commaPos+1), &ok2);

                        if (ok1 && ok2) {
                            RS_CoordinateEvent ce(RS_Vector(x,y) +
                                                  graphicView->getRelativeZero());

                            currentActions.last()->coordinateEvent(&ce);
                            //                            currentActions[actionIndex]->coordinateEvent(&ce);
                        } else {
                            if (RS_DIALOGFACTORY) {
                                RS_DIALOGFACTORY->commandMessage(
                                            "Expression Syntax Error");
                            }
                        }
                        e->accept();
                    }
                }

                // handle absolute polar coordinate input:
                if (!e->isAccepted()) {
                    if (cmd.contains('<') && cmd.at(0)!='@') {
                        int commaPos = cmd.indexOf('<');
                        bool ok1, ok2;
                        double r = RS_Math::eval(cmd.left(commaPos), &ok1);
                        double a = RS_Math::eval(cmd.mid(commaPos+1), &ok2);

                        if (ok1 && ok2) {
							RS_Vector pos{
								RS_Vector::polar(r,RS_Math::deg2rad(a))};
                            RS_CoordinateEvent ce(pos);
                            currentActions.last()->coordinateEvent(&ce);
                        } else {
                            if (RS_DIALOGFACTORY) {
                                RS_DIALOGFACTORY->commandMessage(
                                            "Expression Syntax Error");
                            }
                        }
                        e->accept();
                    }
                }

                // handle relative polar coordinate input:
                if (!e->isAccepted()) {
                    if (cmd.contains('<') && cmd.at(0)=='@') {
                        int commaPos = cmd.indexOf('<');
                        bool ok1, ok2;
                        double r = RS_Math::eval(cmd.mid(1, commaPos-1), &ok1);
                        double a = RS_Math::eval(cmd.mid(commaPos+1), &ok2);

                        if (ok1 && ok2) {
							RS_Vector pos = RS_Vector::polar(r,RS_Math::deg2rad(a));
                            RS_CoordinateEvent ce(pos +
                                                  graphicView->getRelativeZero());
                            currentActions.last()->coordinateEvent(&ce);
                        } else {
                            if (RS_DIALOGFACTORY) {
                                RS_DIALOGFACTORY->commandMessage(
                                            "Expression Syntax Error");
                            }
                        }
                        e->accept();
                    }
                }

                // send command event directly to current action:
                if (!e->isAccepted()) {
//                    std::cout<<"RS_EventHandler::commandEvent(RS_CommandEvent* e): sending cmd("<<qPrintable(e->getCommand()) <<") to action: "<<currentActions.last()->rtti()<<std::endl;
                    currentActions.last()->commandEvent(e);
                }
            }else{
            //send the command to default action
                if (defaultAction) {
                    defaultAction->commandEvent(e);
                }
            }
            // do not accept command here. Actions themselves should be responsible to accept commands
//            e->accept();
        }
    }

    RS_DEBUG->print("RS_EventHandler::commandEvent: OK");
}