summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBen Boeckel <MathStuf@gmail.com>2009-04-02 02:48:17 -0400
committerBen Boeckel <MathStuf@gmail.com>2009-04-02 02:48:17 -0400
commit0e53a2121587feaa78c7e1ecaeb5d5ea0501c129 (patch)
tree68a768c2057fcf31b6d4130ced36d831078b2813
parent5eed3bab26059b73d2ff38522e560fef6b9d2680 (diff)
Fix the map grid to be more flexible
-rw-r--r--sigmodr/widgets/mapeditor/MapGrid.cpp30
-rw-r--r--sigmodr/widgets/mapeditor/MapGrid.h8
2 files changed, 20 insertions, 18 deletions
diff --git a/sigmodr/widgets/mapeditor/MapGrid.cpp b/sigmodr/widgets/mapeditor/MapGrid.cpp
index 5f0b3375..b5d95ed5 100644
--- a/sigmodr/widgets/mapeditor/MapGrid.cpp
+++ b/sigmodr/widgets/mapeditor/MapGrid.cpp
@@ -26,9 +26,8 @@
using namespace Sigmodr::Widgets;
-MapGrid::MapGrid() :
- m_width(0),
- m_height(0),
+MapGrid::MapGrid(const int fringe) :
+ m_fringe(fringe),
m_gridSize(0)
{
setZValue(INT_MIN);
@@ -36,7 +35,7 @@ MapGrid::MapGrid() :
QRectF MapGrid::boundingRect() const
{
- return QRect(-5, -5, m_width + 10, m_height + 10);
+ return m_rect.adjusted(-m_fringe, -m_fringe, m_fringe, m_fringe);
}
void MapGrid::paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget)
@@ -48,25 +47,28 @@ void MapGrid::paint(QPainter* painter, const QStyleOptionGraphicsItem* options,
{
painter->save();
painter->setOpacity(.25);
- for (int i = 0; i < m_width; i += m_gridSize)
- painter->drawLine(i, -5, i, m_height + 5);
- painter->drawLine(m_width, -5, m_width, m_height + 5);
- for (int i = 0; i < m_height; i += m_gridSize)
- painter->drawLine(-5, i, m_width + 5, i);
- painter->drawLine(-5, m_height, m_width + 5, m_height);
+ const int top = m_rect.top() - m_fringe;
+ const int bottom = m_rect.bottom() + m_fringe;
+ const int left = m_rect.left() - m_fringe;
+ const int right = m_rect.right() + m_fringe;
+ for (int i = m_rect.left(); i < m_rect.right(); i += m_gridSize)
+ painter->drawLine(i, top, i, bottom);
+ painter->drawLine(m_rect.right(), top, m_rect.right(), bottom);
+ for (int i = m_rect.top(); i < m_rect.bottom(); i += m_gridSize)
+ painter->drawLine(left, i, right, i);
+ painter->drawLine(left, m_rect.bottom(), right, m_rect.bottom());
painter->setOpacity(1);
painter->restore();
}
painter->setPen(QPen(Qt::red, 3));
- painter->drawRect(QRect(0, 0, m_width, m_height));
+ painter->drawRect(m_rect);
painter->restore();
}
-void MapGrid::setSize(const int width, const int height)
+void MapGrid::setRect(const QRectF& rect)
{
prepareGeometryChange();
- m_width = width;
- m_height = height;
+ m_rect = rect.toRect();
update();
}
diff --git a/sigmodr/widgets/mapeditor/MapGrid.h b/sigmodr/widgets/mapeditor/MapGrid.h
index 43a79afe..aceab753 100644
--- a/sigmodr/widgets/mapeditor/MapGrid.h
+++ b/sigmodr/widgets/mapeditor/MapGrid.h
@@ -31,16 +31,16 @@ namespace Widgets
class SIGMODRWIDGETS_NO_EXPORT MapGrid : public QGraphicsItem
{
public:
- MapGrid();
+ MapGrid(const int fringe = 5);
QRectF boundingRect() const;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* options, QWidget* widget);
- void setSize(const int width, const int height);
+ void setRect(const QRectF& rect);
void setGridSize(const int gridSize);
private:
- int m_width;
- int m_height;
+ QRect m_rect;
+ int m_fringe;
int m_gridSize;
};
}