From d69b552fef83631c404fe44bf63a3d863f1a99ae 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: Mon, 4 Jan 2021 22:45:55 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D1=82=D0=BA=D0=B0=D0=BB=D0=B8=D0=B1?= =?UTF-8?q?=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=20=D1=82=D0=B0=D0=B9=D0=BC=D0=B5?= =?UTF-8?q?=D1=80=20=D1=81=D0=B1=D1=80=D0=BE=D1=81=D0=B0=20=D1=81=D0=BE?= =?UTF-8?q?=D0=B1=D1=8B=D1=82=D0=B8=D1=8F=20=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D1=88=D0=B8=20=D0=B8=20=D0=BC=D1=8B=D1=88=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- qtsgraph.cpp | 12 ++++++++++-- qtsgraph.h | 1 + 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/qtsgraph.cpp b/qtsgraph.cpp index aa27a3e..1f2fe0b 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -67,9 +67,10 @@ QTSGraph::QTSGraph(int w, int h, int x, int y, QWidget *parent) QRgb DefaultColor = 0x00000000; Pen = QPen(QBrush(QColor(DefaultColor)), 1); Brush = QBrush(QColor(DefaultColor),Qt::NoBrush); + ResetInterval = 1000; ResetTimer = new QTimer(); connect(ResetTimer, SIGNAL(timeout()), this, SLOT(slotResetTimer())); - ResetTimer->start(500); + ResetTimer->start(ResetInterval); StartTimer = new QTimer(); connect(StartTimer, SIGNAL(timeout()), this, SLOT(slotStartTimer())); @@ -115,7 +116,7 @@ void QTSGraph::PutPixel(int x, int y, QRgb c, int PenWidth) int QTSGraph::ReadKey() { - if(!EventKeyPressed || IDPressedKey == -1) + if(IDPressedKey == -1) { while(!KeyPressed() && this->isVisible()) Delay(1); @@ -166,6 +167,7 @@ void QTSGraph::Line(int x1, int y1, int x2, int y2) bool QTSGraph::KeyPressed() { + QCoreApplication::processEvents(QEventLoop::AllEvents, 50); bool m = EventKeyPressed; EventKeyPressed = false; return m; @@ -179,7 +181,9 @@ void QTSGraph::slotStartTimer() void QTSGraph::slotResetTimer() { + ResetTimer->stop(); EventKeyPressed = false; + IDPressedKey = -1; EventMouseClicked = false; } @@ -191,6 +195,7 @@ void QTSGraph::paintEvent(QPaintEvent *event) void QTSGraph::mousePressEvent(QMouseEvent *event) { + ResetTimer->stop(); EventMouseClicked = true; if (event->buttons() & Qt::LeftButton) { @@ -200,16 +205,19 @@ void QTSGraph::mousePressEvent(QMouseEvent *event) { // Правая кнопка } + ResetTimer->start(ResetInterval); } void QTSGraph::keyPressEvent(QKeyEvent *event) { + ResetTimer->stop(); EventKeyPressed = true; IDPressedKey = event->key(); if (IDPressedKey == Qt::Key_Escape) { // Нажатие Esc } + ResetTimer->start(ResetInterval); } void QTSGraph::closeEvent(QCloseEvent *event) diff --git a/qtsgraph.h b/qtsgraph.h index 0463c34..60cb508 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -125,6 +125,7 @@ private: void PaintBox(); QBrush Brush; QPen Pen; + int ResetInterval; protected: void paintEvent(QPaintEvent *event) override;