Compare commits

...

3 Commits

Author SHA1 Message Date
Milian Wolff
be176fc1a0 Allow restoring layouts without touching floating dock widgets
The current behavior is great for when we want to apply an older
stored state to a different screen configuration. There,
scaling/shrinking the floating docks makes sense.

But we now also want to have more fine grained window
configurations and save/restore them more frequently. In those
situations, the screen config is the same, but the mainwindow may
or may not be full screen when the state was saved. In this case
we don't want to touch the size of the floating docks - most notably
we don't want to resize a "nearly fullscreen" floating window from
a state with a small main window when loading it into a state with
a fullscreen mainwindow - in such situations the floating window would
get resized beyond the available screen space!

Preventing the latter is probably required as a safety measure
independently of this patch, for situations where the relative
resizing is desired. This is outside the scope of this patch.
2023-02-10 12:04:23 +01:00
Sergio Martins
af455bb37e examples: Show how to hide dock indicators when ctrl is pressed
Fixes issue #334 and issue #337.
Won't add this directly into the library, as each project
has different requirements regarding this.

It's easy to do in application code though.
2023-02-07 23:51:20 +00:00
Sergio Martins
57aded2a67 Fix setDropIndicatorsInhibited(false) not showing drop indicators
It required the user to move the mouse, which was OK but we can do
better.

Now, KDDW will automaticallt re-show the drop indicators if we're in
the middle of a drag operation.

Required for issue #334 and issue #337
2023-02-07 21:58:37 +00:00
6 changed files with 55 additions and 14 deletions

View File

@@ -121,6 +121,9 @@ MyMainWindow::MyMainWindow(const QString &uniqueName, KDDockWidgets::MainWindowO
if (options & KDDockWidgets::MainWindowOption_HasCentralWidget) {
setPersistentCentralWidget(new MyWidget1());
}
// optional, just for demo purposes regarding pressing Ctrl key to hide drop indicators
qApp->installEventFilter(this);
}
MyMainWindow::~MyMainWindow()
@@ -210,3 +213,26 @@ KDDockWidgets::DockWidgetBase *MyMainWindow::newDockWidget()
count++;
return dock;
}
bool MyMainWindow::eventFilter(QObject *obj, QEvent *ev)
{
// This event filter is just for examplify how to use the KDDW API to hide
// the drag indicators when ctrl is pressed
switch (ev->type()) {
case QEvent::KeyPress:
case QEvent::KeyRelease: {
auto kev = static_cast<QKeyEvent *>(ev);
if (kev->key() == Qt::Key_Control && qobject_cast<QWindow *>(obj)) {
const bool hideIndicators = ev->type() == QEvent::KeyPress;
KDDockWidgets::Config::self().setDropIndicatorsInhibited(hideIndicators);
}
}
break;
default:
break;
}
return false;
}

View File

@@ -27,6 +27,7 @@ public:
private:
void createDockWidgets();
bool eventFilter(QObject *obj, QEvent *ev) override;
KDDockWidgets::DockWidgetBase *newDockWidget();
QMenu *m_toggleMenu = nullptr;
const bool m_dockWidget0IsNonClosable;

View File

@@ -182,8 +182,9 @@ private:
enum RestoreOption {
RestoreOption_None = 0,
RestoreOption_RelativeToMainWindow = 1, ///< Skips restoring the main window geometry and the restored dock widgets will use relative sizing.
///< Loading layouts won't change the main window geometry and just use whatever the user has at the moment.
RestoreOption_RelativeToMainWindow = 1 << 0, ///< Skips restoring the main window geometry and the restored dock widgets will use relative sizing.
///< Loading layouts won't change the main window geometry and just use whatever the user has at the moment.
RestoreOption_AbsoluteFloatingDockWindows = 1 << 1, ///< Skips scaling of floating dock windows relative to the main window.
};
Q_DECLARE_FLAGS(RestoreOptions, RestoreOption)
Q_ENUM_NS(RestoreOptions)

View File

@@ -66,15 +66,22 @@ LayoutSaver::Layout *LayoutSaver::Layout::s_currentLayoutBeingRestored = nullptr
inline InternalRestoreOptions internalRestoreOptions(RestoreOptions options)
{
if (options == RestoreOption_None) {
return InternalRestoreOption::None;
} else if (options == RestoreOption_RelativeToMainWindow) {
return InternalRestoreOptions(InternalRestoreOption::SkipMainWindowGeometry)
| InternalRestoreOption::RelativeFloatingWindowGeometry;
} else {
qWarning() << Q_FUNC_INFO << "Unknown options" << options;
return {};
InternalRestoreOptions ret = {};
if (options.testFlag(RestoreOption_RelativeToMainWindow)) {
ret.setFlag(InternalRestoreOption::SkipMainWindowGeometry);
ret.setFlag(InternalRestoreOption::RelativeFloatingWindowGeometry);
options.setFlag(RestoreOption_RelativeToMainWindow, false);
}
if (options.testFlag(RestoreOption_AbsoluteFloatingDockWindows)) {
ret.setFlag(InternalRestoreOption::RelativeFloatingWindowGeometry, false);
options.setFlag(RestoreOption_AbsoluteFloatingDockWindows, false);
}
if (options != RestoreOption_None) {
qWarning() << Q_FUNC_INFO << "Unknown options" << options;
}
return ret;
}
bool LayoutSaver::Private::s_restoreInProgress = false;

View File

@@ -106,6 +106,9 @@ public:
/// Experimental, internal, not for general use.
void enableFallbackMouseGrabber();
// Returns the active state
StateBase *activeState() const;
Q_SIGNALS:
void mousePressed();
void manhattanLengthMove();
@@ -128,7 +131,6 @@ private:
friend class StateDraggingWayland;
DragController(QObject * = nullptr);
StateBase *activeState() const;
WidgetType *qtTopLevelUnderCursor() const;
Draggable *draggableForQObject(QObject *o) const;
QPoint m_pressPos;

View File

@@ -31,10 +31,14 @@ DropIndicatorOverlayInterface::DropIndicatorOverlayInterface(DropArea *dropArea)
connect(DockRegistry::self(), &DockRegistry::dropIndicatorsInhibitedChanged, this,
[this](bool inhibited) {
if (inhibited)
if (inhibited) {
removeHover();
// if false then simply moving the mouse will make the drop indicators appear again
} else {
// Re-add hover. Fastest way is simply faking a mouse move
if (auto state = qobject_cast<StateDragging *>(DragController::instance()->activeState())) {
state->handleMouseMove(QCursor::pos());
}
}
});
}