1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
void GraphicsView::drawBackground(QPainter* painter, const QRectF& rect)
{
// Space between lines
const int space = qRound(50.0 / m_Scale);
const int startH = qCeil(rect.top() / space);
const int endH = qFloor(rect.bottom() / space);
const int startV = qCeil(rect.left() / space);
const int endV = qFloor(rect.right() / space);
QVector<QLineF> linesMain;
QVector<QLineF> linesSecond;
// Horizontal lines
for (int i=startH;i<=endH;i++)
{
int y = i * space;
if ( i==0)
{
linesMain.push_back(QLineF(rect.left(), y, rect.right(), y));
}
else
{
linesSecond.push_back(QLineF(rect.left(), y, rect.right(), y));
}
}
// Vertical lines
for (int j=startV;j<=endV;j++)
{
int x = j * space;
if ( j==0)
{
linesMain.push_back(QLineF(x, rect.top(), x, rect.bottom()-fontSize));
}
else
{
linesSecond.push_back(QLineF(x, rect.top(), x, rect.bottom()-fontSize));
}
}
painter->setPen(m_PenMainAxis);
painter->drawLines(linesMain);
painter->setPen(m_PenSecondAxis);
painter->drawLines(linesSecond);
} |
Partager