Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions src/ddesktopinputselectioncontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,9 +475,15 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event)
break;

QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const auto& tpList = touchEvent->points();
const auto& tp = tpList.first();
QPointF touchPos = tp.lastPosition();
#else
QList<QTouchEvent::TouchPoint> tpList = touchEvent->touchPoints();
QTouchEvent::TouchPoint tp = tpList.first();
QPointF touchPos = tp.lastPos();
#endif

// 有效点击位置
QRectF effectiveRect = anchorRectangle();
Expand Down Expand Up @@ -511,7 +517,11 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event)
break;

QMouseEvent *me = static_cast<QMouseEvent *>(event);
const QPoint mousePos = me->screenPos().toPoint();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPoint mousePos = me->globalPosition().toPoint();
#else
QPoint mousePos = me->screenPos().toPoint();
#endif

// calculate distances from mouse pos to each handle,
// then choose to interact with the nearest handle
Expand Down Expand Up @@ -556,7 +566,12 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event)
m_otherSelectionPoint = QPoint(otherRect.x() + otherRect.width() / 2, otherRect.bottom() + 4);
}

QMouseEvent *mouseEvent = new QMouseEvent(me->type(), me->localPos(), me->windowPos(), me->screenPos(),
QMouseEvent *mouseEvent = new QMouseEvent(me->type(),
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
me->position(), me->scenePosition(), me->globalPosition(),
#else
me->localPos(), me->windowPos(), me->screenPos(),
#endif
me->button(), me->buttons(), me->modifiers(), me->source());
m_eventQueue.append(mouseEvent);
return true;
Expand All @@ -570,7 +585,11 @@ bool DDesktopInputSelectionControl::eventFilter(QObject *object, QEvent *event)
m_handleVisible = true;

QMouseEvent *me = static_cast<QMouseEvent *>(event);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPoint mousePos = me->globalPosition().toPoint();
#else
QPoint mousePos = me->screenPos().toPoint();
#endif
if (m_handleState == HandleIsHeld) {
QPoint delta = m_handleDragStartedPosition - mousePos;
const int startDragDistance = QGuiApplication::styleHints()->startDragDistance();
Expand Down
2 changes: 1 addition & 1 deletion src/dnativesettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
DPP_BEGIN_NAMESPACE

class DPlatformSettings;
class DNativeSettings : public QAbstractDynamicMetaObject
class Q_DECL_HIDDEN DNativeSettings : public QAbstractDynamicMetaObject
{
public:
explicit DNativeSettings(QObject *base, DPlatformSettings *settings, bool global_settings);
Expand Down
3 changes: 2 additions & 1 deletion src/dplatformsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ QT_END_NAMESPACE

DPP_BEGIN_NAMESPACE

class DPlatformSettings
class Q_DECL_HIDDEN DPlatformSettings
{
public:
virtual ~DPlatformSettings() {}
Expand All @@ -41,6 +41,7 @@ class DPlatformSettings
void handlePropertyChanged(const QByteArray &property, const QVariant &value);
void handleNotify(const QByteArray &signal, qint32 data1, qint32 data2);

private:
struct Q_DECL_HIDDEN Callback
{
PropertyChangeFunc func;
Expand Down
15 changes: 15 additions & 0 deletions src/dselectedtexttooltip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ DSelectedTextTooltip::DSelectedTextTooltip()
m_textInfoVec.push_back({Paste, 0, qApp->translate("QLineEdit", "&Paste").split("(").at(0)});

updateColor();
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
// Qt6中使用事件处理替代fontChanged信号
qApp->installEventFilter(this);
#else
connect(qApp, &QGuiApplication::fontChanged, this, &DSelectedTextTooltip::onFontChanged);
#endif

// 更新文本信息
onFontChanged();
Expand All @@ -46,6 +51,16 @@ DSelectedTextTooltip::~DSelectedTextTooltip()
{
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool DSelectedTextTooltip::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::ApplicationFontChange) {
onFontChanged();
}
return QRasterWindow::eventFilter(obj, event);
}
#endif

void DSelectedTextTooltip::onFontChanged()
{
QFontMetrics font_metrics(qApp->font());
Expand Down
3 changes: 3 additions & 0 deletions src/dselectedtexttooltip.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@
protected:
void paintEvent(QPaintEvent *pe) override;
void mousePressEvent(QMouseEvent *event) override;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
bool eventFilter(QObject *obj, QEvent *event) override;
#endif

private slots:

Check warning on line 38 in src/dselectedtexttooltip.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.

Check warning on line 38 in src/dselectedtexttooltip.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
void onFontChanged();

signals:
Expand Down
4 changes: 4 additions & 0 deletions src/dxcbxsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,11 @@ class Q_DECL_HIDDEN DXcbXSettingsPrivate
const QByteArray &key = i.key();
quint16 key_size = key.size();

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
switch (value.value.typeId()) {
#else
switch (value.value.type()) {
#endif
case QMetaType::QColor:
type = XSettingsTypeColor;
break;
Expand Down
2 changes: 1 addition & 1 deletion src/dxcbxsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@

class DXcbXSettingsPrivate;

class DXcbXSettings : public DPlatformSettings
class Q_DECL_HIDDEN DXcbXSettings : public DPlatformSettings
{
Q_DECLARE_PRIVATE(DXcbXSettings)

Check warning on line 26 in src/dxcbxsettings.h

View workflow job for this annotation

GitHub Actions / cppcheck

Unused private function: 'DXcbXSettings::d_func'

Check warning on line 26 in src/dxcbxsettings.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

Unused private function: 'DXcbXSettings::d_func'
public:
DXcbXSettings(xcb_connection_t *connection, const QByteArray &property = QByteArray());
DXcbXSettings(xcb_connection_t *connection, xcb_window_t setting_window, const QByteArray &property = QByteArray());
Expand Down
18 changes: 18 additions & 0 deletions xcb/dframewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -515,23 +515,41 @@ void DFrameWindow::mouseMoveEvent(QMouseEvent *event)
}
set_edge:
/// begin set cursor edge type
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (event->position().x() <= m_contentGeometry.x()) {
#else
if (event->x() <= m_contentGeometry.x()) {
#endif
if (isFixedWidth)
goto skip_set_cursor;

mouseCorner = Utility::LeftEdge;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
} else if (event->position().x() < m_contentGeometry.right()) {
#else
} else if (event->x() < m_contentGeometry.right()) {
#endif
if (isFixedHeight)
goto skip_set_cursor;

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (event->position().y() <= m_contentGeometry.y()) {
mouseCorner = Utility::TopEdge;
} else if (!isFixedWidth || event->position().y() >= m_contentGeometry.bottom()) {
#else
if (event->y() <= m_contentGeometry.y()) {
mouseCorner = Utility::TopEdge;
} else if (!isFixedWidth || event->y() >= m_contentGeometry.bottom()) {
#endif
mouseCorner = Utility::BottomEdge;
} else {
goto skip_set_cursor;
}
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
} else if (!isFixedWidth && (!isFixedHeight || event->position().x() >= m_contentGeometry.right())) {
#else
} else if (!isFixedWidth && (!isFixedHeight || event->x() >= m_contentGeometry.right())) {
#endif
mouseCorner = Utility::RightEdge;
} else {
goto skip_set_cursor;
Expand Down
13 changes: 9 additions & 4 deletions xcb/dhighdpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,13 @@ inline static void init()
Q_CONSTRUCTOR_FUNCTION(init)
void DHighDpi::init()
{
if (QGuiApplication::testAttribute(Qt::AA_DisableHighDpiScaling)
// 可以禁用此行为
|| qEnvironmentVariableIsSet("D_DXCB_DISABLE_OVERRIDE_HIDPI")
if (qEnvironmentVariableIsSet("D_DXCB_DISABLE_OVERRIDE_HIDPI")
// 无有效的xsettings时禁用
|| !DXcbXSettings::getOwner()) {
|| !DXcbXSettings::getOwner()
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|| QGuiApplication::testAttribute(Qt::AA_DisableHighDpiScaling)
#endif
) {
// init函数可能会被重复调用, 此处应该清理VtableHook
if (active) {
#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
Expand All @@ -67,10 +69,13 @@ void DHighDpi::init()
qunsetenv("QT_USE_PHYSICAL_DPI");
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
// Qt6中高DPI缩放总是启用的,无需设置AA_EnableHighDpiScaling
if (!QGuiApplication::testAttribute(Qt::AA_EnableHighDpiScaling)) {
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QHighDpiScaling::initHighDpiScaling();
}
#endif

#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
active = VtableHook::overrideVfptrFun(&QXcbScreen::pixelDensity, pixelDensity);
Expand Down
16 changes: 16 additions & 0 deletions xcb/dnotitlebarwindowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,19 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
#endif
}
if (isTouchDown && event->type() == QEvent::MouseButtonPress) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
touchBeginPosition = static_cast<QMouseEvent*>(event)->globalPosition().toPoint();
#else
touchBeginPosition = static_cast<QMouseEvent*>(event)->globalPos();
#endif
}
// add some redundancy to distinguish trigger between system menu and system move
if (event->type() == QEvent::MouseMove) {
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPointF currentPos = static_cast<QMouseEvent*>(event)->globalPosition();
#else
QPointF currentPos = static_cast<QMouseEvent*>(event)->globalPos();
#endif
QPointF delta = touchBeginPosition - currentPos;
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return VtableHook::callOriginalFun(w, &QWindow::event, event);
Expand All @@ -590,7 +598,11 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
// keeping the moving state, we can just reset ti back to normal.
if (event->type() == QEvent::MouseButtonPress) {
self->m_windowMoving = false;
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
g_pressPoint[this] = dynamic_cast<QMouseEvent*>(event)->globalPosition().toPoint();
#else
g_pressPoint[this] = dynamic_cast<QMouseEvent*>(event)->globalPos();
#endif
}

// ========== 修改:鼠标事件处理保持原有逻辑 ==========
Expand All @@ -605,7 +617,11 @@ bool DNoTitlebarWindowHelper::windowEvent(QEvent *event)
return ret;
}

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
QPointF delta = me->globalPosition() - g_pressPoint[this];
#else
QPointF delta = me->globalPos() - g_pressPoint[this];
#endif
if (delta.manhattanLength() < QGuiApplication::styleHints()->startDragDistance()) {
return ret;
}
Expand Down
8 changes: 8 additions & 0 deletions xcb/dplatformwindowhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,11 @@ bool DPlatformWindowHelper::windowRedirectContent(QWindow *window)

const QVariant &value = window->property(redirectContent);

#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
if (value.typeId() == QMetaType::Bool)
#else
if (value.type() == QVariant::Bool)
#endif
return value.toBool();

return window->surfaceType() == QSurface::OpenGLSurface;
Expand Down Expand Up @@ -612,7 +616,11 @@ bool DPlatformWindowHelper::eventFilter(QObject *watched, QEvent *event)
case QEvent::MouseMove: {
DQMouseEvent *e = static_cast<DQMouseEvent*>(event);
const QRectF rectF(m_windowValidGeometry);
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
const QPointF posF(e->position() - m_frameWindow->contentOffsetHint());
#else
const QPointF posF(e->localPos() - m_frameWindow->contentOffsetHint());
#endif

// QRectF::contains中判断时加入了右下边界
if (!qFuzzyCompare(posF.x(), rectF.width())
Expand Down
Loading