diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp
index 066b3c7..6b841cc 100644
--- a/src/widgets/widgets/qdockarealayout.cpp
+++ b/src/widgets/widgets/qdockarealayout.cpp
@@ -52,7 +52,7 @@
 #include "qmainwindowlayout_p.h"
 #include "qdockwidget_p.h"
 #include <private/qlayoutengine_p.h>
-
+#include <qdebug.h>
 #include <qpainter.h>
 #include <qstyleoption.h>
 
@@ -640,7 +640,7 @@ void QDockAreaLayoutInfo::fitItems()
     }
 }
 
-static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_pos,
+static QInternal::DockPosition dockPosHelperI(const QRect &rect, const QPoint &_pos,
                                         Qt::Orientation o,
                                         bool nestingEnabled,
                                         QDockAreaLayoutInfo::TabMode tabMode)
@@ -742,6 +742,17 @@ static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_p
     }
 }
 
+static QInternal::DockPosition dockPosHelper(const QRect &rect, const QPoint &_pos,
+                                        Qt::Orientation o,
+                                        bool nestingEnabled,
+                                        QDockAreaLayoutInfo::TabMode tabMode)
+{
+    QInternal::DockPosition dp = dockPosHelperI(rect,_pos, o, nestingEnabled, tabMode );
+    qDebug() << __FUNCTION__ << rect << _pos << o << "nestingEnabled=" << nestingEnabled
+              << "tabMode=" << tabMode << "returns " << dp;
+    return dp;
+}
+
 QList<int> QDockAreaLayoutInfo::gapIndex(const QPoint& _pos,
                         bool nestingEnabled, TabMode tabMode) const
 {
@@ -830,6 +841,8 @@ QList<int> QDockAreaLayoutInfo::gapIndex(const QPoint& _pos,
             break;
     }
 
+    qDebug() << __FUNCTION__ << rect << _pos << "nestingEnabled=" << nestingEnabled
+              << "tabMode=" << tabMode << "returns " << result;
     return result;
 }
 
@@ -1143,11 +1156,13 @@ static QRect dockedGeometry(QWidget *widget)
 
     QRect result = widget->geometry();
     result.adjust(0, -titleHeight, 0, 0);
+    qDebug() << __FUNCTION__ << widget << result;
     return result;
 }
 
 bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWidgetItem)
 {
+    qDebug() << __FUNCTION__ << path << dockWidgetItem->widget();
     Q_ASSERT(!path.isEmpty());
 
     bool insert_tabbed = false;
@@ -1218,6 +1233,7 @@ bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWid
         // find out how much space we have in the layout
         int space = 0;
         if (isEmpty()) {
+            qDebug() << __FUNCTION__ << "empty";
             // I am an empty dock area, therefore I am a top-level dock area.
             switch (dockPos) {
                 case QInternal::LeftDock:
@@ -1249,6 +1265,7 @@ bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWid
                 space += item.size - pick(o, item.minimumSize());
             }
         }
+        qDebug() << __FUNCTION__ << "space" << space;
 
         // find the actual size of the gap
         int gap_size = 0;
@@ -1268,6 +1285,7 @@ bool QDockAreaLayoutInfo::insertGap(const QList<int> &path, QLayoutItem *dockWid
             gap_size = pick(o, gap_item.minimumSize());
         gap_item.size = gap_size + sep_size;
     }
+    qDebug() << __FUNCTION__ << "size" << gap_item.size;
 
     // finally, insert the gap
     item_list.insert(index, gap_item);
@@ -2378,6 +2396,7 @@ QList<int> QDockAreaLayout::indexOf(QWidget *dockWidget) const
 
 QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const
 {
+    qDebug() << __FUNCTION__ << '>' << pos;
     QMainWindow::DockOptions opts = mainWindow->dockOptions();
     bool nestingEnabled = opts & QMainWindow::AllowNestedDocks;
     QDockAreaLayoutInfo::TabMode tabMode = QDockAreaLayoutInfo::NoTabs;
@@ -2395,12 +2414,15 @@ QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const
 
     for (int i = 0; i < QInternal::DockCount; ++i) {
         const QDockAreaLayoutInfo &info = docks[i];
-
+        qDebug() << __FUNCTION__ << "loopA" << i << "info.isEmpty()"
+                 << info.isEmpty() << "info.rect" << info.rect
+                 << "contains" << pos << info.rect.contains(pos);
         if (!info.isEmpty() && info.rect.contains(pos)) {
             QList<int> result
                 = docks[i].gapIndex(pos, nestingEnabled, tabMode);
             if (!result.isEmpty())
                 result.prepend(i);
+            qDebug() << __FUNCTION__ << "return A" << result;
             return result;
         }
     }
@@ -2426,18 +2448,23 @@ QList<int> QDockAreaLayout::gapIndex(const QPoint &pos) const
                                 rect.width(), EmptyDropAreaSize);
                     break;
             }
