From 7a4ec0e365ed44a1c63c4e3c34cef17605b284d6 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: Fri, 8 Jan 2021 08:42:13 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A7=D1=82=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BD?= =?UTF-8?q?=D0=B0=D0=B6=D0=B0=D1=82=D0=B8=D1=8F=20=D0=BA=D0=BD=D0=BE=D0=BF?= =?UTF-8?q?=D0=BA=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 --- main.cpp | 9 ++++++++- qtsgraph.cpp | 20 ++++++++++++++++++++ qtsgraph.h | 4 +++- 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 595937c..2647b84 100644 --- a/main.cpp +++ b/main.cpp @@ -30,7 +30,14 @@ void QTSGraph::PaintBox() SetTextStyle(0, 45, 10); OutTextXY(30, 30, "Hello world!"); SetTextStyle(1, 0, 20); - OutTextXY(210, 50, "Hello world!"); + OutTextXY(170, 50, "Кликните мышкой..."); + int m = ReadMouseButton(); + SetColor(clRed); + SetTextStyle(1, 0, 20); + if(m == 1) OutTextXY(150, 80, "Нажата левая кнопка"); + else if(m == 2) OutTextXY(150, 80, "Нажата правая кнопка"); + else if(m == 3) OutTextXY(150, 80, "Нажата средняя кнопка"); + else OutTextXY(150, 80, "Нажата неизвестная кнопка"); SetTextStyle(2, 180, 30); OutTextXY(460, 550, "Hello world!"); SetColor(0x999999); diff --git a/qtsgraph.cpp b/qtsgraph.cpp index 3188aad..d9b8819 100644 --- a/qtsgraph.cpp +++ b/qtsgraph.cpp @@ -103,6 +103,7 @@ void QTSGraph::Circle(int x, int y, int radius) bool QTSGraph::MouseClicked() { + QCoreApplication::processEvents(QEventLoop::AllEvents, 50); bool m = EventMouseClicked; EventMouseClicked = false; return m; @@ -149,6 +150,18 @@ int QTSGraph::ReadKey() return t; } +int QTSGraph::ReadMouseButton() +{ + if(IDMouseButton == -1) + { + while(!MouseClicked() && this->isVisible()) + Delay(1); + } + int t = IDMouseButton; + IDMouseButton = -1; + return t; +} + void QTSGraph::Rectangle(int x1, int y1, int x2, int y2) { QPainter painter(&Canvas); @@ -233,10 +246,17 @@ void QTSGraph::mousePressEvent(QMouseEvent *event) if (event->buttons() & Qt::LeftButton) { // Левая кнопка + IDMouseButton = 1; } else if (event->buttons() & Qt::RightButton) { // Правая кнопка + IDMouseButton = 2; + } + else if (event->buttons() & Qt::MiddleButton) + { + // Средняя кнопка + IDMouseButton = 3; } ResetTimer->start(ResetInterval); } diff --git a/qtsgraph.h b/qtsgraph.h index 25572a7..7610e50 100644 --- a/qtsgraph.h +++ b/qtsgraph.h @@ -79,9 +79,10 @@ public: void OutTextXY(int x, int y, std::string caption); void PutPixel(int x, int y, QRgb c = 0x00000000, int PenWidth = 1); int ReadKey(); + int ReadMouseButton(); void Rectangle(int x1, int y1, int x2, int y2); void SetColor(QRgb c); - void SetFillStyle(int Pattern, QRgb Color); // Стиль и цыет заливки + void SetFillStyle(int Pattern, QRgb Color); // Стиль и цвет заливки /* 0 - NoBrush 1 - SolidPattern @@ -127,6 +128,7 @@ private: bool EventMouseClicked = false; bool EventKeyPressed = false; int IDPressedKey = -1; + int IDMouseButton = -1; int ResetInterval; int TextDirection = 0;