mirror of
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System.git
synced 2025-04-01 02:42:39 +08:00
try to deal with dragging maximized window
This commit is contained in:
parent
5b1313ff6b
commit
60e0dfe14f
@ -68,6 +68,8 @@ struct FloatingDockContainerPrivate
|
||||
#ifdef Q_OS_LINUX
|
||||
QWidget* MouseEventHandler = nullptr;
|
||||
CFloatingWidgetTitleBar* TitleBar = nullptr;
|
||||
QRect NormalizedGeometry = {0,0,0,0};
|
||||
bool IsMaximized = false;
|
||||
#endif
|
||||
|
||||
/**
|
||||
@ -491,9 +493,11 @@ void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
|
||||
#ifndef Q_OS_LINUX
|
||||
Q_UNUSED(MouseEventHandler)
|
||||
#endif
|
||||
resize(Size);
|
||||
d->setState(DragState);
|
||||
d->DragStartMousePosition = DragStartMousePos;
|
||||
if (!isMaximized()) {
|
||||
resize(Size);
|
||||
d->DragStartMousePosition = DragStartMousePos;
|
||||
}
|
||||
d->setState(DragState);
|
||||
#ifdef Q_OS_LINUX
|
||||
// I have not found a way on Linux to display the floating widget behind the
|
||||
// dock overlay. That means if the user drags this floating widget around,
|
||||
@ -513,7 +517,9 @@ void CFloatingDockContainer::startFloating(const QPoint &DragStartMousePos,
|
||||
}
|
||||
}
|
||||
#endif
|
||||
moveFloating();
|
||||
if (!isMaximized()) {
|
||||
moveFloating();
|
||||
}
|
||||
show();
|
||||
|
||||
}
|
||||
@ -657,17 +663,46 @@ void CFloatingDockContainer::onMaximizeRequest()
|
||||
}
|
||||
ADS_PRINT("CFloatingDockContainer::onMaximizeRequest() current screen: " + currentScreen->name());
|
||||
// get current windows state, if it is maximized and moved or not
|
||||
if (windowState() == Qt::WindowMaximized)
|
||||
if (geometry().size() == currentScreen->availableGeometry().size())
|
||||
{
|
||||
setWindowState(Qt::WindowNoState);
|
||||
setGeometry(d->NormalizedGeometry);
|
||||
d->TitleBar->setMaximizedIcon(false);
|
||||
d->IsMaximized = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
qDebug() << "maximize";
|
||||
d->NormalizedGeometry = geometry();
|
||||
d->IsMaximized = true;
|
||||
setGeometry(currentScreen->availableGeometry());
|
||||
d->TitleBar->setMaximizedIcon(true);
|
||||
}
|
||||
}
|
||||
|
||||
void CFloatingDockContainer::dragToNormalize()
|
||||
{
|
||||
auto cursorPos = QCursor::pos();
|
||||
qDebug() << "pos" << cursorPos;
|
||||
auto screen = QGuiApplication::screenAt(QCursor::pos());
|
||||
if (d->IsMaximized) {
|
||||
auto screenGeometry = screen->availableGeometry();
|
||||
QRect r = QRect(cursorPos.x()
|
||||
-(cursorPos.x() - screenGeometry.left())/(double)screenGeometry.width() * d->NormalizedGeometry.width(),
|
||||
cursorPos.y(), d->NormalizedGeometry.width(),d->NormalizedGeometry.height());
|
||||
qDebug() << "rect"<<r;
|
||||
move(r.left(), r.top());
|
||||
resize(r.width(), r.height());
|
||||
d->IsMaximized = false;
|
||||
qDebug() << "geometry" << geometry();
|
||||
}
|
||||
}
|
||||
|
||||
bool CFloatingDockContainer::isMaximized() const
|
||||
{
|
||||
// todo when initialized with maximum size?
|
||||
return d->IsMaximized;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -208,6 +208,9 @@ public:
|
||||
* maximize or normalize the container size.
|
||||
*/
|
||||
void onMaximizeRequest();
|
||||
void dragToNormalize();
|
||||
|
||||
bool isMaximized() const;
|
||||
#endif
|
||||
|
||||
}; // class FloatingDockContainer
|
||||
|
@ -173,6 +173,7 @@ void CFloatingWidgetTitleBar::mouseMoveEvent(QMouseEvent *ev)
|
||||
// move floating window
|
||||
if (DraggingFloatingWidget == d->DragState)
|
||||
{
|
||||
d->FloatingWidget->dragToNormalize();
|
||||
d->FloatingWidget->moveFloating();
|
||||
Super::mouseMoveEvent(ev);
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user