Координатная сетка

main
Артём Проскурнёв 4 years ago
parent 7028802380
commit 16db5c08b3
  1. 1
      main.cpp
  2. 59
      qtsgraph.cpp
  3. 4
      qtsgraph.h

@ -19,6 +19,7 @@ void QTSGraph::PaintBox()
{
// Начало рисования
ShowAxes();
SetColor(clGreen);
Line(0, 0, 600, 600);
SetColor(0xFF0000);

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

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

Loading…
Cancel
Save