Ejemplo n.º 1
0
void BooleanTool::pathObjectToPolygons(
        const PathObject* object,
        ClipperLib::Paths& polygons,
        PolyMap& polymap)
{
	object->update();
	
	polygons.reserve(polygons.size() + object->parts().size());
	
	for (const auto& part : object->parts())
	{
		const PathCoordVector& path_coords = part.path_coords;
		auto path_coords_end = path_coords.size();
		if (part.isClosed())
			--path_coords_end;
		
		ClipperLib::Path polygon;
		for (auto i = 0u; i < path_coords_end; ++i)
		{
			auto point = MapCoord { path_coords[i].pos };
			polygon.push_back(ClipperLib::IntPoint(point.nativeX(), point.nativeY()));
			polymap.insertMulti(polygon.back(), std::make_pair(&part, &path_coords[i]));
		}
		
		bool orientation = Orientation(polygon);
		if ( (&part == &object->parts().front()) != orientation )
		{
			std::reverse(polygon.begin(), polygon.end());
		}
		
		// Push_back shall move the polygon.
		static_assert(std::is_nothrow_move_constructible<ClipperLib::Path>::value, "ClipperLib::Path must be nothrow move constructible");
		polygons.push_back(polygon);
	}
}
Ejemplo n.º 2
0
void TemplateTransform::load(QXmlStreamReader& xml)
{
	Q_ASSERT(xml.name() == "transformation");
	
	XmlElementReader element { xml };
	auto x64 = element.attribute<qint64>(QLatin1String("x"));
	auto y64 = element.attribute<qint64>(QLatin1String("y"));
	auto coord = MapCoord::fromNative64withOffset(x64, y64);
	template_x = coord.nativeX();
	template_y = coord.nativeY();
	template_scale_x = element.attribute<double>(QLatin1String("scale_x"));
	template_scale_y = element.attribute<double>(QLatin1String("scale_y"));
	template_rotation = element.attribute<double>(QLatin1String("rotation"));
}
Ejemplo n.º 3
0
bool DrawTextTool::mouseReleaseEvent(QMouseEvent* event, MapCoordF map_coord, MapWidget* widget)
{
	if (text_editor)
	{
		if (text_editor->mouseReleaseEvent(event, map_coord, widget))
			return true;
		else
		{
			cur_pos = event->pos();
			cur_pos_map = map_coord;
			finishEditing();
			return true;
		}
	}
	
	if (event->button() != Qt::LeftButton)
		return false;
	
	if (dragging)
	{
		// Create box text
		double width = qAbs(cur_pos_map.x() - click_pos_map.x());
		double height = qAbs(cur_pos_map.y() - click_pos_map.y());
		auto midpoint = MapCoord { 0.5 * (cur_pos_map + click_pos_map) };
		preview_text->setBox(midpoint.nativeX(), midpoint.nativeY(), width, height);
		
		dragging = false;
		updateDirtyRect();
	}
	else
		setPreviewLetter();
	
	preview_text->setText("");

	// Create the TextObjectEditor
	text_editor = new TextObjectEditorHelper(preview_text, editor);
	connect(text_editor, SIGNAL(selectionChanged(bool)), this, SLOT(selectionChanged(bool)));
	
	updatePreviewText();
	updateStatusText();
	
	return true;
}