+            qDebug() << __FUNCTION__ << "loopB" << i << r << "contains pos" << pos << r.contains(pos);
             if (r.contains(pos)) {
                 if (opts & QMainWindow::ForceTabbedDocks && !info.item_list.isEmpty()) {
                     //in case of ForceTabbedDocks, we pass -1 in order to force the gap to be tabbed
                     //it mustn't be completely empty otherwise it won't work
-                    return QList<int>() << i << -1 << 0;
+                    QList<int> result = QList<int>() << i << -1 << 0;
+                    qDebug() << __FUNCTION__ << "return B" << result;
+                    return result;
                 } else {
-                    return QList<int>() << i << 0;
+                    QList<int> result = QList<int>() << i << 0;
+                    qDebug() << __FUNCTION__ << "return C" << result;
+                    return result;
                 }
             }
         }
     }
-
+    qDebug() << __FUNCTION__ << '<' << "empty";
     return QList<int>();
 }
 
diff --git a/src/widgets/widgets/qdockwidget.cpp b/src/widgets/widgets/qdockwidget.cpp
index ad9481a..2ad98d1 100644
--- a/src/widgets/widgets/qdockwidget.cpp
+++ b/src/widgets/widgets/qdockwidget.cpp
@@ -735,6 +735,7 @@ void QDockWidgetPrivate::startDrag()
 
     if (state->ctrlDrag)
         layout->restore();
+    qDebug() << __FUNCTION__ << '\n' << layout << '\n' << "START";
 
     state->dragging = true;
 }
@@ -749,8 +750,10 @@ void QDockWidgetPrivate::endDrag(bool abort)
     if (state->dragging) {
         QMainWindowLayout *mwLayout = qt_mainwindow_layout(qobject_cast<QMainWindow *>(q->parentWidget()));
         Q_ASSERT(mwLayout != 0);
+        qDebug() << __FUNCTION__ ;
 
         if (abort || !mwLayout->plug(state->widgetItem)) {
+            qDebug() << __FUNCTION__ << "fail, abort=" << abort;
             if (hasFeature(this, QDockWidget::DockWidgetFloatable)) {
                 if (state->ownWidgetItem)
                     delete state->widgetItem;
@@ -774,7 +777,9 @@ void QDockWidgetPrivate::endDrag(bool abort)
                 mwLayout->revert(state->widgetItem);
             }
         }
+        qDebug() << __FUNCTION__ << '\n' << mwLayout;
     }
+
     delete state;
     state = 0;
 }
@@ -872,6 +877,8 @@ bool QDockWidgetPrivate::mouseMoveEvent(QMouseEvent *event)
 
     if (state->dragging && !state->nca) {
         QPoint pos = event->globalPos() - state->pressPos;
+        qDebug() << __FUNCTION__ << "global" << event->globalPos() << "presspos" << state->pressPos
+                 << "->" << pos;
         q->move(pos);
 
         if (state && !state->ctrlDrag)
diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp
index df46c00..33af8e8 100644
--- a/src/widgets/widgets/qmainwindowlayout.cpp
+++ b/src/widgets/widgets/qmainwindowlayout.cpp
@@ -407,6 +407,7 @@ QWidget *QMainWindowLayoutState::centralWidget() const
 QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget,
                                             const QPoint &pos) const
 {
+    qDebug() << __FUNCTION__ << widget << pos;
     QList<int> result;
 
 #ifndef QT_NO_TOOLBAR
@@ -425,10 +426,11 @@ QList<int> QMainWindowLayoutState::gapIndex(QWidget *widget,
         result = dockAreaLayout.gapIndex(pos);
         if (!result.isEmpty())
             result.prepend(1);
+        qDebug() << __FUNCTION__ << "RETURN A" << result;
         return result;
     }
 #endif //QT_NO_DOCKWIDGET
-
+    qDebug() << __FUNCTION__ << '<' << result;
     return result;
 }
 
