configure_touch_widget.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // SPDX-FileCopyrightText: 2020 Citra Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <optional>
  5. #include <utility>
  6. #include <vector>
  7. #include <QFrame>
  8. #include <QPointer>
  9. class QLabel;
  10. // Widget for representing touchscreen coordinates
  11. class TouchScreenPreview : public QFrame {
  12. Q_OBJECT
  13. Q_PROPERTY(QColor dotHighlightColor MEMBER dot_highlight_color)
  14. public:
  15. explicit TouchScreenPreview(QWidget* parent);
  16. ~TouchScreenPreview() override;
  17. void SetCoordLabel(QLabel*);
  18. int AddDot(int device_x, int device_y);
  19. void RemoveDot(int id);
  20. void HighlightDot(int id, bool active = true) const;
  21. void MoveDot(int id, int device_x, int device_y) const;
  22. signals:
  23. void DotAdded(const QPoint& pos);
  24. void DotSelected(int dot_id);
  25. void DotMoved(int dot_id, const QPoint& pos);
  26. protected:
  27. void resizeEvent(QResizeEvent*) override;
  28. void mouseMoveEvent(QMouseEvent*) override;
  29. void leaveEvent(QEvent*) override;
  30. void mousePressEvent(QMouseEvent*) override;
  31. bool eventFilter(QObject*, QEvent*) override;
  32. private:
  33. std::optional<QPoint> MapToDeviceCoords(int screen_x, int screen_y) const;
  34. void PositionDot(QLabel* dot, int device_x = -1, int device_y = -1) const;
  35. bool ignore_resize = false;
  36. QPointer<QLabel> coord_label;
  37. std::vector<std::pair<int, QLabel*>> dots;
  38. int max_dot_id = 0;
  39. QColor dot_highlight_color;
  40. static constexpr char PropId[] = "dot_id";
  41. static constexpr char PropX[] = "device_x";
  42. static constexpr char PropY[] = "device_y";
  43. struct DragState {
  44. bool active = false;
  45. QPointer<QLabel> dot;
  46. QPoint start_pos;
  47. };
  48. DragState drag_state;
  49. };