-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouseprocessing.cpp
More file actions
93 lines (82 loc) · 3.24 KB
/
mouseprocessing.cpp
File metadata and controls
93 lines (82 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <mainwindow.h>
#include <ui_mainwindow.h>
/* Обрабатываем движение мыши */
void MainWindow::slotMouseMove(QMouseEvent* event)
{
QCustomPlot* senderCanvas = qobject_cast<QCustomPlot*>(sender());
if (!senderCanvas)
return;
QCPAxis* Haxis = senderCanvas->axisRect()->rangeDragAxis(Qt::Horizontal);
QCPAxis* Vaxis = senderCanvas->axisRect()->rangeDragAxis(Qt::Vertical);
double diff = 0;
if (isMouseHold_)
{
if (senderCanvas->xAxis->scaleType() == QCPAxis::stLinear)
{
diff = Haxis->pixelToCoord(mDragStart_.x()) - Haxis->pixelToCoord(event->pos().x());
Haxis->setRange(DragStartHorzRange_.lower + diff, DragStartHorzRange_.upper - diff);
}
if (senderCanvas->yAxis->scaleType() == QCPAxis::stLinear)
{
diff = Vaxis->pixelToCoord(mDragStart_.y()) - Vaxis->pixelToCoord(event->pos().y());
Vaxis->setRange(DragStartVertRange_.lower + diff, DragStartVertRange_.upper - diff);
}
senderCanvas->replot();
}
}
/* Ообрабатываем нажатие кнопок мыши */
void MainWindow::slotMousePress(QMouseEvent* event)
{
QCustomPlot* senderCanvas = qobject_cast<QCustomPlot*>(sender());
if (!senderCanvas)
return;
if (event->button() == Qt::RightButton)
{
mouseHoldTimer_.start();
setCursor(Qt::ClosedHandCursor);
mDragStart_ = event->pos();
isMouseHold_ = true;
DragStartHorzRange_ = senderCanvas->axisRect()->rangeDragAxis(Qt::Horizontal)->range();
DragStartVertRange_ = senderCanvas->axisRect()->rangeDragAxis(Qt::Vertical)->range();
}
}
/* Обрабатываем отпускание кнопок мыши */
void MainWindow::slotMouseRelease(QMouseEvent* event)
{
QCustomPlot* senderCanvas = qobject_cast<QCustomPlot*>(sender());
if (!senderCanvas)
return;
if (event->button() == Qt::RightButton)
{
setCursor(Qt::ArrowCursor);
isMouseHold_ = false;
// Проверяем, сколько времени была зажата правая кнопка мыши
if (mouseHoldTimer_.elapsed() >= 250)
{
// Если кнопка была зажата более 100 мс, то не показываем контекстное меню
return;
}
else
{
activeCanvas = senderCanvas;
// Иначе показываем контекстное меню
QMenu* menu = new QMenu(this);
menu->addAction(tr("Сохранить изображение"), this, SLOT(slotSavePlotPNG()));
menu->addAction(tr("Сохранить данные в .txt"), this, SLOT(slotSaveDataFromPlot()));
menu->addAction(tr("Восстановить размер"), this, SLOT(slotResetCanvas()));
QPoint pos = event->globalPos();
pos.rx() += 10;
pos.ry() -= 75;
menu->exec(pos); // Исправлено для показа меню
delete menu;
}
}
}
/* Обрабатываем двойной щелчок мыши */
void MainWindow::slotMouseDoubleClick(QMouseEvent* event)
{
if (event->button() == Qt::LeftButton)
{
// Здесь можно добавить логику, если требуется реакция на двойной щелчок
}
}