123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "qmovewindowmanager.h"
- #include "qevent.h"
- QMoveWindowManager::QMoveWindowManager(QWidget *parent, QRect hit/*=QRect()*/) : QObject(parent), m_bLeftButtonPress(false)
- {
- m_parent = parent;
- m_hit = hit;
- }
- QMoveWindowManager::~QMoveWindowManager()
- {
- }
- bool QMoveWindowManager::eventFilter(QObject * obj, QEvent * evt)
- {
- QMouseEvent * event;
- switch (evt->type()){
- case QEvent::MouseButtonPress:
- event = (QMouseEvent *)evt;
- if (event->button() == Qt::LeftButton)
- {
- if (!m_hit.isValid() || m_hit.contains(event->pos())){
- m_ptPress = event->globalPos();
- if (!m_parent->isMaximized() && !m_parent->isMinimized()) m_bLeftButtonPress = true;
- }
- }
- break;
- case QEvent::MouseMove:
- event = (QMouseEvent *)evt;
- if (m_bLeftButtonPress)
- {
- m_ptMove = event->globalPos();
- //Òƶ¯Ö÷´°¿Ú
- m_parent->move(m_parent->pos() + m_ptMove - m_ptPress);
- m_ptPress = m_ptMove;
- }
- break;
- case QEvent::MouseButtonRelease:
- event = (QMouseEvent *)evt;
- if (event->button() == Qt::LeftButton)
- {
- m_bLeftButtonPress = false;
- }
- break;
- }
- return false;
- }
|