DragAbleWidget.h 1.3 KB

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