From 16db5c08b385b1adc2dc3064a18bb6726b3f12c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D1=80=D1=82=D1=91=D0=BC=20=D0=9F=D1=80=D0=BE=D1=81?= =?UTF-8?q?=D0=BA=D1=83=D1=80=D0=BD=D1=91=D0=B2?= Date: Mon, 11 Jan 2021 15:21:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9A=D0=BE=D0=BE=D1=80=D0=B4=D0=B8=D0=BD?= =?UTF-8?q?=D0=B0=D1=82=D0=BD=D0=B0=D1=8F=20=D1=81=D0=B5=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 1 + qtsgraph.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++ qtsgraph.h | 4 ++++ 3 files changed, 64 insertions(+) diff --git a/main.cpp b/main.cpp index 67d6ba8..6140283 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ void QTSGraph::PaintBox() { // Начало рисования + ShowAxes(); SetColor(clGreen); Line(0, 0, 600, 600); SetColor(0xFF0000); diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 962638a..01e0c37 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -101,6 +101,16 @@ QTSGraph::~QTSGraph() // Деструктор } +void QTSGraph::ShowAxes() +{ + AxesVisible = true; +} + +void QTSGraph::HideAxes() +{ + AxesVisible = false; +} + void QTSGraph::Circle(int x, int y, int radius) { QPainter painter(&Canvas); @@ -257,6 +267,55 @@ void QTSGraph::paintEvent(QPaintEvent *event) { QPainter p(this); p.drawPixmap(0, 0, Canvas); + 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) + { + p.drawLine(0, Canvas.height() - 1, Canvas.width() - 1, Canvas.height() - 1); + p.drawLine(Canvas.width() - 10, Canvas.height() - 10, Canvas.width() - 1, Canvas.height() - 1); + p.drawText(Canvas.width() - 10, Canvas.height() - 15, "X"); + 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)); + } + else + { + p.drawLine(0, 0, Canvas.width() - 1, 0); + p.drawLine(Canvas.width() - 10, 10, Canvas.width() - 1, 0); + p.drawText(Canvas.width() - 10, 22, "X"); + 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)); + } + } } void QTSGraph::mousePressEvent(QMouseEvent *event) diff --git a/qtsgraph.h b/qtsgraph.h index 5b02e45..6e86bc7 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -71,6 +71,9 @@ public: bool SwapYAxis = false; + void ShowAxes(); + void HideAxes(); + void Circle(int x, int y, int radius); void Delay(int ms = 1000); void Ellipse(int x1, int y1, int x2, int y2); @@ -128,6 +131,7 @@ private slots: void slotStartTimer(); private: + bool AxesVisible = false; bool EventMouseClicked = false; bool EventKeyPressed = false; int IDPressedKey = -1;