bool GoForwardActionWidget::eventFilter(QObject *object, QEvent *event)
{
	if (event->type() == QEvent::ContextMenu)
	{
		QContextMenuEvent *contextMenuEvent(dynamic_cast<QContextMenuEvent*>(event));

		if (contextMenuEvent)
		{
			QAction *action(menu()->activeAction());

			if (action && action->data().type() == QVariant::Int)
			{
				QMenu contextMenu(menu());
				QAction *removeEntryAction(contextMenu.addAction(tr("Remove Entry"), NULL, NULL, QKeySequence(Qt::Key_Delete)));
				QAction *purgeEntryAction(contextMenu.addAction(tr("Purge Entry"), NULL, NULL, QKeySequence(Qt::ShiftModifier | Qt::Key_Delete)));
				QAction *selectedAction(contextMenu.exec(contextMenuEvent->globalPos()));

				if (selectedAction == removeEntryAction)
				{
					menu()->close();

					getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt());
				}
				else if (selectedAction == purgeEntryAction)
				{
					menu()->close();

					getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt(), true);
				}
			}
		}
	}
	else if (event->type() == QEvent::KeyPress)
	{
		QKeyEvent *keyEvent(dynamic_cast<QKeyEvent*>(event));

		if (keyEvent && keyEvent->key() == Qt::Key_Delete && getWindow())
		{
			QAction *action(menu()->activeAction());

			if (action && action->data().type() == QVariant::Int)
			{
				menu()->close();

				getWindow()->getContentsWidget()->removeHistoryIndex(action->data().toInt(), keyEvent->modifiers().testFlag(Qt::ShiftModifier));
			}
		}
	}

	return QObject::eventFilter(object, event);
}
Esempio n. 2
0
void BuildingSprite::onTouchEnded(Touch* pTouch, Event* pEvent)
{
    // 标记为被选中
    if(_isTouched == true) {
        if (_deltaPos <= LIMIT_DELTA) {
            
            // 第一次点击
            if (_isSelected == false) {
                // 先去除占地
                GM()->setCoverd(_pos, -1);
            }
            
            _isSelected = true;
            this->setOpacity(255);
            this->setColor(Color3B::GREEN);
            this->setLocalZOrder(TILED_TOTAL_X + TILED_TOTAL_Y + 1);
            _tip->setOpacity(255);
            selectedAction();
        }
    }
    else {
        if (_isShowOpt == true) {
            _isSelected = false;
            this->setOpacity(0);
            this->setColor(Color3B::WHITE);
            this->setTiledPos();
            _tip->setOpacity(0);
            unselectedAction();
        }
    }
    
    // 显示/隐藏操作opt
    if (_isTouched == true) {
        if (_deltaPos <= LIMIT_DELTA) {
            auto maplayer = (HomeMapLayer*)this->getParent();
            auto optlayer = ((HomeScene*)maplayer->getParent())->_optLayer;
            optlayer->show(this);
            _isShowOpt = true;
        }
    }
    else if(_isShowOpt == true) {
        auto maplayer = (HomeMapLayer*)this->getParent();
        auto optlayer = ((HomeScene*)maplayer->getParent())->_optLayer;
        optlayer->hide(this);
        _isShowOpt = false;
    }
}