From eba43e164eb7e99afd5405b43c191863036e77cd 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: Sat, 2 Jan 2021 00:32:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=92=D1=8B=D0=B2=D0=BE=D0=B4=20=D1=82=D0=B5?= =?UTF-8?q?=D0=BA=D1=81=D1=82=D0=B0,=20=D0=BF=D1=80=D1=8F=D0=BC=D0=BE?= =?UTF-8?q?=D1=83=D0=B3=D0=BE=D0=BB=D1=8C=D0=BD=D0=B8=D0=BA,=20=D1=81?= =?UTF-8?q?=D1=82=D0=B8=D0=BB=D1=8C=20=D0=BB=D0=B8=D0=BD=D0=B8=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- example/main.cpp | 19 +++++++++++++++---- qtsgraph.cpp | 24 +++++++++++++++++++++++- qtsgraph.h | 14 +++++++++++++- 3 files changed, 51 insertions(+), 6 deletions(-) diff --git a/example/main.cpp b/example/main.cpp index 5aac539..aa3e5b1 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -1,4 +1,5 @@ #include "../qtsgraph.h" +#include int main(int argc, char *argv[]) { @@ -19,20 +20,30 @@ void QTSGraph::PaintBox() { // Начало рисования + for(int i = 0; i <= 5; i++) + { + SetPenStyle(1, 1); + SetColor(clBlue); + Rectangle(5, 390 + i * 20, 220, 410 + i * 20); + SetColor(clBlack); + OutTextXY(10, 405 + i * 20, std::to_string(i)); + SetPenStyle(1, i); + Line(30, 400 + i * 20, 200, 400 + i * 20); + } SetColor(0x00AAAAAA); Line(120, 120, 135, 260); - SetWidth(5); + SetPenWidth(5); SetColor(clBlue); Line(110, 110, 125, 250); PutPixel(100, 100, 0x00FF0000, 10); - Delay(2000); + Delay(1000); PutPixel(300, 100); int x = 1; while(!MouseClicked() && x < 1024) { - PutPixel(x, 50, 0x555555+x*16, 5); + PutPixel(x, 50, 0x555555 + x * 16, 5); x += 1; - Delay(1); + Delay(10); } // Конец рисования diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 09d8a68..4e2d80d 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -41,6 +41,14 @@ bool QTSGraph::MouseClicked() return m; } +void QTSGraph::OutTextXY(int x, int y, std::string s) +{ + QPainter painter(&Canvas); + painter.setPen(Pen); + painter.drawText(x, y, QString::fromStdString(s)); + update(); +} + void QTSGraph::PutPixel(int x, int y, QRgb c, int PenWidth) { QPainter painter(&Canvas); @@ -49,12 +57,26 @@ void QTSGraph::PutPixel(int x, int y, QRgb c, int PenWidth) update(); } +void QTSGraph::Rectangle(int x1, int y1, int x2, int y2) +{ + QPainter painter(&Canvas); + painter.setPen(Pen); + painter.drawRect(x1, y1, x2 - x1, y2 - y1); + update(); +} + void QTSGraph::SetColor(QRgb c) { Pen.setColor(QColor(c)); } -void QTSGraph::SetWidth(int PenWidth) +void QTSGraph::SetPenStyle(int PenWidth, int PenStyle) +{ + Pen.setWidth(PenWidth); + Pen.setStyle(Qt::PenStyle(PenStyle)); +} + +void QTSGraph::SetPenWidth(int PenWidth) { Pen.setWidth(PenWidth); } diff --git a/qtsgraph.h b/qtsgraph.h index 6189d33..23b19f0 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -9,6 +9,7 @@ #include #include #include +#include #define clRed 0x00FF0000 #define clGreen 0x0000FF00 @@ -27,9 +28,20 @@ public: void Delay(int ms = 1000); void Line(int x1, int y1, int x2, int y2); bool MouseClicked(); + void OutTextXY(int x, int y, std::string s); void PutPixel(int x, int y, QRgb c = 0x00000000, int PenWidth = 1); + void Rectangle(int x1, int y1, int x2, int y2); void SetColor(QRgb c); - void SetWidth(int PenWidth); + void SetPenStyle(int PenWidth, int PenStyle = 1); // Толщина и стиль линии + /* + 0 - NoPen + 1 - SolidLine + 2 - DashLine + 3 - DotLine + 4 - DashDotLine + 5 - DashDotDotLine + */ + void SetPenWidth(int PenWidth); private slots: void slotStartTimer();