Chatterino
DraggablePopup.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "widgets/BaseWindow.hpp"
4 
5 #include <QPoint>
6 #include <QTimer>
7 
8 #include <memory>
9 
10 namespace chatterino {
11 
12 class DraggablePopup : public BaseWindow
13 {
14  Q_OBJECT
15 
16 public:
22  DraggablePopup(bool closeAutomatically, QWidget *parent);
23 
24 protected:
25  void mousePressEvent(QMouseEvent *event) override;
26  void mouseReleaseEvent(QMouseEvent *event) override;
27  void mouseMoveEvent(QMouseEvent *event) override;
28 
29  // lifetimeHack_ is used to check that the window hasn't been destroyed yet
30  std::shared_ptr<bool> lifetimeHack_;
31 
32 private:
33  // isMoving_ is set to true if the user is holding the left mouse button down and has moved the mouse a small amount away from the original click point (startPosDrag_)
34  bool isMoving_ = false;
35 
36  // startPosDrag_ is the coordinates where the user originally pressed the mouse button down to start dragging
37  QPoint startPosDrag_;
38 
39  // requestDragPos_ is the final screen coordinates where the widget should be moved to.
40  // Takes the relative position of where the user originally clicked the widget into account
41  QPoint requestedDragPos_;
42 
43  // dragTimer_ is called ~60 times per second once the user has initiated dragging
44  QTimer dragTimer_;
45 };
46 
47 } // namespace chatterino
DraggablePopup(bool closeAutomatically, QWidget *parent)
Definition: DraggablePopup.cpp:25
void mouseReleaseEvent(QMouseEvent *event) override
Definition: DraggablePopup.cpp:69
Definition: BaseWindow.hpp:20
Definition: Application.cpp:48
Definition: DraggablePopup.hpp:12
void mouseMoveEvent(QMouseEvent *event) override
Definition: DraggablePopup.cpp:75
void mousePressEvent(QMouseEvent *event) override
Definition: DraggablePopup.cpp:59
std::shared_ptr< bool > lifetimeHack_
Definition: DraggablePopup.hpp:30
virtual bool event(QEvent *event) override
Definition: BaseWindow.cpp:333