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. #include <QTimer>
  10. #include <QWidget>
  11. namespace Ui {
  12. class DragAbleWidget;
  13. }
  14. class DragAbleWidget : public QWidget
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit DragAbleWidget(QWidget *parent = 0);
  19. ~DragAbleWidget();
  20. QWidget *getContainWidget();
  21. void setTitle(QString str);
  22. void doShowMaxSize();
  23. void doShowFullScreen();
  24. void doShowNormal();
  25. private:
  26. Ui::DragAbleWidget *ui;
  27. QTimer *mTimer;
  28. ///以下是改变窗体大小相关
  29. ////////
  30. protected:
  31. // bool eventFilter(QObject *obj, QEvent *event);
  32. void mouseReleaseEvent(QMouseEvent *event);
  33. void mouseMoveEvent(QMouseEvent *event);
  34. void mousePressEvent(QMouseEvent *event);
  35. private:
  36. bool isMax; //是否最大化
  37. QRect mLocation;
  38. bool mIsResizeMode;
  39. bool isLeftPressDown; // 判断左键是否按下
  40. QPoint dragPosition; // 窗口移动拖动时需要记住的点
  41. int dir; // 窗口大小改变时,记录改变方向
  42. void checkCursorDirect(const QPoint &cursorGlobalPoint);
  43. void showBorderRadius(bool isShow);
  44. void doChangeFullScreen();
  45. void doChangeMaxSize();
  46. private slots:
  47. void slotTimerTimeOut();
  48. };
  49. #endif // DRAGABLEWIDGET_H