DragAbleWidget.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /**
  2. * 叶海辉
  3. * QQ群121376426
  4. * http://blog.yundiantech.com/
  5. */
  6. #ifndef DRAGABLEWIDGET_H
  7. #define DRAGABLEWIDGET_H
  8. #include <QWidget>
  9. #include <QTimer>
  10. namespace Ui {
  11. class DragAbleWidget;
  12. }
  13. //鼠标实现改变窗口大小
  14. #define PADDING 6
  15. enum Direction { UP=0, DOWN, LEFT, RIGHT, LEFTTOP, LEFTBOTTOM, RIGHTBOTTOM, RIGHTTOP, NONE };
  16. class DragAbleWidget : public QWidget
  17. {
  18. Q_OBJECT
  19. public:
  20. explicit DragAbleWidget(QWidget *parent = 0);
  21. ~DragAbleWidget();
  22. QWidget *getContainWidget();
  23. void setTitle(QString str);
  24. private:
  25. Ui::DragAbleWidget *ui;
  26. QTimer *mTimer;
  27. ///以下是改变窗体大小相关
  28. ////////
  29. protected:
  30. // bool eventFilter(QObject *obj, QEvent *event);
  31. void mouseReleaseEvent(QMouseEvent *event);
  32. void mouseMoveEvent(QMouseEvent *event);
  33. void mousePressEvent(QMouseEvent *event);
  34. private:
  35. bool isMax = false; //是否最大化
  36. QRect mLocation;
  37. bool mIsResizeMode = false;
  38. bool isLeftPressDown = false; // 判断左键是否按下
  39. QPoint dragPosition; // 窗口移动拖动时需要记住的点
  40. int dir; // 窗口大小改变时,记录改变方向
  41. void checkCursorDirect(const QPoint &cursorGlobalPoint);
  42. void doShowFullScreen();
  43. void doShowNormal();
  44. void showBorderRadius(bool isShow);
  45. void doChangeFullScreen();
  46. private slots:
  47. void slotTimerTimeOut();
  48. void on_btnMenu_Close_clicked();
  49. void on_btnMenu_Max_clicked();
  50. void on_btnMenu_Min_clicked();
  51. };
  52. #endif // DRAGABLEWIDGET_H