configure_touch_widget.h 1.7 KB

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