Корректировка координатной сетки

main
Артём Проскурнёв 4 years ago
parent 16db5c08b3
commit a2dd5b77c4
  1. 2
      main.cpp
  2. 36
      qtsgraph.cpp

@ -11,6 +11,7 @@ int main(int argc, char *argv[])
*/ */
QTSGraph w(600, 600); QTSGraph w(600, 600);
//w.SwapYAxis = true;
w.show(); w.show();
return a.exec(); return a.exec();
} }
@ -19,7 +20,6 @@ void QTSGraph::PaintBox()
{ {
// Начало рисования // Начало рисования
ShowAxes();
SetColor(clGreen); SetColor(clGreen);
Line(0, 0, 600, 600); Line(0, 0, 600, 600);
SetColor(0xFF0000); SetColor(0xFF0000);

@ -267,13 +267,10 @@ void QTSGraph::paintEvent(QPaintEvent *event)
{ {
QPainter p(this); QPainter p(this);
p.drawPixmap(0, 0, Canvas); p.drawPixmap(0, 0, Canvas);
int correctY = 0;
int mult = 1;
if(AxesVisible) if(AxesVisible)
{ {
p.setPen(QPen(QBrush(QColor(Qt::lightGray)), 1));
p.drawLine(Canvas.width() / 2, 0, Canvas.width() / 2, Canvas.height() - 1);
p.drawLine(0, Canvas.height() / 2, Canvas.width() - 1, Canvas.height() / 2);
p.drawText(Canvas.width() / 2 + 2, 12, QString::number(Canvas.width() / 2));
p.drawText(2, Canvas.height() / 2 - 2, QString::number(Canvas.height() / 2));
p.setPen(QPen(QBrush(QColor(Qt::red)), 3)); p.setPen(QPen(QBrush(QColor(Qt::red)), 3));
if(SwapYAxis) if(SwapYAxis)
{ {
@ -283,17 +280,7 @@ void QTSGraph::paintEvent(QPaintEvent *event)
p.drawLine(0, Canvas.height() - 1, 0, 0); p.drawLine(0, Canvas.height() - 1, 0, 0);
p.drawLine(10, 10, 0, 0); p.drawLine(10, 10, 0, 0);
p.drawText(12, 12, "Y"); p.drawText(12, 12, "Y");
correctY = 1;
p.setPen(QPen(QBrush(QColor(0xDDDDDD)), 1));
p.drawLine(Canvas.width() / 4, 0, Canvas.width() / 4, Canvas.height() - 1);
p.drawLine(0, Canvas.height() / 4, Canvas.width() - 1, Canvas.height() / 4);
p.drawText(Canvas.width() / 4 + 2, 12, QString::number(Canvas.width() / 4));
p.drawText(2, Canvas.height() / 4 - 2, QString::number(3 * Canvas.height() / 4));
p.drawLine(3 * Canvas.width() / 4, 0, 3 * Canvas.width() / 4, Canvas.height() - 1);
p.drawLine(0, 3 * Canvas.height() / 4, Canvas.width() - 1, 3 * Canvas.height() / 4);
p.drawText(3 * Canvas.width() / 4 + 2, 12, QString::number(3 * Canvas.width() / 4));
p.drawText(2, 3 * Canvas.height() / 4 - 2, QString::number(Canvas.height() / 4));
} }
else else
{ {
@ -303,18 +290,25 @@ void QTSGraph::paintEvent(QPaintEvent *event)
p.drawLine(0, Canvas.height() - 1, 0, 0); p.drawLine(0, Canvas.height() - 1, 0, 0);
p.drawLine(10, Canvas.height() - 10, 0, Canvas.height() - 1); p.drawLine(10, Canvas.height() - 10, 0, Canvas.height() - 1);
p.drawText(13, Canvas.height() - 2, "Y"); p.drawText(13, Canvas.height() - 2, "Y");
}
p.setPen(QPen(QBrush(QColor(Qt::lightGray)), 1));
p.drawLine(Canvas.width() / 2, 0, Canvas.width() / 2, Canvas.height() - 1);
p.drawLine(0, Canvas.height() / 2 - correctY, Canvas.width() - 1, Canvas.height() / 2 - correctY);
p.drawText(Canvas.width() / 2 + 2, 12, QString::number(Canvas.width() / 2));
p.drawText(2, Canvas.height() / 2 - 2, QString::number(Canvas.height() / 2));
p.setPen(QPen(QBrush(QColor(0xDDDDDD)), 1)); p.setPen(QPen(QBrush(QColor(0xDDDDDD)), 1));
p.drawLine(Canvas.width() / 4, 0, Canvas.width() / 4, Canvas.height() - 1); p.drawLine(Canvas.width() / 4, 0, Canvas.width() / 4, Canvas.height() - 1);
p.drawLine(0, Canvas.height() / 4, Canvas.width() - 1, Canvas.height() / 4); p.drawLine(0, Canvas.height() / 4 - correctY, Canvas.width() - 1, Canvas.height() / 4 - correctY);
p.drawText(Canvas.width() / 4 + 2, 12, QString::number(Canvas.width() / 4)); p.drawText(Canvas.width() / 4 + 2, 12, QString::number(Canvas.width() / 4));
p.drawText(2, Canvas.height() / 4 - 2, QString::number(Canvas.height() / 4)); if(correctY) mult = 3;
p.drawText(2, Canvas.height() / 4 - 2, QString::number(mult * Canvas.height() / 4));
p.drawLine(3 * Canvas.width() / 4, 0, 3 * Canvas.width() / 4, Canvas.height() - 1); p.drawLine(3 * Canvas.width() / 4, 0, 3 * Canvas.width() / 4, Canvas.height() - 1);
p.drawLine(0, 3 * Canvas.height() / 4, Canvas.width() - 1, 3 * Canvas.height() / 4); p.drawLine(0, 3 * Canvas.height() / 4 - 1, Canvas.width() - 1, 3 * Canvas.height() / 4 - correctY);
p.drawText(3 * Canvas.width() / 4 + 2, 12, QString::number(3 * Canvas.width() / 4)); p.drawText(3 * Canvas.width() / 4 + 2, 12, QString::number(3 * Canvas.width() / 4));
p.drawText(2, 3 * Canvas.height() / 4 - 2, QString::number(3 * Canvas.height() / 4)); mult = correctY ? 1 : 3;
} p.drawText(2, 3 * Canvas.height() / 4 - 2, QString::number(mult * Canvas.height() / 4));
} }
} }

Loading…
Cancel
Save