예제 #1
0
void CanvasModel::handleCommand(protocol::MessagePtr cmd)
{
	using namespace protocol;

	// Apply ACL filter
	if(!m_aclfilter->filterMessage(*cmd)) {
		qDebug("Filtered message %d from %d", cmd->type(), cmd->contextId());
		return;
	}

	if(cmd->isMeta()) {
		// Handle meta commands here
		switch(cmd->type()) {
		case MSG_CHAT:
			metaChat(cmd.cast<Chat>());
			break;
		case MSG_USER_JOIN:
			metaUserJoin(cmd.cast<UserJoin>());
			break;
		case MSG_USER_LEAVE:
			metaUserLeave(cmd.cast<UserLeave>());
			break;
		case MSG_SESSION_OWNER:
		case MSG_USER_ACL:
		case MSG_SESSION_ACL:
		case MSG_LAYER_ACL:
			// Handled by the ACL filter
			break;
		case MSG_INTERVAL:
			/* intervals are used only when playing back recordings */
			break;
		case MSG_LASERTRAIL:
			metaLaserTrail(cmd.cast<protocol::LaserTrail>());
			break;
		case MSG_MOVEPOINTER:
			metaMovePointer(cmd.cast<MovePointer>());
			break;
		case MSG_MARKER:
			metaMarkerMessage(cmd.cast<Marker>());
			break;
		default:
			qWarning("Unhandled meta message type %d", cmd->type());
		}

	} else if(cmd->isCommand()) {
		// The state tracker handles all drawing commands
		m_statetracker->receiveQueuedCommand(cmd);
		emit canvasModified();

	} else {
		qWarning("CanvasModel::handleDrawingCommand: command %d is neither Meta nor Command type!", cmd->type());
	}
}
예제 #2
0
void IndexBuilder::addToIndex(const protocol::MessagePtr msg)
{
	IndexType type = IDX_NULL;
	QString title;
	quint32 color = _colors[msg->contextId()];

	switch(msg->type()) {
	using namespace protocol;
	case MSG_CANVAS_RESIZE: type = IDX_RESIZE; break;

	case MSG_LAYER_CREATE: type = IDX_CREATELAYER; break;

	case MSG_LAYER_DELETE: type = IDX_DELETELAYER; break;
	case MSG_PUTIMAGE: type = IDX_PUTIMAGE; break;

	case MSG_PEN_MOVE:
	case MSG_PEN_UP: type = IDX_STROKE; break;

	case MSG_TOOLCHANGE:
		_colors[msg->contextId()] = msg.cast<const protocol::ToolChange>().color();
		break;

	case MSG_ANNOTATION_CREATE:
	case MSG_ANNOTATION_DELETE:
	case MSG_ANNOTATION_EDIT:
	case MSG_ANNOTATION_RESHAPE: type = IDX_ANNOTATE; break;

	case MSG_UNDO:
		if(msg.cast<const protocol::Undo>().points() > 0)
			type = IDX_UNDO;
		else
			type = IDX_REDO;
		break;

	case MSG_FILLRECT:
		type = IDX_FILL;
		color = msg.cast<const protocol::FillRect>().color();
		break;

	case MSG_CHAT:
		type = IDX_CHAT;
		title = msg.cast<const protocol::Chat>().message().left(32);
		break;

	case MSG_INTERVAL: type = IDX_PAUSE; break;

	case MSG_MOVEPOINTER: type = IDX_LASER; break;

	case MSG_MARKER:
		type = IDX_MARKER;
		title = msg.cast<const protocol::Marker>().text();
		break;

	case MSG_USER_JOIN:
		m_index.m_ctxnames[msg->contextId()] = msg.cast<const protocol::UserJoin>().name();
		return;

	default: break;
	}

	if(type==IDX_NULL) {
		return;

	} else if(type==IDX_PUTIMAGE || type==IDX_ANNOTATE) {
		// Combine consecutive messages from the same user
		for(int i=m_index.m_index.size()-1;i>=0;--i) {
			IndexEntry &e = m_index.m_index[i];
			if(e.context_id == msg->contextId()) {
				if(e.type == type) {
					e.end = _pos;
					return;
				}
				break;
			}
		}

	} else if(type==IDX_LASER) {
		// Combine laser pointer strokes
		for(int i=m_index.m_index.size()-1;i>=0;--i) {
			IndexEntry &e = m_index.m_index[i];
			if(e.context_id == msg->contextId()) {
				if(!(e.flags & IndexEntry::FLAG_FINISHED)) {
					e.end = _pos;
					if(msg->type() == protocol::MSG_LASERTRAIL)
						e.flags |= IndexEntry::FLAG_FINISHED;
					return;
				}
				break;
			}
		}

	} else if(type==IDX_STROKE) {
		// Combine all strokes up to last pen-up from the same user
		for(int i=m_index.m_index.size()-1;i>=0;--i) {
			IndexEntry &e = m_index.m_index[i];
			if(e.context_id == msg->contextId() && e.type == IDX_STROKE) {
				if(!(e.flags & IndexEntry::FLAG_FINISHED)) {
					e.end = _pos;
					if(msg->type() == protocol::MSG_PEN_UP)
						e.flags |= IndexEntry::FLAG_FINISHED;
					return;
				}
				break;
			}
		}
	}

	// New index entry
	m_index.m_index.append(IndexEntry(type, msg->contextId(), _offset, _pos, _pos, color, title));
}