Exemplo n.º 1
0
QList<MessagePtr> BlankCanvasLoader::loadInitCommands()
{
	QList<MessagePtr> msgs;

	msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, _size.width(), _size.height(), 0)));
	msgs.append(MessagePtr(new protocol::LayerCreate(1, 1, 0, _color.rgba(), 0, QGuiApplication::tr("Background"))));
	msgs.append(MessagePtr(new protocol::LayerCreate(1, 2, 0, 0, 0, QGuiApplication::tr("Foreground"))));
	return msgs;
}
Exemplo n.º 2
0
QList<MessagePtr> ImageCanvasLoader::loadInitCommands()
{
	if(m_filename.endsWith(".ora", Qt::CaseInsensitive)) {
		// Load OpenRaster image
		// TODO identify by filetype magic?
		openraster::OraResult ora = openraster::loadOpenRaster(m_filename);

		if(!ora.error.isEmpty()) {
			m_error = ora.error;
			return QList<MessagePtr>();
		}

		if(ora.warnings != openraster::OraResult::NO_WARNINGS) {
			QString text = QGuiApplication::tr("Drawpile does not support all the features used in this OpenRaster file. Saving this file may result in data loss.\n");
			if((ora.warnings & openraster::OraResult::ORA_EXTENDED))
				text += "\n- " + QGuiApplication::tr("Application specific extensions are used");
			if((ora.warnings & openraster::OraResult::ORA_NESTED))
				text += "\n- " + QGuiApplication::tr("Nested layers are not fully supported.");

			m_warning = text;
		}
		return ora.commands;

	} else {
		// Load an image using Qt's image loader.
		// If the image is animated, each frame is loaded as a layer
		QList<MessagePtr> msgs;
		QImageReader ir(m_filename);
		int layerId = 1;

		while(true) {
			QImage image = ir.read();

			if(image.isNull()) {
				if(layerId>1)
					break;
				m_error = ir.errorString();
				return QList<MessagePtr>();
			}

			if(layerId==1) {
				msgs << MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0));
			}

			image = image.convertToFormat(QImage::Format_ARGB32);
			msgs << MessagePtr(new protocol::LayerCreate(1, layerId, 0, 0, 0, QStringLiteral("Layer %1").arg(layerId)));
			msgs << net::command::putQImage(1, layerId, 0, 0, image, paintcore::BlendMode::MODE_REPLACE);
			++layerId;
		}

		return msgs;
	}
}
Exemplo n.º 3
0
QList<MessagePtr> QImageCanvasLoader::loadInitCommands()
{
	QList<MessagePtr> msgs;

	QImage image = _image.convertToFormat(QImage::Format_ARGB32);

	msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0)));
	msgs.append(MessagePtr(new protocol::LayerCreate(1, 1, 0, 0, 0, "Background")));
	msgs.append(net::command::putQImage(1, 1, 0, 0, image, paintcore::BlendMode::MODE_REPLACE));

	return msgs;
}
Exemplo n.º 4
0
void Session::removeUser(Client *user)
{
	Q_ASSERT(m_clients.contains(user));

	if(user->id() == m_initUser && m_state == Reset) {
		// Whoops, the resetter left before the job was done!
		// We simply cancel the reset in that case and go on
		m_initUser = 0;
		m_resetstream.clear();
		switchState(Running);
	}

	m_clients.removeOne(user);

	addToCommandStream(MessagePtr(new protocol::UserLeave(user->id())));

	ensureOperatorExists();

	// Reopen the session when the last user leaves
	if(m_clients.isEmpty()) {
		setClosed(false);
	}

	user->deleteLater();

	m_lastEventTime = QDateTime::currentDateTime();

	emit userDisconnected(this);
}
Exemplo n.º 5
0
void Client::sendSystemChat(const QString &message)
{
	protocol::ServerReply msg {
		protocol::ServerReply::MESSAGE,
		message,
		QJsonObject()
	};

	d->msgqueue->send(MessagePtr(new protocol::Command(0, msg.toJson())));
}
Exemplo n.º 6
0
QList<MessagePtr> SnapshotLoader::loadInitCommands()
{
	QList<MessagePtr> msgs;

	// Most important bit first: canvas initialization
	const QSize imgsize = m_layers->size();
	msgs.append(MessagePtr(new protocol::CanvasResize(m_contextId, 0, imgsize.width(), imgsize.height(), 0)));

	// Preset default layer
	if(m_session && m_session->layerlist()->defaultLayer()>0)
		msgs.append(MessagePtr(new protocol::DefaultLayer(m_contextId, m_session->layerlist()->defaultLayer())));

	// Create layers
	for(int i=0;i<m_layers->layerCount();++i) {
		const paintcore::Layer *layer = m_layers->getLayerByIndex(i);

		const QColor fill = layer->isSolidColor();

		msgs.append(MessagePtr(new protocol::LayerCreate(m_contextId, layer->id(), 0, fill.isValid() ? fill.rgba() : 0, 0, layer->title())));
		msgs.append(MessagePtr(new protocol::LayerAttributes(m_contextId, layer->id(), layer->opacity(), 1)));

		if(!fill.isValid())
			msgs.append(net::command::putQImage(m_contextId, layer->id(), 0, 0, layer->toImage(), paintcore::BlendMode::MODE_REPLACE));

		if(m_session && m_session->stateTracker()->isLayerLocked(layer->id()))
			msgs.append(MessagePtr(new protocol::LayerACL(m_contextId, layer->id(), true, QList<uint8_t>())));
	}

	// Create annotations
	for(const paintcore::Annotation &a : m_layers->annotations()->getAnnotations()) {
		const QRect g = a.rect;
		msgs.append(MessagePtr(new protocol::AnnotationCreate(m_contextId, a.id, g.x(), g.y(), g.width(), g.height())));
		msgs.append((MessagePtr(new protocol::AnnotationEdit(m_contextId, a.id, a.background.rgba(), 0, 0, a.text))));
	}

	// User tool changes
	if(m_session) {
		QHashIterator<int, canvas::DrawingContext> iter(m_session->stateTracker()->drawingContexts());
		while(iter.hasNext()) {
			iter.next();

			msgs.append(net::command::brushToToolChange(
				iter.key(),
				iter.value().tool.layer_id,
				iter.value().tool.brush
			));
		}
	}

	return msgs;
}
Exemplo n.º 7
0
QList<MessagePtr> SnapshotLoader::loadInitCommands()
{
	QList<MessagePtr> msgs;

	// Most important bit first: canvas initialization
	const QSize imgsize = _session->image()->size();
	msgs.append(MessagePtr(new protocol::CanvasResize(1, 0, imgsize.width(), imgsize.height(), 0)));

	// Less important, but it's nice to see it straight away
	if(!_session->title().isEmpty())
		msgs.append((MessagePtr(new protocol::SessionTitle(1, _session->title()))));

	// Create layers
	for(int i=0;i<_session->image()->layers();++i) {
		const paintcore::Layer *layer = _session->image()->getLayerByIndex(i);
		msgs.append(MessagePtr(new protocol::LayerCreate(1, layer->id(), 0, 0, 0, layer->title())));
		msgs.append(MessagePtr(new protocol::LayerAttributes(1, layer->id(), layer->opacity(), 1)));
		msgs.append(net::putQImage(1, layer->id(), 0, 0, layer->toImage(), paintcore::BlendMode::MODE_REPLACE));
		if(_session->isLayerLocked(layer->id()))
			msgs.append(MessagePtr(new protocol::LayerACL(1, layer->id(), true, QList<uint8_t>())));
	}

	// Create annotations
	foreach(const paintcore::Annotation *a, _session->image()->annotations()) {
		const QRect g = a->rect();
		msgs.append(MessagePtr(new protocol::AnnotationCreate(1, a->id(), g.x(), g.y(), g.width(), g.height())));
		msgs.append((MessagePtr(new protocol::AnnotationEdit(1, a->id(), a->backgroundColor().rgba(), a->text()))));
	}

	// User tool changes
	QHashIterator<int, drawingboard::DrawingContext> iter(_session->drawingContexts());
	while(iter.hasNext()) {
		iter.next();

		msgs.append(net::brushToToolChange(
			iter.key(),
			iter.value().tool.layer_id,
			iter.value().tool.brush
		));
	}

	return msgs;
}
Exemplo n.º 8
0
void Client::sendChat(const QString &message, bool announce, bool action)
{
	_server->sendMessage(MessagePtr(new protocol::Chat(m_myId, message, announce, action)));
}
Exemplo n.º 9
0
QList<MessagePtr> ImageCanvasLoader::loadInitCommands()
{
	if(_filename.endsWith(".ora", Qt::CaseInsensitive)) {
		// Load OpenRaster image
		using openraster::Reader;
		// TODO identify by filetype magic?
		Reader reader;

		if(reader.load(_filename) == false) {
			_error = reader.error();
			return QList<MessagePtr>();
		}

		if(reader.warnings() != Reader::NO_WARNINGS) {
			QString text = QApplication::tr("Drawpile does not support all the features used in this OpenRaster file. Saving this file may result in data loss.\n");
			if((reader.warnings() & Reader::ORA_EXTENDED))
				text += "\n- " + QApplication::tr("Application specific extensions are used");
			if((reader.warnings() & Reader::ORA_NESTED))
				text += "\n- " + QApplication::tr("Nested layers are not fully supported.");
			QMessageBox::warning(0, QApplication::tr("Partially supported OpenRaster"), text);
		}
		return reader.initCommands();
	} else if(_filename.endsWith(".dptxt", Qt::CaseInsensitive)) {
		TextCommandLoader txt(filename());

		if(!txt.load()) {
			_error = txt.errorMessage();
			return QList<MessagePtr>();
		}

		return txt.loadInitCommands();
	} else {
		// Load an image using Qt's image loader.
		// If the image is animated, each frame is loaded as a layer
		QList<MessagePtr> msgs;
		QImageReader ir(_filename);
		int layerId = 1;

		while(true) {
			QImage image = ir.read();

			if(image.isNull()) {
				if(layerId>1)
					break;
				_error = ir.errorString();
				return QList<MessagePtr>();
			}

			if(layerId==1) {
				msgs << MessagePtr(new protocol::CanvasResize(1, 0, image.size().width(), image.size().height(), 0));
			}

			image = image.convertToFormat(QImage::Format_ARGB32);
			msgs << MessagePtr(new protocol::LayerCreate(1, layerId, 0, 0, 0, QStringLiteral("Layer %1").arg(layerId)));
			msgs << net::putQImage(1, layerId, 0, 0, image, paintcore::BlendMode::MODE_REPLACE);
			++layerId;
		}

		return msgs;
	}
}