Beispiel #1
0
void WmfExport::paintDocument(KarbonDocument* document)
{

    // resolution
    mDpi = 1000;

    QSizeF pageSize = document->pageSize();
    int width = static_cast<int>(POINT_TO_INCH(pageSize.width()) * mDpi);
    int height = static_cast<int>(POINT_TO_INCH(pageSize.height()) * mDpi);

    mWmf->setDefaultDpi(mDpi);
    mWmf->setWindow(0, 0, width, height);

    if ((pageSize.width() != 0) && (pageSize.height() != 0)) {
        mScaleX = static_cast<double>(width) / pageSize.width();
        mScaleY = static_cast<double>(height) / pageSize.height();
    }

    QList<KoShape*> shapes = document->shapes();
    qSort(shapes.begin(), shapes.end(), KoShape::compareShapeZIndex);

    // Export layers.
    foreach(KoShape * shape, shapes) {
        if (dynamic_cast<KoShapeContainer*>(shape))
            continue;
        paintShape(shape);
    }
}
Beispiel #2
0
void CMapWidget::paintEvent(QPaintEvent *event) {
	if (!m_map || !m_patches)
		return;

	QPainter painter(this);
	if (m_zoomFactorX < 1.0f)
		painter.setRenderHint(QPainter::SmoothPixmapTransform);
	painter.scale(m_zoomFactorX, m_zoomFactorY);

	const QRect &rawRect = event->rect();
	// scale the rect, todo: extract this into a method
	QRect rect(int(rawRect.x() / m_zoomFactorX),
			   int(rawRect.y() / m_zoomFactorY),
			   int(rawRect.width() / m_zoomFactorX),
			   int(rawRect.height() / m_zoomFactorY)
			   );

	//painter.fillRect(rect, Qt::white);

	// for bounds checking, scale the rect
	int minX = qMax(0, (rect.x() / 64) - 8);
	int minY = qMax(0, (rect.y() / 16) - 16);
	int maxX = qMin(m_map->width(), (rect.right() / 64) + 8);
	int maxY = qMin(m_map->height(), (rect.bottom() / 16) + 16);

	// This code is a mess, I know.
	CMap::ObjectType toPreview = m_currentTool->typesToPreview();

	// Floors layer
	if (m_showFloors) {
		for (int y = minY; y < maxY; y++) {
			for (int x = minX; x < maxX; x++) {
				int floorNum = m_map->floors[x][y];
				if (toPreview & CMap::Floor)
					floorNum = m_currentTool->whatThingFor(CMap::Floor, x, y, floorNum);
				floorNum = m_map->randomisedFloor(x, y, floorNum);

				paintShape(painter, rect, x, y, m_patches->floors, floorNum);
			}
		}
	}

	// Regions layer
	if (m_showRegions) {
		for (int y = minY; y < maxY; y++) {
			for (int x = minX; x < maxX; x++) {
				int regionNum = m_map->regions[x][y];
				if (toPreview & CMap::Region)
					regionNum = m_currentTool->whatThingFor(CMap::Region, x, y, regionNum);

				if (regionNum > 0)
					paintShape(painter, rect, x, y, m_patches->regions, m_patches->regionIndexer.imageNumForShape(regionNum));
			}
		}
	}

	// Walking borders
	if (m_showWalkingBorders) {
		int borderLeft = 4;
		int borderRight = m_map->width() - 7;
		int borderTop = 9;
		int borderBottom = m_map->height() - 9;

		for (int y = minY; y < maxY; y++) {
			for (int x = minX; x < maxX; x++) {
				if (x < borderLeft || x > borderRight || y < borderTop || y > borderBottom) {
					painter.drawPixmap(
								screenXForPos(x, y) + 1,
								screenYForPos(y) + 63,
								walkingBorderPixmap);
				}
			}
		}
	}

	if (isHovering) {
		painter.drawPixmap(
					screenXForPos(hovered.x / 2, hovered.y) + 1,
					screenYForPos(hovered.y) + 63,
					highlightPixmap);
	}

	// Everything else
	for (int y = minY; y < maxY; y++) {
		for (int x = minX; x < maxX; x++) {
			if (m_showWalls) {
				int leftWall = m_map->walls[x*2][y];
				if (toPreview & CMap::LeftWall)
					leftWall = m_currentTool->whatThingFor(CMap::LeftWall, x*2, y, leftWall);

				if (leftWall > 0)
					paintShape(painter, rect, x, y, m_patches->walls, m_patches->wallIndexer.imageNumForShape(leftWall) + 1, -16, -8);


				int rightWall = m_map->walls[x*2+1][y];
				if (toPreview & CMap::RightWall)
					rightWall = m_currentTool->whatThingFor(CMap::RightWall, x*2+1, y, rightWall);

				if (rightWall > 0)
					paintShape(painter, rect, x, y, m_patches->walls, m_patches->wallIndexer.imageNumForShape(rightWall), 16, -8);
			}

			if (m_showItems) {
				int floorNum = m_map->floors[x][y];
				if (toPreview & CMap::Floor)
					floorNum = m_currentTool->whatThingFor(CMap::Floor, x, y, floorNum);
				floorNum = m_map->randomisedFloor(x, y, floorNum);

				int offsetX = 0, offsetY = 0;
				if (m_patches->floors.exists(floorNum)) {
					const CShape &shape = m_patches->floors[floorNum];
					const CFrame &frame = shape.frames.first();
					offsetX = frame.furrePosX;
					offsetY = frame.furrePosY;
				}

				int itemNum = m_map->items[x][y];
				if (toPreview & CMap::Item)
					itemNum = m_currentTool->whatThingFor(CMap::Item, x, y, itemNum);
				itemNum = m_map->randomisedItem(x, y, itemNum);

				if (itemNum > 0)
					paintShape(painter, rect, x, y, m_patches->items, itemNum, offsetX, offsetY);
			}


			if (m_showEffects) {
				int effectNum = m_map->effects[x][y];
				if (toPreview & CMap::Effect)
					effectNum = m_currentTool->whatThingFor(CMap::Effect, x, y, effectNum);

				if (effectNum > 0)
					paintShape(painter, rect, x, y, m_patches->effects, effectNum);
			}
		}
	}

	if (isHovering) {
		painter.drawPixmap(
					screenXForPos(hovered.x / 2, hovered.y) + 1,
					screenYForPos(hovered.y) + 63,
					highlightTransPixmap);
	}

	// Now, selections
	if (m_map->hasSelection) {
		for (int y = minY; y < maxY; y++) {
			int base = y * m_map->width();

			for (int x = minX; x < maxX; x++) {
				if (m_map->selectionMask.testBit(base + x)) {
					painter.drawPixmap(
								screenXForPos(x, y) + 1,
								screenYForPos(y) + 63,
								highlightTransPixmap);
				}
			}
		}
	}
}