LookAtClick.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
3 #include <QMouseEvent>
4 #include <QPainter>
5 
8 
9 
10 #include "LookAtClick.h"
11 
12 LookAtClick::LookAtClick(QWidget* parent) : QWidget(parent)
13 {
14  setMouseTracking(true);
15  setCursor(Qt::PointingHandCursor);
16  this->installEventFilter(this);
17  std::cout << "mousetracking activated!\n";
18 }
19 void LookAtClick::drawBackground(QImage& image)
20 {
21  _backgroundImage = image.copy();
22  setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
23  setFixedSize(image.size());
24  QImage newImage(image.size(), QImage::Format_ARGB32);
25  newImage.fill(Qt::white);
26  QPainter painter(&newImage);
27  painter.drawImage(QPoint(0, 0), _backgroundImage);
28  _backgroundImage = newImage;
29  update();
30 }
31 
32 QSize LookAtClick::sizeHint() const
33 {
34  return _backgroundImage.size();
35 }
36 
37 bool LookAtClick::eventFilter(QObject* watched, QEvent* event)
38 {
39  if (event->type() == QEvent::MouseButtonPress)
40  {
41  ARMARX_INFO << "mousePressEvent found";
42  mousePressEvent(static_cast<QMouseEvent*>(event));
43  }
44  return false;
45 }
46 
47 void LookAtClick::mousePressEvent(QMouseEvent* event)
48 {
49  ARMARX_INFO << "mousePressEvent triggered!";
50  if (event->button() == Qt::LeftButton)
51  {
52  ARMARX_INFO << "Leftclick detected!";
53  _lastPoint = event->pos();
54  QPoint offset;
55  _center.setX(_backgroundImage.size().rwidth() / 2);
56  _center.setY(_backgroundImage.size().rheight() / 2);
57  offset.setX(_lastPoint.x() - _center.x());
58  offset.setY(_lastPoint.y() - _center.y());
59  clickedAt(offset);
60  }
61 }
62 
63 void LookAtClick::mouseMoveEvent(QMouseEvent* event)
64 {
65  std::cout << "Mouse is moving!\n";
66 }
67 
68 void LookAtClick::paintEvent(QPaintEvent* event)
69 {
70  QPainter painter(this);
71  QRect dirtyRect = event->rect();
72  painter.drawImage(dirtyRect, _backgroundImage, dirtyRect);
73 }
LookAtClick::mousePressEvent
void mousePressEvent(QMouseEvent *event) override
Definition: LookAtClick.cpp:47
LookAtClick::paintEvent
void paintEvent(QPaintEvent *event) override
Definition: LookAtClick.cpp:68
LookAtClick::clickedAt
void clickedAt(const QPoint &point)
LookAtClick.h
LookAtClick::sizeHint
QSize sizeHint() const override
Definition: LookAtClick.cpp:32
LookAtClick::mouseMoveEvent
void mouseMoveEvent(QMouseEvent *event) override
Definition: LookAtClick.cpp:63
LookAtClick::eventFilter
bool eventFilter(QObject *watched, QEvent *event) override
Definition: LookAtClick.cpp:37
armarx::armem::server::ltm::util::mongodb::detail::update
bool update(mongocxx::collection &coll, const nlohmann::json &query, const nlohmann::json &update)
Definition: mongodb.cpp:67
ExpressionException.h
ARMARX_INFO
#define ARMARX_INFO
Definition: Logging.h:174
LookAtClick::LookAtClick
LookAtClick(QWidget *parent=nullptr)
Definition: LookAtClick.cpp:12
Logging.h
LookAtClick::drawBackground
void drawBackground(QImage &image)
Definition: LookAtClick.cpp:19