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();