diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-23 09:34:24 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-06-23 09:35:41 (GMT) |
commit | 7e1c40f036cc0d1e7ec093a07e77c95a829c4b21 (patch) | |
tree | 6ce3b96432706581e1a73d059d907de4508ea52f /src/gui/widgets | |
parent | 6769af5510b963e10dc045630e1ab07fd16ba6d1 (diff) | |
download | Qt-7e1c40f036cc0d1e7ec093a07e77c95a829c4b21.zip Qt-7e1c40f036cc0d1e7ec093a07e77c95a829c4b21.tar.gz Qt-7e1c40f036cc0d1e7ec093a07e77c95a829c4b21.tar.bz2 |
QDockWidget: size incorrect when moving separator on fixed-size dock.
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/qdockarealayout.cpp | 65 | ||||
-rw-r--r-- | src/gui/widgets/qdockarealayout_p.h | 5 | ||||
-rw-r--r-- | src/gui/widgets/qmainwindowlayout.cpp | 42 | ||||
-rw-r--r-- | src/gui/widgets/qmainwindowlayout_p.h | 7 |
4 files changed, 58 insertions, 61 deletions
diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index 3125304..cbfa5bf 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -924,43 +924,41 @@ static int separatorMoveHelper(QVector<QLayoutStruct> &list, int index, int delt return delta; } -int QDockAreaLayoutInfo::separatorMove(int index, int delta, QVector<QLayoutStruct> *cache) +int QDockAreaLayoutInfo::separatorMove(int index, int delta) { #ifndef QT_NO_TABBAR Q_ASSERT(!tabbed); #endif - if (cache->isEmpty()) { - QVector<QLayoutStruct> &list = *cache; - list.resize(item_list.size()); - for (int i = 0; i < item_list.size(); ++i) { - const QDockAreaLayoutItem &item = item_list.at(i); - QLayoutStruct &ls = list[i]; - Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); - if (item.skip()) { - ls.empty = true; - } else { - ls.empty = false; - ls.pos = item.pos; - ls.size = item.size; - ls.minimumSize = pick(o, item.minimumSize()); - ls.maximumSize = pick(o, item.maximumSize()); - } + QVector<QLayoutStruct> list(item_list.size()); + for (int i = 0; i < list.size(); ++i) { + const QDockAreaLayoutItem &item = item_list.at(i); + QLayoutStruct &ls = list[i]; + Q_ASSERT(!(item.flags & QDockAreaLayoutItem::GapItem)); + if (item.skip()) { + ls.empty = true; + } else { + const int separatorSpace = item.hasFixedSize(o) ? 0 : sep; + ls.empty = false; + ls.pos = item.pos; + ls.size = item.size + separatorSpace; + ls.minimumSize = pick(o, item.minimumSize()) + separatorSpace; + ls.maximumSize = pick(o, item.maximumSize()) + separatorSpace; + } } - QVector<QLayoutStruct> list = *cache; - - delta = separatorMoveHelper(list, index, delta, sep); + //the separator space has been added to the size, so we pass 0 as a parameter + delta = separatorMoveHelper(list, index, delta, 0 /*separator*/); - for (int i = 0; i < item_list.size(); ++i) { + for (int i = 0; i < list.size(); ++i) { QDockAreaLayoutItem &item = item_list[i]; if (item.skip()) continue; QLayoutStruct &ls = list[i]; - item.size = ls.size; + const int separatorSpace = item.hasFixedSize(o) ? 0 : sep; + item.size = ls.size - separatorSpace; item.pos = ls.pos; - if (item.subinfo != 0) { item.subinfo->rect = itemRect(i); item.subinfo->fitItems(); @@ -1974,7 +1972,6 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> } else { int dummy; stream >> item.pos >> item.size >> dummy >> dummy; - // qDebug() << widget << item.pos << item.size; if (!testing) { widget->setFloating(false); widget->setVisible(flags & StateFlagVisible); @@ -3115,31 +3112,29 @@ QRegion QDockAreaLayout::separatorRegion() const } int QDockAreaLayout::separatorMove(QList<int> separator, const QPoint &origin, - const QPoint &dest, - QVector<QLayoutStruct> *cache) + const QPoint &dest) { int delta = 0; int index = separator.last(); + + if (separator.count() > 1) { QDockAreaLayoutInfo *info = this->info(separator); delta = pick(info->o, dest - origin); if (delta != 0) - delta = info->separatorMove(index, delta, cache); + delta = info->separatorMove(index, delta); info->apply(false); return delta; } - if (cache->isEmpty()) { - QVector<QLayoutStruct> &list = *cache; + QVector<QLayoutStruct> list; - if (index == QInternal::LeftDock || index == QInternal::RightDock) - getGrid(0, &list); - else - getGrid(&list, 0); - } + if (index == QInternal::LeftDock || index == QInternal::RightDock) + getGrid(0, &list); + else + getGrid(&list, 0); - QVector<QLayoutStruct> list = *cache; int sep_index = index == QInternal::LeftDock || index == QInternal::TopDock ? 0 : 1; Qt::Orientation o = index == QInternal::LeftDock || index == QInternal::RightDock diff --git a/src/gui/widgets/qdockarealayout_p.h b/src/gui/widgets/qdockarealayout_p.h index 137aeba..771aa52 100644 --- a/src/gui/widgets/qdockarealayout_p.h +++ b/src/gui/widgets/qdockarealayout_p.h @@ -181,7 +181,7 @@ public: void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip, const QPoint &mouse) const; QRegion separatorRegion() const; - int separatorMove(int index, int delta, QVector<QLayoutStruct> *cache); + int separatorMove(int index, int delta); QLayoutItem *itemAt(int *x, int index) const; QLayoutItem *takeAt(int *x, int index); @@ -277,8 +277,7 @@ public: void paintSeparators(QPainter *p, QWidget *widget, const QRegion &clip, const QPoint &mouse) const; QRegion separatorRegion() const; - int separatorMove(QList<int> separator, const QPoint &origin, const QPoint &dest, - QVector<QLayoutStruct> *cache); + int separatorMove(QList<int> separator, const QPoint &origin, const QPoint &dest); void updateSeparatorWidgets() const; QLayoutItem *itemAt(int *x, int index) const; diff --git a/src/gui/widgets/qmainwindowlayout.cpp b/src/gui/widgets/qmainwindowlayout.cpp index 10e07d3..526e7a5 100644 --- a/src/gui/widgets/qmainwindowlayout.cpp +++ b/src/gui/widgets/qmainwindowlayout.cpp @@ -1304,30 +1304,15 @@ bool QMainWindowLayout::separatorMove(const QPoint &pos) if (movingSeparator.isEmpty()) return false; movingSeparatorPos = pos; - separatorMoveTimer->start(); + separatorMoveTimer.start(0, this); return true; } -void QMainWindowLayout::doSeparatorMove() -{ - if (movingSeparator.isEmpty()) - return; - if (movingSeparatorOrigin == movingSeparatorPos) - return; - - layoutState = savedState; - layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin, - movingSeparatorPos, - &separatorMoveCache); - movingSeparatorPos = movingSeparatorOrigin; -} - bool QMainWindowLayout::endSeparatorMove(const QPoint&) { bool result = !movingSeparator.isEmpty(); movingSeparator.clear(); savedState.clear(); - separatorMoveCache.clear(); return result; } @@ -1687,10 +1672,6 @@ QMainWindowLayout::QMainWindowLayout(QMainWindow *mainwindow) #ifndef QT_NO_TABBAR sep = mainwindow->style()->pixelMetric(QStyle::PM_DockWidgetSeparatorExtent, 0, mainwindow); #endif - separatorMoveTimer = new QTimer(this); - separatorMoveTimer->setSingleShot(true); - separatorMoveTimer->setInterval(0); - connect(separatorMoveTimer, SIGNAL(timeout()), this, SLOT(doSeparatorMove())); #ifndef QT_NO_TABWIDGET for (int i = 0; i < QInternal::DockCount; ++i) @@ -1982,6 +1963,27 @@ bool QMainWindowLayout::usesHIToolBar(QToolBar *toolbar) const #endif } +void QMainWindowLayout::timerEvent(QTimerEvent *e) +{ +#ifndef QT_NO_DOCKWIDGET + if (e->timerId() == separatorMoveTimer.timerId()) { + //let's move the separators + separatorMoveTimer.stop(); + if (movingSeparator.isEmpty()) + return; + if (movingSeparatorOrigin == movingSeparatorPos) + return; + + layoutState = savedState; + layoutState.dockAreaLayout.separatorMove(movingSeparator, movingSeparatorOrigin, + movingSeparatorPos); + movingSeparatorPos = movingSeparatorOrigin; + } +#endif + QLayout::timerEvent(e); +} + + QT_END_NAMESPACE #endif // QT_NO_MAINWINDOW diff --git a/src/gui/widgets/qmainwindowlayout_p.h b/src/gui/widgets/qmainwindowlayout_p.h index f5fcbda..26f8633 100644 --- a/src/gui/widgets/qmainwindowlayout_p.h +++ b/src/gui/widgets/qmainwindowlayout_p.h @@ -61,6 +61,7 @@ #include "QtGui/qtabbar.h" #include "QtCore/qvector.h" #include "QtCore/qset.h" +#include "QtCore/qbasictimer.h" #include "private/qlayoutengine_p.h" #include "qdockarealayout_p.h" @@ -165,6 +166,8 @@ public: void setDockOptions(QMainWindow::DockOptions opts); bool usesHIToolBar(QToolBar *toolbar) const; + void timerEvent(QTimerEvent *e); + // status bar QLayoutItem *statusbar; @@ -243,8 +246,7 @@ public: QList<int> movingSeparator; QPoint movingSeparatorOrigin, movingSeparatorPos; - QTimer *separatorMoveTimer; - QVector<QLayoutStruct> separatorMoveCache; + QBasicTimer separatorMoveTimer; bool startSeparatorMove(const QPoint &pos); bool separatorMove(const QPoint &pos); @@ -298,7 +300,6 @@ private slots: void animationFinished(QWidget *widget); void allAnimationsFinished(); #ifndef QT_NO_DOCKWIDGET - void doSeparatorMove(); #ifndef QT_NO_TABBAR void tabChanged(); #endif |