Skip to content

Commit

Permalink
Qt6 compatibility
Browse files Browse the repository at this point in the history
- Added code compatibility for Qt6;
    - Replaced deprecated calls (Qt6 only):
        - MouseEvent::globalPos -> MouseEvent::globalPosition::toPoint;
        - MouseEvent::globalX -> MouseEvent::globalPosition::toPoint::x;
        - MouseEvent::globalY -> MouseEvent::globalPosition::toPoint::y.
    - Applied code macro when necessary.
- Updated code samples.
  • Loading branch information
mauromascarenhas committed Oct 21, 2021
1 parent ab4e3a8 commit 64d4cb4
Show file tree
Hide file tree
Showing 14 changed files with 103 additions and 35 deletions.
17 changes: 16 additions & 1 deletion sample/CustomFrame-Dynamic/customwindow/qcustomtitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -30,16 +30,31 @@
#include <QEvent>
#include <QLabel>
#include <QPoint>
#include <QPointF>
#include <QPixmap>
#include <QWidget>
#include <QPainter>
#include <QtGlobal>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPushButton>
#include <QStyleOption>

#ifndef EV_GLOBAL_MACRO
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define EV_GLOBAL_X(event) event->globalX()
#define EV_GLOBAL_Y(event) event->globalY()
#define EV_GLOBAL_POS(event) event->globalPos()
#else
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
#endif
#define EV_GLOBAL_MACRO
#endif

