mirror of
https://github.com/barry-ran/QtScrcpy.git
synced 2025-08-01 13:28:38 +00:00
fix: magnetic widget adsorb bug
This commit is contained in:
parent
fe4cb202f6
commit
a4daf33bfe
2 changed files with 11 additions and 3 deletions
|
@ -9,6 +9,7 @@ MagneticWidget::MagneticWidget(QWidget *adsorbWidget, AdsorbPositions adsorbPos)
|
|||
Q_ASSERT(m_adsorbWidget);
|
||||
setParent(m_adsorbWidget);
|
||||
setWindowFlags(windowFlags() | Qt::Tool);
|
||||
m_adsorbWidgetSize = m_adsorbWidget->size();
|
||||
|
||||
m_adsorbWidget->installEventFilter(this);
|
||||
}
|
||||
|
@ -30,6 +31,10 @@ bool MagneticWidget::eventFilter(QObject *watched, QEvent *event)
|
|||
if (watched != m_adsorbWidget || !event) {
|
||||
return false;
|
||||
}
|
||||
// 始终记录adsorbWidget最新size
|
||||
if (QEvent::Resize == event->type()) {
|
||||
m_adsorbWidgetSize = m_adsorbWidget->size();
|
||||
}
|
||||
if (m_adsorbed && QEvent::Move == event->type()) {
|
||||
move(m_adsorbWidget->pos() - m_relativePos);
|
||||
}
|
||||
|
@ -48,7 +53,7 @@ bool MagneticWidget::eventFilter(QObject *watched, QEvent *event)
|
|||
pos.setY(pos.y() - m_relativePos.y());
|
||||
break;
|
||||
case AP_OUTSIDE_RIGHT:
|
||||
pos.setX(pos.x() + m_adsorbWidget->width());
|
||||
pos.setX(pos.x() + m_adsorbWidgetSize.width());
|
||||
pos.setY(pos.y() - m_relativePos.y());
|
||||
break;
|
||||
case AP_OUTSIDE_TOP:
|
||||
|
@ -165,8 +170,8 @@ void MagneticWidget::moveEvent(QMoveEvent *event)
|
|||
void MagneticWidget::getGeometry(QRect &relativeWidgetRect, QRect &targetWidgetRect)
|
||||
{
|
||||
relativeWidgetRect.setTopLeft(m_adsorbWidget->pos());
|
||||
relativeWidgetRect.setWidth(m_adsorbWidget->width());
|
||||
relativeWidgetRect.setHeight(m_adsorbWidget->height());
|
||||
relativeWidgetRect.setWidth(m_adsorbWidgetSize.width());
|
||||
relativeWidgetRect.setHeight(m_adsorbWidgetSize.height());
|
||||
|
||||
targetWidgetRect.setTopLeft(pos());
|
||||
targetWidgetRect.setWidth(width());
|
||||
|
|
|
@ -46,6 +46,9 @@ private:
|
|||
QPoint m_relativePos;
|
||||
bool m_adsorbed = false;
|
||||
QPointer<QWidget> m_adsorbWidget;
|
||||
// 单独记录adsorbWidgetSize,因为Widget setGeometry的时候,会先收到Move事件,后收到Resize事件,
|
||||
// 但是收到Move事件时Widget的size()已经是setGeometry指定的size了
|
||||
QSize m_adsorbWidgetSize;
|
||||
AdsorbPosition m_curAdsorbPosition;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue