Commit 068ae9df authored by Alexander Schuch's avatar Alexander Schuch
Browse files

Center board vertically if required.

The board is centered horizontally already in case the board is tall. If
it is wide however, it still is aligned to the top leaving empty space
just at the bottom. This patch vertically centers a wide board.

Remove a work-around for Qt 4.6; Qt 4.8 is required and there is no
visible difference without that work-around.

The element "screen" had a transparent bar at the upper edge and
adjustments were done in the code to hide it. As the element has been
fixed, the adjustments can be removed.

REVIEW: 114851
GUI:
parent 9cc27c23
......@@ -76,7 +76,7 @@ QRectF PlanetItem::boundingRect() const
{
qreal size = m_scene->getSectorSize();
return QRectF(m_sector->coord().y() * size + m_scene->itemsHorizontalOffset(),
m_sector->coord().x() * size,
m_sector->coord().x() * size + m_scene->itemsVerticalOffset(),
size,
size);
}
......@@ -101,7 +101,7 @@ void PlanetItem::paint(QPainter *p, const QStyleOptionGraphicsItem * /*option*/,
// Display the planet
qreal sectorSize = m_scene->getSectorSize();
QPointF sectorTopLeft(m_sector->coord().y() * sectorSize + m_scene->itemsHorizontalOffset(),
m_sector->coord().x() * sectorSize);
m_sector->coord().x() * sectorSize + m_scene->itemsVerticalOffset());
QPixmap planetPix = renderPixmap(m_lookName, sectorSize, sectorSize);
p->drawPixmap(sectorTopLeft, planetPix);
......
......@@ -141,14 +141,12 @@ MapScene::planetItemSelected (PlanetItem *item)
void
MapScene::drawBackground ( QPainter * painter, const QRectF & /*rect*/ )
{
// NOTE: without this line, background is black when using Qt 4.6! Qt bug?
painter->setCompositionMode( QPainter::CompositionMode_SourceOver );
qreal sectorSize = getSectorSize();
qreal horizontalOffset = itemsHorizontalOffset();
qreal verticalOffset = itemsVerticalOffset();
qreal m_sectorSize = getSectorSize();
qreal m_horizontalOffset = itemsHorizontalOffset();
qreal mapWidth = map()->columns()*m_sectorSize;
qreal mapHeight = map()->rows()*m_sectorSize;
qreal mapWidth = map()->columns()*sectorSize;
qreal mapHeight = map()->rows()*sectorSize;
QPen pen = painter->pen();
pen.setColor(Qt::black);
......@@ -157,14 +155,16 @@ MapScene::drawBackground ( QPainter * painter, const QRectF & /*rect*/ )
painter->setPen(pen);
painter->fillRect(0, 0, m_width, m_height, Qt::black);
m_renderer->render(painter, "background", QRectF(0, 0, m_width, m_height));
m_renderer->render(painter, "screen", QRectF(m_horizontalOffset, -5, mapWidth, mapHeight + 5));
m_renderer->render(painter, "screen", QRectF(horizontalOffset, verticalOffset, mapWidth, mapHeight));
painter->setOpacity(0.5);
qreal lastLine = mapWidth + m_horizontalOffset;
for (qreal i = m_horizontalOffset ; i <= lastLine ; i += m_sectorSize) {
painter->drawLine(QPointF(i, 0), QPointF(i, mapHeight));
qreal lastLine = mapWidth + horizontalOffset;
for (qreal i = horizontalOffset ; i <= lastLine ; i += sectorSize) {
painter->drawLine(QPointF(i, verticalOffset), QPointF(i, mapHeight + verticalOffset));
}
for (qreal j = 0 ; j <= mapHeight ; j += m_sectorSize) {
painter->drawLine(QPointF(m_horizontalOffset, j), QPointF(mapWidth + m_horizontalOffset, j));
lastLine = mapHeight + verticalOffset;
for (qreal j = verticalOffset ; j <= lastLine ; j += sectorSize) {
painter->drawLine(QPointF(horizontalOffset, j), QPointF(mapWidth + horizontalOffset, j));
}
}
......@@ -187,7 +187,7 @@ MapScene::displayPlanetInfo(Planet *planet)
QPointF pos(
planet->sector()->coord().y() * getSectorSize() + itemsHorizontalOffset(),
planet->sector()->coord().x() * getSectorSize()
planet->sector()->coord().x() * getSectorSize() + itemsVerticalOffset()
);
displayPlanetInfo(planet, pos);
......@@ -241,3 +241,10 @@ MapScene::itemsHorizontalOffset()
{
return (m_width - map()->columns() * getSectorSize()) / 2;
}
qreal
MapScene::itemsVerticalOffset()
{
return (m_height - map()->rows() * getSectorSize()) / 2;
}
......@@ -63,6 +63,7 @@ class MapScene: public QGraphicsScene
void drawBackground( QPainter * painter, const QRectF & rect );
qreal itemsHorizontalOffset();
qreal itemsVerticalOffset();
qreal getSectorSize();
void resizeScene(const QRectF& rect);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment