Exemplo n.º 1
0
 void handleEvent(SDL_Event evt) {
     /* Left Ctrl+s -> Save level
      * Delete -> delete current block
      * Space -> Make current block draggable
      * Arrow keys -> Set direction of current block
      * Any valid letter -> create block of that type
      */
     
     if(evt.type != SDL_KEYDOWN) return;
     
     if(evt.key.keysym.mod & KMOD_LCTRL && evt.key.keysym.sym == SDLK_s) {
         saveLevel();
     }
     
     else if(evt.key.keysym.sym == SDLK_DELETE) {
         deleteBlock();
     }
     
     else {
         switch(evt.key.keysym.sym) {
             case SDLK_UP:
                 setBlockDirection(rtBlock::UP);
                 break;
             case SDLK_DOWN:
                 setBlockDirection(rtBlock::DOWN);
                 break;
             case SDLK_RIGHT:
                 setBlockDirection(rtBlock::RIGHT);
                 break;
             case SDLK_LEFT:
                 setBlockDirection(rtBlock::LEFT);
                 break;
                 
             case SDLK_SPACE:
                 setDraggable();
                 break;
                 
             default:setBlock(evt.key.keysym.sym);
         }
     }
 }
Exemplo n.º 2
0
void RTF::Reader::read(QIODevice* device, QTextDocument* text)
{
	try {
		// Open file
		m_text = 0;
		if (!m_cursor.isNull()) {
			m_cursor = QTextCursor();
		}
		m_text = text;
		m_cursor = QTextCursor(m_text);
		m_cursor.movePosition(QTextCursor::End);
		m_token.setDevice(device);
		setBlockDirection(Qt::LeftToRight);

		// Check file type
		m_token.readNext();
		if (m_token.type() == StartGroupToken) {
			pushState();
		} else {
			throw tr("Not a supported RTF file.");
		}
		m_token.readNext();
		if (m_token.type() != ControlWordToken || m_token.text() != "rtf" || m_token.value() != 1) {
			throw tr("Not a supported RTF file.");
		}

		// Parse file contents
		while (!m_states.isEmpty() && m_token.hasNext()) {
			m_token.readNext();

			if ((m_token.type() != EndGroupToken) && !m_in_block) {
				m_cursor.insertBlock();
				m_in_block = true;
			}

			if (m_token.type() == StartGroupToken) {
				pushState();
			} else if (m_token.type() == EndGroupToken) {
				popState();
			} else if (m_token.type() == ControlWordToken) {
				if (!m_state.ignore_control_word && functions.contains(m_token.text())) {
					functions[m_token.text()].call(this, m_token);
				}
			} else if (m_token.type() == TextToken) {
				if (!m_state.ignore_text) {
					m_cursor.insertText(m_codec->toUnicode(m_token.text()));
				}
			}
		}
	} catch (const QString& error) {
		m_error = error;
	}
}