Corrected the updating of normal geometry for window

This commit is contained in:
Eism
2022-02-04 18:12:11 +02:00
committed by Sergio Martins
parent 412860abac
commit 220471f746
3 changed files with 30 additions and 50 deletions

View File

@@ -299,7 +299,7 @@ if(CMAKE_COMPILER_IS_GNUCXX OR IS_CLANG_BUILD)
endif()
if(${PROJECT_NAME}_QTQUICK)
target_link_libraries(kddockwidgets PUBLIC Qt${Qt_VERSION_MAJOR}::Widgets Qt${Qt_VERSION_MAJOR}::Quick Qt${Qt_VERSION_MAJOR}::QuickControls2)
target_link_libraries(kddockwidgets PUBLIC Qt${Qt_VERSION_MAJOR}::Widgets Qt${Qt_VERSION_MAJOR}::Quick Qt${Qt_VERSION_MAJOR}::QuickControls2 PRIVATE Qt${Qt_VERSION_MAJOR}::GuiPrivate)
else()
target_link_libraries(kddockwidgets PUBLIC Qt${Qt_VERSION_MAJOR}::Widgets PRIVATE Qt${Qt_VERSION_MAJOR}::WidgetsPrivate)
endif()

View File

@@ -34,6 +34,8 @@
#include <QQuickView>
#include <QScopedValueRollback>
#include <qpa/qplatformwindow.h>
using namespace KDDockWidgets;
namespace KDDockWidgets {
@@ -181,54 +183,13 @@ void QWidgetAdapter::onMouseRelease()
void QWidgetAdapter::onCloseEvent(QCloseEvent *)
{
}
void QWidgetAdapter::onResizeEvent(QResizeEvent *event)
void QWidgetAdapter::onResizeEvent(QResizeEvent *)
{
QWindow* window = windowHandle();
if (!window) {
return;
}
if (isNormalWindowState(m_oldWindowState)) {
QRect geo = normalGeometry();
auto curState = window->windowState();
if (isNormalWindowState(curState)) {
geo.setSize(event->size());
} else {
geo.setSize(event->oldSize());
}
setNormalGeometry(geo);
}
updateNormalGeometry();
}
void QWidgetAdapter::onMoveEvent(QMoveEvent *event)
void QWidgetAdapter::onMoveEvent(QMoveEvent *)
{
QWindow* window = windowHandle();
if (!window) {
return;
}
if (isNormalWindowState(m_oldWindowState)) {
QRect geo = normalGeometry();
auto windowCurrentState = window->windowState();
if (isNormalWindowState(windowCurrentState)) {
geo.moveTopLeft(event->pos());
} else {
geo.moveTopLeft(event->oldPos());
}
setNormalGeometry(geo);
}
}
void QWidgetAdapter::onWindowStateChangeEvent(QWindowStateChangeEvent *)
{
QWindow* window = windowHandle();
if (!window) {
return;
}
m_oldWindowState = window->windowState();
updateNormalGeometry();
}
void QWidgetAdapter::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &data)
@@ -259,6 +220,27 @@ void QWidgetAdapter::itemChange(QQuickItem::ItemChange change, const QQuickItem:
}
}
void QWidgetAdapter::updateNormalGeometry()
{
QWindow *window = windowHandle();
if (!window) {
return;
}
QRect normalGeometry;
if (const QPlatformWindow *pw = window->handle()) {
normalGeometry = pw->normalGeometry();
}
if (!normalGeometry.isValid() && isNormalWindowState(window->windowState())) {
normalGeometry = window->geometry();
}
if (normalGeometry.isValid()) {
setNormalGeometry(normalGeometry);
}
}
void QWidgetAdapter::QQUICKITEMgeometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry)
{
// Send a few events manually, since QQuickItem doesn't do it for us.
@@ -795,8 +777,6 @@ bool QWidgetAdapter::eventFilter(QObject *watched, QEvent *ev)
onResizeEvent(static_cast<QResizeEvent *>(ev));
} else if (ev->type() == QEvent::Move) {
onMoveEvent(static_cast<QMoveEvent *>(ev));
} else if (ev->type() == QEvent::WindowStateChange) {
onWindowStateChangeEvent(static_cast<QWindowStateChangeEvent *>(ev));
}
}

View File

@@ -253,10 +253,11 @@ protected:
virtual void onCloseEvent(QCloseEvent *);
virtual void onResizeEvent(QResizeEvent *);
virtual void onMoveEvent(QMoveEvent *);
virtual void onWindowStateChangeEvent(QWindowStateChangeEvent *);
void itemChange(QQuickItem::ItemChange, const QQuickItem::ItemChangeData &) override;
private:
void updateNormalGeometry();
QSize m_sizeHint;
QSizePolicy m_sizePolicy = QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
;
@@ -269,7 +270,6 @@ private:
bool m_inSetParent = false;
MouseEventRedirector *m_mouseEventRedirector = nullptr;
QRect m_normalGeometry;
Qt::WindowStates m_oldWindowState = Qt::WindowState::WindowNoState;
};
inline qreal logicalDpiFactor(const QQuickItem *item)