Skip to content

Commit

Permalink
[hotfix]增加qt5的兼容
Browse files Browse the repository at this point in the history
  • Loading branch information
czyt1988 committed Jan 11, 2024
1 parent 8dd3c94 commit cb8ae91
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/SARibbonBar/SAFramelessHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,9 +349,10 @@ bool SAPrivateFramelessWidgetData::handleMousePressEvent(QMouseEvent* event)
m_bLeftButtonTitlePressed = event->pos().y() < m_moveMousePos.m_nTitleHeight;

QRect frameRect = m_pWidget->frameGeometry();
m_pressedMousePos.recalculate(event->globalPosition().toPoint(), frameRect);
auto gp = SA_MOUSEEVENT_GLOBALPOS_POINT(event);
m_pressedMousePos.recalculate(gp, frameRect);

m_ptDragPos = event->globalPosition().toPoint() - frameRect.topLeft();
m_ptDragPos = gp - frameRect.topLeft();

if (m_pressedMousePos.m_bOnEdges) {
if (m_pWidget->isMaximized()) {
Expand Down Expand Up @@ -393,33 +394,33 @@ bool SAPrivateFramelessWidgetData::handleMouseReleaseEvent(QMouseEvent* event)

bool SAPrivateFramelessWidgetData::handleMouseMoveEvent(QMouseEvent* event)
{
QPoint p = SA_MOUSEEVENT_GLOBALPOS_POINT(event);
if (m_bLeftButtonPressed) {
if (d->m_bWidgetResizable && m_pressedMousePos.m_bOnEdges) {
if (m_pWidget->isMaximized()) {
//窗口在最大化状态时,点击边界不做任何处理
return (false);
}
resizeWidget(event->globalPosition().toPoint());
resizeWidget(p);
return (true);
} else if (d->m_bWidgetMovable && m_bLeftButtonTitlePressed) {
if (m_pWidget->isMaximized()) {
//先求出窗口到鼠标的相对位置
QRect normalGeometry = m_pWidget->normalGeometry();
m_pWidget->showNormal();
QPoint p = event->globalPosition().toPoint();
p.ry() -= 10;
p.rx() -= (normalGeometry.width() / 2);
m_pWidget->move(p);
//这时要重置m_ptDragPos
m_ptDragPos = QPoint(normalGeometry.width() / 2, 10);
return (true);
}
moveWidget(event->globalPosition().toPoint());
moveWidget(p);
return (true);
}
return (false);
} else if (d->m_bWidgetResizable) {
updateCursorShape(event->globalPosition().toPoint());
updateCursorShape(p);
}
return (false);
}
Expand All @@ -437,7 +438,7 @@ bool SAPrivateFramelessWidgetData::handleLeaveEvent(QEvent* event)
bool SAPrivateFramelessWidgetData::handleHoverMoveEvent(QHoverEvent* event)
{
if (d->m_bWidgetResizable) {
updateCursorShape(m_pWidget->mapToGlobal(event->position().toPoint()));
updateCursorShape(m_pWidget->mapToGlobal(SA_HOVEREVENT_POS_POINT(event)));
}
return (false);
}
Expand Down
26 changes: 26 additions & 0 deletions src/SARibbonBar/SARibbonGlobal.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,32 @@ enum class SARibbonAlignment
#endif
#endif


#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#ifndef SA_MOUSEEVENT_GLOBALPOS_POINT
#define SA_MOUSEEVENT_GLOBALPOS_POINT(MouseEventPtr) MouseEventPtr->globalPosition().toPoint()
#endif
#else
#ifndef SA_MOUSEEVENT_GLOBALPOS_POINT
#define SA_MOUSEEVENT_GLOBALPOS_POINT(MouseEventPtr) MouseEventPtr->globalPos()
#endif
#endif

#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#ifndef SA_HOVEREVENT_POS_POINT
#define SA_HOVEREVENT_POS_POINT(HoverEventPtr) HoverEventPtr->position().toPoint()
#endif
#else
#ifndef SA_HOVEREVENT_POS_POINT
#define SA_HOVEREVENT_POS_POINT(HoverEventPtr) HoverEventPtr->pos()
#endif
#endif






#ifndef SA_DEBUG_PRINT_SIZE_HINT
/**
@def 定义此宏,将打印和尺寸刷新相关的信息
Expand Down

0 comments on commit cb8ae91

Please sign in to comment.