qmovewindowmanager.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "qmovewindowmanager.h"
  2. #include "qevent.h"
  3. QMoveWindowManager::QMoveWindowManager(QWidget *parent, QRect hit/*=QRect()*/) : QObject(parent), m_bLeftButtonPress(false)
  4. {
  5. m_parent = parent;
  6. m_hit = hit;
  7. }
  8. QMoveWindowManager::~QMoveWindowManager()
  9. {
  10. }
  11. bool QMoveWindowManager::eventFilter(QObject * obj, QEvent * evt)
  12. {
  13. QMouseEvent * event;
  14. switch (evt->type()){
  15. case QEvent::MouseButtonPress:
  16. event = (QMouseEvent *)evt;
  17. if (event->button() == Qt::LeftButton)
  18. {
  19. if (!m_hit.isValid() || m_hit.contains(event->pos())){
  20. m_ptPress = event->globalPos();
  21. if (!m_parent->isMaximized() && !m_parent->isMinimized()) m_bLeftButtonPress = true;
  22. }
  23. }
  24. break;
  25. case QEvent::MouseMove:
  26. event = (QMouseEvent *)evt;
  27. if (m_bLeftButtonPress)
  28. {
  29. m_ptMove = event->globalPos();
  30. //Òƶ¯Ö÷´°¿Ú
  31. m_parent->move(m_parent->pos() + m_ptMove - m_ptPress);
  32. m_ptPress = m_ptMove;
  33. }
  34. break;
  35. case QEvent::MouseButtonRelease:
  36. event = (QMouseEvent *)evt;
  37. if (event->button() == Qt::LeftButton)
  38. {
  39. m_bLeftButtonPress = false;
  40. }
  41. break;
  42. }
  43. return false;
  44. }