DragAbleWidget.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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; //是否最大化
  36. QRect mLocation;
  37. bool isLeftPressDown; // 判断左键是否按下
  38. QPoint dragPosition; // 窗口移动拖动时需要记住的点
  39. int dir; // 窗口大小改变时,记录改变方向
  40. void checkCursorDirect(const QPoint &cursorGlobalPoint);
  41. void doShowFullScreen();
  42. void doShowNormal();
  43. void showBorderRadius(bool isShow);
  44. void doChangeFullScreen();
  45. private slots:
  46. void slotTimerTimeOut();
  47. void on_btnMenu_Close_clicked();
  48. void on_btnMenu_Max_clicked();
  49. void on_btnMenu_Min_clicked();
  50. };
  51. #endif // DRAGABLEWIDGET_H