void PhysGraphicsScene
::drawBackground(QPainter *painter,
const QRectF &rect
) { Q_UNUSED(rect);
int w_2 = width() / 2;
int h_2 = height() / 2;
painter -> setPen(Qt::blue);
painter -> drawLine(0, h_2, width(), h_2); // X-Axis
painter -> drawLine(w_2, 0 , w_2, height()); // Y-Axis
mtx.translate(w_2, h_2);
mtx.scale(1, -1);
painter -> setMatrix(mtx);
painter -> setPen(Qt::NoPen);
painter
-> setBrush
(QBrush(Qt
::blue, Qt
::Dense4Pattern));
painter -> drawRect(-10, -10, 20, 20);
QLineF y_axis
(-10,
-10,
-10,
10);
QLineF x_axis
(-10,
-10,
10,
-10);
QLineF angleLine1, angleLine2;
pen.setWidth(2);
pen.setColor(Qt::red);
painter -> setPen(pen);
setupAngleLine(angleLine1, x_axis.p2(), x_axis.p1(), 135.0);
setupAngleLine(angleLine2, x_axis.p2(), x_axis.p1(), -135.0);
painter -> drawLine(x_axis); // X-Axis
painter -> drawLine(angleLine1);
painter -> drawLine(angleLine2);
pen.setColor(Qt::green);
setupAngleLine(angleLine1, y_axis.p2(), y_axis.p1(), 45.0);
setupAngleLine(angleLine2, y_axis.p2(), y_axis.p1(), 135.0);
painter -> setPen(pen);
painter -> drawLine(y_axis); // Y-Axis
painter -> drawLine(angleLine1);
painter -> drawLine(angleLine2);
if (m_Mode == InsertLine && m_pLine)
drawAngledPlane(painter);
}
void PhysGraphicsScene
::drawAngledPlane(QPainter *painter
) { QPointF lineMidPoint
= findLineMidPoint
(m_pLine
->line
());
QRectF lineRect
(m_pLine
->line
().
p1(), m_pLine
->line
().
p2());
// Draw the temporary cartesian axis' origin'ed at p1 of the line
pen.setStyle(Qt::DashDotDotLine);
pen.setWidth(2);
painter ->setPen(pen);
xAxis.setAngle(90);
xAxis.
setP1(m_pLine
->line
().
p1()); xAxis.
setP2(QPointF(m_pLine
->line
().
dx(),
0));
xAxis.setLength(m_pLine ->line().dx());
yAxis.setAngle(0);
yAxis.setLength(m_pLine ->line().dy());
painter -> drawLine(xAxis); // x-axis
painter -> drawLine(yAxis); // y-axis
// Draw the arc from the false cartesian axis to the line
double angle = m_pLine ->line().angle();
}
void PhysGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect) {
Q_UNUSED(rect);
QMatrix mtx;
int w_2 = width() / 2;
int h_2 = height() / 2;
painter -> setPen(Qt::blue);
painter -> drawLine(0, h_2, width(), h_2); // X-Axis
painter -> drawLine(w_2, 0 , w_2, height()); // Y-Axis
mtx.translate(w_2, h_2);
mtx.scale(1, -1);
painter -> setMatrix(mtx);
painter -> setPen(Qt::NoPen);
painter -> setBrush(QBrush(Qt::blue, Qt::Dense4Pattern));
painter -> drawRect(-10, -10, 20, 20);
QLineF y_axis(-10, -10, -10, 10);
QLineF x_axis(-10, -10, 10, -10);
QPen pen;
QLineF angleLine1, angleLine2;
pen.setWidth(2);
pen.setColor(Qt::red);
painter -> setPen(pen);
setupAngleLine(angleLine1, x_axis.p2(), x_axis.p1(), 135.0);
setupAngleLine(angleLine2, x_axis.p2(), x_axis.p1(), -135.0);
painter -> drawLine(x_axis); // X-Axis
painter -> drawLine(angleLine1);
painter -> drawLine(angleLine2);
pen.setColor(Qt::green);
setupAngleLine(angleLine1, y_axis.p2(), y_axis.p1(), 45.0);
setupAngleLine(angleLine2, y_axis.p2(), y_axis.p1(), 135.0);
painter -> setPen(pen);
painter -> drawLine(y_axis); // Y-Axis
painter -> drawLine(angleLine1);
painter -> drawLine(angleLine2);
if (m_Mode == InsertLine && m_pLine)
drawAngledPlane(painter);
}
void PhysGraphicsScene::drawAngledPlane(QPainter *painter) {
QPointF lineMidPoint = findLineMidPoint(m_pLine ->line());
QRectF lineRect(m_pLine ->line().p1(), m_pLine ->line().p2());
// Draw the temporary cartesian axis' origin'ed at p1 of the line
QPen pen(Qt::lightGray);
pen.setStyle(Qt::DashDotDotLine);
pen.setWidth(2);
painter ->setPen(pen);
QLineF xAxis, yAxis;
xAxis.setAngle(90);
xAxis.setP1(m_pLine ->line().p1()); xAxis.setP2(QPointF(m_pLine ->line().dx(), 0));
xAxis.setLength(m_pLine ->line().dx());
yAxis.setAngle(0);
yAxis.setLength(m_pLine ->line().dy());
painter -> drawLine(xAxis); // x-axis
painter -> drawLine(yAxis); // y-axis
// Draw the arc from the false cartesian axis to the line
double angle = m_pLine ->line().angle();
}
To copy to clipboard, switch view to plain text mode
Bookmarks