namespace QCustomAttrs {
enum WindowButton {
Minimize = 0x01,
Expand Down
4 changes: 3 additions & 1 deletion sample/CustomFrame-Dynamic/customwindow/qcustomwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 4 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -30,13 +30,15 @@
#include <QTimer>
#include <QPoint>
#include <QStyle>
#include <QPointF>
#include <QObject>
#include <QWidget>
#include <QCursor>
#include <QWindow>
#include <QMenuBar>
#include <QPainter>
#include <QToolBar>
#include <QtGlobal>
#include <QStatusBar>
#include <QSizePolicy>
#include <QMetaMethod>
Expand Down
6 changes: 3 additions & 3 deletions sample/CustomFrame-Static/customwindow/qcustomtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand Down Expand Up @@ -118,12 +118,12 @@ void QCustomTitleBar::setWindowButtonEnabled(QCustomAttrs::WindowButton btn, boo
}

void QCustomTitleBar::mouseMoveEvent(QMouseEvent *event){
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(event->globalPos());
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(EV_GLOBAL_POS(event));
QWidget::mouseMoveEvent(event);
}

void QCustomTitleBar::mousePressEvent(QMouseEvent *event){
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(event->globalPos());
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(EV_GLOBAL_POS(event));
QWidget::mousePressEvent(event);
}

Expand Down
17 changes: 16 additions & 1 deletion sample/CustomFrame-Static/customwindow/qcustomtitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -22,16 +22,31 @@
#include <QEvent>
#include <QLabel>
#include <QPoint>
#include <QPointF>
#include <QPixmap>
#include <QWidget>
#include <QPainter>
#include <QtGlobal>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPushButton>
#include <QStyleOption>

#ifndef EV_GLOBAL_MACRO
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define EV_GLOBAL_X(event) event->globalX()
#define EV_GLOBAL_Y(event) event->globalY()
#define EV_GLOBAL_POS(event) event->globalPos()
#else
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
#endif
#define EV_GLOBAL_MACRO
#endif

namespace QCustomAttrs {
enum WindowButton {
Minimize = 0x01,
Expand Down
12 changes: 6 additions & 6 deletions sample/CustomFrame-Static/customwindow/qcustomwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand Down Expand Up @@ -118,20 +118,20 @@ bool QCustomWindow::eventFilter(QObject *, QEvent *event){
case QEvent::MouseMove:
if (this->cOpStatus & OperationType::CUSTOM_RESIZE)
customMouseMoveEvent(static_cast<QMouseEvent*>(event));
else if (!this->isMoving()) redefineCursor(static_cast<QMouseEvent*>(event)->globalPos());
else if (!this->isMoving()) redefineCursor(EV_GLOBAL_POS(static_cast<QMouseEvent*>(event)));
break;
default: break;
}
return false;
}

void QCustomWindow::mousePressEvent(QMouseEvent *event){
this->redefineCursor(event->globalPos());
this->redefineCursor(EV_GLOBAL_POS(event));
if (event->button() & Qt::LeftButton && this->mLock){
if (!this->forceCustomResize && this->windowHandle()->startSystemResize(this->mLock))
this->cOpStatus = OperationType::SYSTEM_RESIZE;
else {
QPoint posCursor = event->globalPos();
QPoint posCursor = EV_GLOBAL_POS(event);
if (this->mLock & Qt::TopEdge) posCursor.ry() -= this->y();
if (this->mLock & Qt::LeftEdge) posCursor.rx() -= this->x();
if (this->mLock & Qt::RightEdge) posCursor.rx() -= (this->x() + this->width());
Expand All @@ -144,12 +144,12 @@ void QCustomWindow::mousePressEvent(QMouseEvent *event){

void QCustomWindow::mouseReleaseEvent(QMouseEvent *event){
this->cOpStatus = OperationType::NONE;
this->redefineCursor(event->globalPos());
this->redefineCursor(EV_GLOBAL_POS(event));
QWidget::mouseReleaseEvent(event);
}

void QCustomWindow::customMouseMoveEvent(QMouseEvent *event){
int gX = event->globalX(), gY = event->globalY();
int gX = EV_GLOBAL_X(event), gY = EV_GLOBAL_Y(event);
QPoint tL = this->geometry().topLeft(), bR = this->geometry().bottomRight();

bool cRH = bR.x() - tL.x() > this->minimumWidth();
Expand Down
4 changes: 3 additions & 1 deletion sample/CustomFrame-Static/customwindow/qcustomwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 30 of August of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -22,13 +22,15 @@
#include <QTimer>
#include <QPoint>
#include <QStyle>
#include <QPointF>
#include <QObject>
#include <QWidget>
#include <QCursor>
#include <QWindow>
#include <QMenuBar>
#include <QPainter>
#include <QToolBar>
#include <QtGlobal>
#include <QStatusBar>
#include <QSizePolicy>
#include <QMetaMethod>
Expand Down
6 changes: 3 additions & 3 deletions src/QCustomWindow-Dynamic/qcustomtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand Down Expand Up @@ -118,12 +118,12 @@ void QCustomTitleBar::setWindowButtonEnabled(QCustomAttrs::WindowButton btn, boo
}

void QCustomTitleBar::mouseMoveEvent(QMouseEvent *event){
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(event->globalPos());
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(EV_GLOBAL_POS(event));
QWidget::mouseMoveEvent(event);
}

void QCustomTitleBar::mousePressEvent(QMouseEvent *event){
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(event->globalPos());
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(EV_GLOBAL_POS(event));
QWidget::mousePressEvent(event);
}

Expand Down
17 changes: 16 additions & 1 deletion src/QCustomWindow-Dynamic/qcustomtitlebar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -30,16 +30,31 @@
#include <QEvent>
#include <QLabel>
#include <QPoint>
#include <QPointF>
#include <QPixmap>
#include <QWidget>
#include <QPainter>
#include <QtGlobal>
#include <QMainWindow>
#include <QHBoxLayout>
#include <QMouseEvent>
#include <QPaintEvent>
#include <QPushButton>
#include <QStyleOption>

#ifndef EV_GLOBAL_MACRO
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
#define EV_GLOBAL_X(event) event->globalX()
#define EV_GLOBAL_Y(event) event->globalY()
#define EV_GLOBAL_POS(event) event->globalPos()
#else
#define EV_GLOBAL_X(event) event->globalPosition().toPoint().x()
#define EV_GLOBAL_Y(event) event->globalPosition().toPoint().y()
#define EV_GLOBAL_POS(event) event->globalPosition().toPoint()
#endif
#define EV_GLOBAL_MACRO
#endif

namespace QCustomAttrs {
enum WindowButton {
Minimize = 0x01,
Expand Down
12 changes: 6 additions & 6 deletions src/QCustomWindow-Dynamic/qcustomwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand Down Expand Up @@ -118,20 +118,20 @@ bool QCustomWindow::eventFilter(QObject *, QEvent *event){
case QEvent::MouseMove:
if (this->cOpStatus & OperationType::CUSTOM_RESIZE)
customMouseMoveEvent(static_cast<QMouseEvent*>(event));
else if (!this->isMoving()) redefineCursor(static_cast<QMouseEvent*>(event)->globalPos());
else if (!this->isMoving()) redefineCursor(EV_GLOBAL_POS(static_cast<QMouseEvent*>(event)));
break;
default: break;
}
return false;
}

void QCustomWindow::mousePressEvent(QMouseEvent *event){
this->redefineCursor(event->globalPos());
this->redefineCursor(EV_GLOBAL_POS(event));
if (event->button() & Qt::LeftButton && this->mLock){
if (!this->forceCustomResize && this->windowHandle()->startSystemResize(this->mLock))
this->cOpStatus = OperationType::SYSTEM_RESIZE;
else {
QPoint posCursor = event->globalPos();
QPoint posCursor = EV_GLOBAL_POS(event);
if (this->mLock & Qt::TopEdge) posCursor.ry() -= this->y();
if (this->mLock & Qt::LeftEdge) posCursor.rx() -= this->x();
if (this->mLock & Qt::RightEdge) posCursor.rx() -= (this->x() + this->width());
Expand All @@ -144,12 +144,12 @@ void QCustomWindow::mousePressEvent(QMouseEvent *event){

void QCustomWindow::mouseReleaseEvent(QMouseEvent *event){
this->cOpStatus = OperationType::NONE;
this->redefineCursor(event->globalPos());
this->redefineCursor(EV_GLOBAL_POS(event));
QWidget::mouseReleaseEvent(event);
}

void QCustomWindow::customMouseMoveEvent(QMouseEvent *event){
int gX = event->globalX(), gY = event->globalY();
int gX = EV_GLOBAL_X(event), gY = EV_GLOBAL_Y(event);
QPoint tL = this->geometry().topLeft(), bR = this->geometry().bottomRight();

bool cRH = bR.x() - tL.x() > this->minimumWidth();
Expand Down
4 changes: 3 additions & 1 deletion src/QCustomWindow-Dynamic/qcustomwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 4 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand All @@ -30,13 +30,15 @@
#include <QTimer>
#include <QPoint>
#include <QStyle>
#include <QPointF>
#include <QObject>
#include <QWidget>
#include <QCursor>
#include <QWindow>
#include <QMenuBar>
#include <QPainter>
#include <QToolBar>
#include <QtGlobal>
#include <QStatusBar>
#include <QSizePolicy>
#include <QMetaMethod>
Expand Down
6 changes: 3 additions & 3 deletions src/QCustomWindow-Static/qcustomtitlebar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Developer: Mauro Mascarenhas de Araújo
# Contact: [email protected]
# Licence: Mozilla Public Licence 2.0
# Date: 5 of September of 2021
# Date: 31 of October of 2021
#
# Licence notice
#
Expand Down Expand Up @@ -118,12 +118,12 @@ void QCustomTitleBar::setWindowButtonEnabled(QCustomAttrs::WindowButton btn, boo
}

void QCustomTitleBar::mouseMoveEvent(QMouseEvent *event){
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(event->globalPos());
if (event->buttons() & Qt::LeftButton) emit changeWindowPositionRequest(EV_GLOBAL_POS(event));
QWidget::mouseMoveEvent(event);
}

void QCustomTitleBar::mousePressEvent(QMouseEvent *event){
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(event->globalPos());
if (event->button() & Qt::LeftButton) emit startWindowMoveRequest(EV_GLOBAL_POS(event));
QWidget::mousePressEvent(event);
}

Expand Down
Loading

0 comments on commit 64d4cb4

Please sign in to comment.