Pass the DropArea to setDropIndicatorAllowedFunc() too
So the lambda can have more advanced usage and inspect the target layout before allowing or disallowing the drop. For our use case, we want to limit max 3 dock widgets side by side, for example.
This commit is contained in:
@@ -267,7 +267,8 @@ int main(int argc, char **argv)
|
||||
// Dock widget 8 will only be allowed to dock to the outer areasa
|
||||
auto func = [](KDDockWidgets::DropLocation location,
|
||||
const KDDockWidgets::DockWidgetBase::List &source,
|
||||
const KDDockWidgets::DockWidgetBase::List &target) {
|
||||
const KDDockWidgets::DockWidgetBase::List &target,
|
||||
KDDockWidgets::DropArea *) {
|
||||
Q_UNUSED(target); // When dragging into a tab, 'target' would have the list of already tabbed dock widgets
|
||||
|
||||
const bool isDraggingDW8 = std::find_if(source.cbegin(), source.cend(), [] (KDDockWidgets::DockWidgetBase *dw) {
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace KDDockWidgets {
|
||||
class DockWidgetBase;
|
||||
class MainWindowBase;
|
||||
class FrameworkWidgetFactory;
|
||||
class DropArea;
|
||||
|
||||
typedef KDDockWidgets::DockWidgetBase *(*DockWidgetFactoryFunc)(const QString &name);
|
||||
typedef KDDockWidgets::MainWindowBase *(*MainWindowFactoryFunc)(const QString &name);
|
||||
@@ -47,11 +48,13 @@ typedef KDDockWidgets::MainWindowBase *(*MainWindowFactoryFunc)(const QString &n
|
||||
/// @param location The drop indicator location to allow or disallow
|
||||
/// @param source The dock widgets being dragged
|
||||
/// @param target The dock widgets within an existing docked tab group
|
||||
/// @param dropArea The target drop area. Can belong to a MainWindow or a FloatingWindow.
|
||||
/// @return true if the docking is allowed.
|
||||
/// @sa setDropIndicatorAllowedFunc
|
||||
typedef bool (*DropIndicatorAllowedFunc)(DropLocation location,
|
||||
const QVector<DockWidgetBase *> &source,
|
||||
const QVector<DockWidgetBase *> &target);
|
||||
const QVector<DockWidgetBase *> &target,
|
||||
DropArea *dropArea);
|
||||
|
||||
/// @deprecated Use DropIndicatorAllowedFunc instead.
|
||||
/// @brief Function to allow the user more granularity to disallow dock widgets to tab together
|
||||
@@ -262,7 +265,8 @@ public:
|
||||
*
|
||||
* auto func = [] (KDDockWidgets::DropLocation loc,
|
||||
* const KDDockWidgets::DockWidgetBase::List &source,
|
||||
* const KDDockWidgets::DockWidgetBase::List &target)
|
||||
* const KDDockWidgets::DockWidgetBase::List &target,
|
||||
* KDDockWidgets::DropArea *)
|
||||
* {
|
||||
* // disallows dockFoo to be docked to outer areas
|
||||
* return !((loc & KDDockWidgets::DropLocation_Outter) && source.contains(dockFoo));
|
||||
|
||||
@@ -96,6 +96,9 @@ public:
|
||||
|
||||
FloatingWindow *floatingWindowBeingDragged() const;
|
||||
|
||||
/// @brief Returns the current drop area under the mouse
|
||||
DropArea *dropAreaUnderCursor() const;
|
||||
|
||||
///@brief Returns the window being dragged
|
||||
WindowBeingDragged *windowBeingDragged() const;
|
||||
|
||||
@@ -126,7 +129,6 @@ private:
|
||||
DragController(QObject * = nullptr);
|
||||
StateBase *activeState() const;
|
||||
WidgetType *qtTopLevelUnderCursor() const;
|
||||
DropArea *dropAreaUnderCursor() const;
|
||||
Draggable *draggableForQObject(QObject *o) const;
|
||||
QPoint m_pressPos;
|
||||
QPoint m_offset;
|
||||
|
||||
@@ -161,7 +161,8 @@ bool DropIndicatorOverlayInterface::dropIndicatorVisible(DropLocation dropLoc) c
|
||||
}
|
||||
|
||||
if (auto dropIndicatorAllowedFunc = Config::self().dropIndicatorAllowedFunc()) {
|
||||
if (!dropIndicatorAllowedFunc(dropLoc, source, target))
|
||||
DropArea *dropArea = DragController::instance()->dropAreaUnderCursor();
|
||||
if (!dropIndicatorAllowedFunc(dropLoc, source, target, dropArea))
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user