configure_touch_widget.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. void resizeEvent(QResizeEvent*) override;
  29. void mouseMoveEvent(QMouseEvent*) override;
  30. void leaveEvent(QEvent*) override;
  31. void mousePressEvent(QMouseEvent*) override;
  32. 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 DragState {
  45. bool active = false;
  46. QPointer<QLabel> dot;
  47. QPoint start_pos;
  48. };
  49. DragState drag_state;
  50. };