Exemplo n.º 1
0
void SpellItem::keyPressEvent(QKeyEvent * event)
{
	Spell * spellParent = NULL;
	switch (event->key())
	{
		// Delete : remove that spell
	case Qt::Key::Key_Delete :
		spellParent = spell_->getParent();
		if (spellParent == NULL)
		{
			// Can't remove the top level spell, so just clear it
			cout << "Clearing top level spell" << endl;
			spell_->clear();
		}
		else
		{
			cout << "Removing spell" << endl;
			spellParent->remove(spell_);
		}
		emit(changedSpell());
		break;
	case Qt::Key::Key_Plus:
		// No need for the alternative add
		//if (event->modifiers() & Qt::ShiftModifier)
		spell_->addEmptyChild();
		emit(changedSpell());
		break;
	case Qt::Key::Key_Escape:
		clearFocus();
		break;
	}
}
Exemplo n.º 2
0
	void RuneItem::keyPressEvent(QKeyEvent * event)
	{
		Spell * spellParent = NULL;
		switch (event->key())
		{
			// Delete : remove that spell
		case Qt::Key::Key_Delete:
			spellParent = spell_->getParent();
			if (spellParent == NULL)
			{
				// Can't remove the top level spell, so just clear it
				cout << "Clearing top level spell" << endl;
				spell_->clear();
				emit(changedSpell());
			}
			else
			{
				cout << "Removing spell" << endl;
				spellParent->remove(spell_);
				emit(changedSpell());
			}
			break;
		case Qt::Key::Key_Minus:
			// remove : remove last
			if (QApplication::keyboardModifiers().testFlag(Qt::ControlModifier))
				spell_->removeLastChild();
			else if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
				spell_->removeLastModifier();
			else
				spell_->removeLastComponent();
			emit(changedSpell());
			break;
		case Qt::Key::Key_Plus:
		case Qt::Key::Key_Insert:
			if (QApplication::keyboardModifiers().testFlag(Qt::ShiftModifier))
				spell_->addEmptyModifier();	// adding a modifier
			else
				spell_->addEmptyComponent();	// adding a component
			emit(changedSpell());
			break;
		case Qt::Key::Key_Back:
			spell_->setRune(-1);
			image_.setPixmap(QPixmap());
			emit(changedSpell());
			break;
		case Qt::Key::Key_Enter:
		case Qt::Key::Key_Return:
			chooseRune();
			break;
		case Qt::Key::Key_Escape:
			clearFocus();
			break;
		}
	}