Вывод текста, прямоугольник, стиль линии

main
Артём Проскурнёв 3 years ago
parent 8bb265fd94
commit eba43e164e
  1. 19
      example/main.cpp
  2. 24
      qtsgraph.cpp
  3. 14
      qtsgraph.h

@ -1,4 +1,5 @@
#include "../qtsgraph.h"
#include <string>
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);
}
// Конец рисования

@ -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);
}

@ -9,6 +9,7 @@
#include <QMouseEvent>
#include <QTimer>
#include <QTime>
#include <string>
#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();

Loading…
Cancel
Save