Чтение нажатия кнопки мыши

main
Артём Проскурнёв 3 years ago
parent f6ca30a3fd
commit 7a4ec0e365
  1. 9
      main.cpp
  2. 20
      qtsgraph.cpp
  3. 4
      qtsgraph.h

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

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

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

Loading…
Cancel
Save