@@ -563,6 +565,7 @@ QRect QMainWindowLayoutState::gapRect(const QList<int> &path) const
 
 QLayoutItem *QMainWindowLayoutState::plug(const QList<int> &path)
 {
+    qDebug() << __FUNCTION__ << path;
     int i = path.first();
 
 #ifndef QT_NO_TOOLBAR
@@ -580,6 +583,7 @@ QLayoutItem *QMainWindowLayoutState::plug(const QList<int> &path)
 
 QLayoutItem *QMainWindowLayoutState::unplug(const QList<int> &path, QMainWindowLayoutState *other)
 {
+    qDebug() << __FUNCTION__ << path << other;
     int i = path.first();
 
 #ifdef QT_NO_TOOLBAR
@@ -1571,12 +1575,15 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem)
     fixToolBarOrientation(widgetItem, currentGapPos.at(1));
 
     QWidget *widget = widgetItem->widget();
+    qDebug() << __FUNCTION__ << widget << "currentGapPos" << currentGapPos;
 
     QList<int> previousPath = layoutState.indexOf(widget);
 
     const QLayoutItem *it = layoutState.plug(currentGapPos);
-    if (!it)
+    if (!it) {
+        qDebug() << __FUNCTION__ << "!it, return false";
         return false;
+    }
     Q_ASSERT(it == widgetItem);
     if (!previousPath.isEmpty())
         layoutState.remove(previousPath);
@@ -1835,12 +1842,16 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse
 
     QWidget *widget = widgetItem->widget();
     QPoint pos = parentWidget()->mapFromGlobal(mousePos);
+    qDebug() << __FUNCTION__  << widget << "global" << mousePos << "mapped by "
+             << parentWidget() << "to" << pos;
 
     if (!savedState.isValid())
         savedState = layoutState;
 
     QList<int> path = savedState.gapIndex(widget, pos);
 
+    qDebug() << __FUNCTION__  << "got path" << path;
+
     if (!path.isEmpty()) {
         bool allowed = false;
 
@@ -1856,14 +1867,18 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse
         if (!allowed)
             path.clear();
     }
+    qDebug() << __FUNCTION__  << "got path B" << path;
 
-    if (path == currentGapPos)
+    if (path == currentGapPos) {
+        qDebug() << __FUNCTION__  << "returns" << currentGapPos;
         return currentGapPos; // the gap is already there
+    }
 
     currentGapPos = path;
     if (path.isEmpty()) {
         fixToolBarOrientation(widgetItem, 2); // 2 = top dock, ie. horizontal
         restore(true);
+        qDebug() << __FUNCTION__  << "returns EMPTY A";
         return QList<int>();
     }
 
@@ -1873,6 +1888,7 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse
 
     if (!newState.insertGap(path, widgetItem)) {
         restore(true); // not enough space
+        qDebug() << __FUNCTION__  << "returns EMPTY B: not enough space";
         return QList<int>();
     }
 
@@ -1880,6 +1896,8 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse
     QSize size = newState.rect.size();
 
     if (min.width() > size.width() || min.height() > size.height()) {
+        qDebug() << __FUNCTION__  << "returns EMPTY C: size constraints"
+                 << "size=" << size << "min=" << min;
         restore(true);
         return QList<int>();
     }
@@ -1895,6 +1913,7 @@ QList<int> QMainWindowLayout::hover(QLayoutItem *widgetItem, const QPoint &mouse
     applyState(layoutState);
 
     updateGapIndicator();
+    qDebug() << __FUNCTION__  << "<returns" << path;
 
     return path;
 }
