Git commit 068ae9dfb653a39740d45042d9daff0fcb627c38 by Alexander Schuch. Committed on 04/01/2014 at 12:01. Pushed by aschuch into branch 'master'.
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: M +2 -2 map/mapitems.cc M +21 -14 map/mapscene.cc M +1 -0 map/mapscene.h http://commits.kde.org/konquest/068ae9dfb653a39740d45042d9daff0fcb627c38 diff --git a/map/mapitems.cc b/map/mapitems.cc index 2216dda..3c2a5e3 100644 --- a/map/mapitems.cc +++ b/map/mapitems.cc @@ -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); diff --git a/map/mapscene.cc b/map/mapscene.cc index ba53c23..015c2dd 100644 --- a/map/mapscene.cc +++ b/map/mapscene.cc @@ -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; +} diff --git a/map/mapscene.h b/map/mapscene.h index 79666be..15fa16a 100644 --- a/map/mapscene.h +++ b/map/mapscene.h @@ -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);
