diff --git a/main.cpp b/main.cpp index 0752aa8..e59cc70 100644 --- a/main.cpp +++ b/main.cpp @@ -9,14 +9,23 @@ int main(int argc, char *argv[]) return a.exec(); } -void QTSGraph::slotstarttimer() +void QTSGraph::slotStartTimer() { + // Тут рисовать - putpixel(100,100); - delay(2000); - putpixel(300,100); + PutPixel(100,100); + Delay(2000); + PutPixel(300,100); + int x=1; + while(!MouseClicked() && x < 1024) + { + PutPixel(x,50); + x+=1; + Delay(200); + } // Конец рисования - starttimer->stop(); + + StartTimer->stop(); } diff --git a/qtSimpleGraph.pro.user b/qtSimpleGraph.pro.user index 9cc3bc3..d291e54 100644 --- a/qtSimpleGraph.pro.user +++ b/qtSimpleGraph.pro.user @@ -1,6 +1,6 @@ - + EnvironmentId diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 1bb0fbe..3be126b 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -1,7 +1,7 @@ #include "qtsgraph.h" #include "ui_qtsgraph.h" -void QTSGraph::delay(int ms) +void QTSGraph::Delay(int ms) { QTime dieTime= QTime::currentTime().addMSecs(ms); while (QTime::currentTime() < dieTime) @@ -25,9 +25,9 @@ QTSGraph::QTSGraph(int w, int h, int x, int y, QWidget *parent) this->setWindowTitle("Рисунок"); m_Pixmap = QPixmap(w, h); m_Pixmap.fill(Qt::white); - starttimer = new QTimer(); - connect(starttimer, SIGNAL(timeout()), this, SLOT(slotstarttimer())); - starttimer->start(500); + StartTimer = new QTimer(); + connect(StartTimer, SIGNAL(timeout()), this, SLOT(slotStartTimer())); + StartTimer->start(500); } QTSGraph::~QTSGraph() @@ -35,7 +35,14 @@ QTSGraph::~QTSGraph() delete ui; } -void QTSGraph::putpixel(int x, int y, Qt::GlobalColor c) +bool QTSGraph::MouseClicked() +{ + bool m = EventMouseClicked; + EventMouseClicked = false; + return m; +} + +void QTSGraph::PutPixel(int x, int y, Qt::GlobalColor c) { QPainter painter(&m_Pixmap); painter.setPen(QPen(QBrush(QColor(c)), 5 )); @@ -51,6 +58,7 @@ void QTSGraph::paintEvent(QPaintEvent *event) void QTSGraph::mousePressEvent(QMouseEvent *event) { + EventMouseClicked = true; if (event->buttons() & Qt::LeftButton) { // Левая кнопка diff --git a/qtsgraph.h b/qtsgraph.h index 209c395..5245316 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -20,18 +20,20 @@ class QTSGraph : public QMainWindow public: QTSGraph(int w = 640, int h = 480, int x = -1, int y = -1, QWidget *parent = nullptr); ~QTSGraph(); - void putpixel(int x, int y, Qt::GlobalColor c = Qt::red); - void delay(int ms = 1000); + void PutPixel(int x, int y, Qt::GlobalColor c = Qt::red); + void Delay(int ms = 1000); + bool MouseClicked(); private slots: - void slotstarttimer(); + void slotStartTimer(); private: Ui::QTSGraph *ui; QPixmap m_Pixmap; - QTimer *starttimer; + QTimer *StartTimer; + bool EventMouseClicked = false; protected: void paintEvent(QPaintEvent *event) override; - void mousePressEvent(QMouseEvent *event); + void mousePressEvent(QMouseEvent *event) override; };