From 212d009d1493e03c2e1e554d77b751804f804710 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: Thu, 31 Dec 2020 04:27:55 +0300 Subject: [PATCH] =?UTF-8?q?MouseClicked()=20-=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=D0=B6=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF=D0=BA=D0=B8=20=D0=BC=D1=8B?= =?UTF-8?q?=D1=88=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.cpp | 19 ++++++++++++++----- qtSimpleGraph.pro.user | 2 +- qtsgraph.cpp | 18 +++++++++++++----- qtsgraph.h | 12 +++++++----- 4 files changed, 35 insertions(+), 16 deletions(-) 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; };