diff --git a/main.cpp b/main.cpp index 6140283..1aceffb 100644 --- a/main.cpp +++ b/main.cpp @@ -11,6 +11,7 @@ int main(int argc, char *argv[]) */ QTSGraph w(600, 600); + //w.SwapYAxis = true; w.show(); return a.exec(); } @@ -19,7 +20,6 @@ void QTSGraph::PaintBox() { // Начало рисования - ShowAxes(); SetColor(clGreen); Line(0, 0, 600, 600); SetColor(0xFF0000); diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 01e0c37..98b96f8 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -267,13 +267,10 @@ void QTSGraph::paintEvent(QPaintEvent *event) { QPainter p(this); p.drawPixmap(0, 0, Canvas); + int correctY = 0; + int mult = 1; 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)); if(SwapYAxis) { @@ -283,17 +280,7 @@ void QTSGraph::paintEvent(QPaintEvent *event) p.drawLine(0, Canvas.height() - 1, 0, 0); p.drawLine(10, 10, 0, 0); p.drawText(12, 12, "Y"); - - 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)); + correctY = 1; } else { @@ -303,18 +290,25 @@ void QTSGraph::paintEvent(QPaintEvent *event) p.drawLine(0, Canvas.height() - 1, 0, 0); p.drawLine(10, Canvas.height() - 10, 0, Canvas.height() - 1); p.drawText(13, Canvas.height() - 2, "Y"); - - 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(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(3 * Canvas.height() / 4)); } + 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.drawLine(Canvas.width() / 4, 0, Canvas.width() / 4, Canvas.height() - 1); + 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)); + 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(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)); + mult = correctY ? 1 : 3; + p.drawText(2, 3 * Canvas.height() / 4 - 2, QString::number(mult * Canvas.height() / 4)); } }