diff options
Diffstat (limited to 'src/gui/widgets')
-rw-r--r-- | src/gui/widgets/qabstractscrollarea.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/qabstractslider.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/qdockarealayout.cpp | 9 | ||||
-rw-r--r-- | src/gui/widgets/qdockwidget.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/qfontcombobox.cpp | 11 | ||||
-rw-r--r-- | src/gui/widgets/qmenu.cpp | 44 | ||||
-rw-r--r-- | src/gui/widgets/qmenu_p.h | 1 | ||||
-rw-r--r-- | src/gui/widgets/qmenubar.cpp | 4 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbar.cpp | 2 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbararealayout.cpp | 50 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbararealayout_p.h | 6 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbarlayout.cpp | 5 | ||||
-rw-r--r-- | src/gui/widgets/qtoolbarlayout_p.h | 2 |
13 files changed, 78 insertions, 74 deletions
diff --git a/src/gui/widgets/qabstractscrollarea.cpp b/src/gui/widgets/qabstractscrollarea.cpp index b0d0baf..35639b7 100644 --- a/src/gui/widgets/qabstractscrollarea.cpp +++ b/src/gui/widgets/qabstractscrollarea.cpp @@ -1130,10 +1130,13 @@ void QAbstractScrollArea::mouseMoveEvent(QMouseEvent *e) void QAbstractScrollArea::wheelEvent(QWheelEvent *e) { Q_D(QAbstractScrollArea); - if (static_cast<QWheelEvent*>(e)->orientation() == Qt::Horizontal) - QApplication::sendEvent(d->hbar, e); - else - QApplication::sendEvent(d->vbar, e); + QScrollBar *const bars[2] = { d->hbar, d->vbar }; + int idx = (e->orientation() == Qt::Vertical) ? 1 : 0; + int other = (idx + 1) % 2; + if (!bars[idx]->isVisible() && bars[other]->isVisible()) + idx = other; // If the scrollbar of the event orientation is hidden, fallback to the other. + + QApplication::sendEvent(bars[idx], e); } #endif diff --git a/src/gui/widgets/qabstractslider.cpp b/src/gui/widgets/qabstractslider.cpp index fec9fab..e0db9c2 100644 --- a/src/gui/widgets/qabstractslider.cpp +++ b/src/gui/widgets/qabstractslider.cpp @@ -690,8 +690,6 @@ void QAbstractSlider::wheelEvent(QWheelEvent * e) { Q_D(QAbstractSlider); e->ignore(); - if (e->orientation() != d->orientation && !rect().contains(e->pos())) - return; int stepsToScroll = 0; qreal offset = qreal(e->delta()) / 120; diff --git a/src/gui/widgets/qdockarealayout.cpp b/src/gui/widgets/qdockarealayout.cpp index dffec11..953edab 100644 --- a/src/gui/widgets/qdockarealayout.cpp +++ b/src/gui/widgets/qdockarealayout.cpp @@ -1841,7 +1841,6 @@ void QDockAreaLayoutInfo::saveState(QDataStream &stream) const } } -#ifdef Q_WS_MAC static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) { switch (pos) { @@ -1853,7 +1852,6 @@ static Qt::DockWidgetArea toDockWidgetArea(QInternal::DockPosition pos) } return Qt::NoDockWidgetArea; } -#endif static QRect constrainedRect(QRect rect, const QRect &desktop) { @@ -1933,6 +1931,9 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> item_list.append(item); } else { QDockAreaLayoutItem item(new QDockWidgetItem(widget)); + if (!testing) { + item_list.append(item); + } if (flags & StateFlagFloating) { bool drawer = false; #ifdef Q_WS_MAC // drawer support @@ -1977,12 +1978,10 @@ bool QDockAreaLayoutInfo::restoreState(QDataStream &stream, QList<QDockWidget*> if (!testing) { widget->setFloating(false); widget->setVisible(flags & StateFlagVisible); + emit widget->dockLocationChanged(toDockWidgetArea(dockPos)); } } - if (!testing) { - item_list.append(item); - } } } else if (nextMarker == SequenceMarker) { int dummy; diff --git a/src/gui/widgets/qdockwidget.cpp b/src/gui/widgets/qdockwidget.cpp index a8e2a37..9cf6af1 100644 --- a/src/gui/widgets/qdockwidget.cpp +++ b/src/gui/widgets/qdockwidget.cpp @@ -1225,6 +1225,7 @@ void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) features &= DockWidgetFeatureMask; if (d->features == features) return; + const bool closableChanged = (d->features ^ features) & DockWidgetClosable; d->features = features; QDockWidgetLayout *layout = qobject_cast<QDockWidgetLayout*>(this->layout()); @@ -1233,6 +1234,10 @@ void QDockWidget::setFeatures(QDockWidget::DockWidgetFeatures features) d->toggleViewAction->setEnabled((d->features & DockWidgetClosable) == DockWidgetClosable); emit featuresChanged(d->features); update(); + if (closableChanged && layout->nativeWindowDeco()) { + //this ensures the native decoration is drawn + d->setWindowState(true /*floating*/, true /*unplug*/); + } } QDockWidget::DockWidgetFeatures QDockWidget::features() const diff --git a/src/gui/widgets/qfontcombobox.cpp b/src/gui/widgets/qfontcombobox.cpp index 806db59..d601f81 100644 --- a/src/gui/widgets/qfontcombobox.cpp +++ b/src/gui/widgets/qfontcombobox.cpp @@ -247,7 +247,14 @@ void QFontComboBoxPrivate::_q_updateModel() } list = result; + //we need to block the signals so that the model doesn't emit reset + //this prevents the current index from changing + //it will be updated just after this + ///TODO: we should finda way to avoid blocking signals and have a real update of the model + const bool old = m->blockSignals(true); m->setStringList(list); + m->blockSignals(old); + if (list.isEmpty()) { if (currentFont != QFont()) { currentFont = QFont(); @@ -420,8 +427,10 @@ void QFontComboBox::setCurrentFont(const QFont &font) Q_D(QFontComboBox); if (font != d->currentFont) { d->currentFont = font; - emit currentFontChanged(d->currentFont); d->_q_updateModel(); + if (d->currentFont == font) { //else the signal has already be emitted by _q_updateModel + emit currentFontChanged(d->currentFont); + } } } diff --git a/src/gui/widgets/qmenu.cpp b/src/gui/widgets/qmenu.cpp index cc39b7f..54d1612 100644 --- a/src/gui/widgets/qmenu.cpp +++ b/src/gui/widgets/qmenu.cpp @@ -602,14 +602,7 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason } #ifndef QT_NO_STATUSTIP } else if (previousAction) { - QWidget *w = causedPopup.widget; - while (QMenu *m = qobject_cast<QMenu*>(w)) - w = m->d_func()->causedPopup.widget; - if (w) { - QString empty; - QStatusTipEvent tip(empty); - QApplication::sendEvent(w, &tip); - } + previousAction->d_func()->showStatusText(topCausedWidget(), QString()); #endif } if (hideActiveMenu) { @@ -623,6 +616,15 @@ void QMenuPrivate::setCurrentAction(QAction *action, int popup, SelectionReason } } +//return the top causedPopup.widget that is not a QMenu +QWidget *QMenuPrivate::topCausedWidget() const +{ + QWidget* top = causedPopup.widget; + while (QMenu* m = qobject_cast<QMenu *>(top)) + top = m->d_func()->causedPopup.widget; + return top; +} + QAction *QMenuPrivate::actionAt(QPoint p) const { if (!q_func()->rect().contains(p)) //sanity check @@ -1094,10 +1096,7 @@ void QMenuPrivate::activateAction(QAction *action, QAction::ActionEvent action_e QAccessible::updateAccessibility(q, actionIndex, QAccessible::Selection); } #endif - QWidget *w = causedPopup.widget; - while (QMenu *m = qobject_cast<QMenu*>(w)) - w = m->d_func()->causedPopup.widget; - action->showStatusText(w); + action->showStatusText(topCausedWidget()); } else { actionAboutToTrigger = 0; } @@ -1801,10 +1800,7 @@ void QMenu::popup(const QPoint &p, QAction *atAction) #ifndef QT_NO_MENUBAR // if this menu is part of a chain attached to a QMenuBar, set the // _NET_WM_WINDOW_TYPE_DROPDOWN_MENU X11 window type - QWidget* top = this; - while (QMenu* m = qobject_cast<QMenu *>(top)) - top = m->d_func()->causedPopup.widget; - setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(top) != 0); + setAttribute(Qt::WA_X11NetWmWindowTypeDropDownMenu, qobject_cast<QMenuBar *>(d->topCausedWidget()) != 0); #endif ensurePolished(); // Get the right font @@ -2752,18 +2748,14 @@ void QMenu::keyPressEvent(QKeyEvent *e) } } if (!key_consumed) { - if (QWidget *caused = d->causedPopup.widget) { - while(QMenu *m = qobject_cast<QMenu*>(caused)) - caused = m->d_func()->causedPopup.widget; #ifndef QT_NO_MENUBAR - if (QMenuBar *mb = qobject_cast<QMenuBar*>(caused)) { - QAction *oldAct = mb->d_func()->currentAction; - QApplication::sendEvent(mb, e); - if (mb->d_func()->currentAction != oldAct) - key_consumed = true; - } -#endif + if (QMenuBar *mb = qobject_cast<QMenuBar*>(d->topCausedWidget())) { + QAction *oldAct = mb->d_func()->currentAction; + QApplication::sendEvent(mb, e); + if (mb->d_func()->currentAction != oldAct) + key_consumed = true; } +#endif } #ifdef Q_OS_WIN32 diff --git a/src/gui/widgets/qmenu_p.h b/src/gui/widgets/qmenu_p.h index a5bde7c..c021063 100644 --- a/src/gui/widgets/qmenu_p.h +++ b/src/gui/widgets/qmenu_p.h @@ -215,6 +215,7 @@ public: SelectedFromKeyboard, SelectedFromElsewhere }; + QWidget *topCausedWidget() const; QAction *actionAt(QPoint p) const; void setFirstActionActive(); void setCurrentAction(QAction *, int popup = -1, SelectionReason reason = SelectedFromElsewhere, bool activateFirst = false); diff --git a/src/gui/widgets/qmenubar.cpp b/src/gui/widgets/qmenubar.cpp index 689d2e1..b1ff662 100644 --- a/src/gui/widgets/qmenubar.cpp +++ b/src/gui/widgets/qmenubar.cpp @@ -332,7 +332,9 @@ void QMenuBarPrivate::popupAction(QAction *action, bool activateFirst) QPoint pos(q->mapToGlobal(QPoint(adjustedActionRect.left(), adjustedActionRect.bottom() + 1))); QSize popup_size = activeMenu->sizeHint(); - QRect screenRect = QApplication::desktop()->screenGeometry(pos); + //we put the popup menu on the screen containing the bottom-center of the action rect + QRect screenRect = QApplication::desktop()->screenGeometry(pos + QPoint(adjustedActionRect.width() / 2, 0)); + pos = QPoint(qMax(pos.x(), screenRect.x()), qMax(pos.y(), screenRect.y())); const bool fitUp = (q->mapToGlobal(adjustedActionRect.topLeft()).y() >= popup_size.height()); const bool fitDown = (pos.y() + popup_size.height() <= screenRect.bottom()); diff --git a/src/gui/widgets/qtoolbar.cpp b/src/gui/widgets/qtoolbar.cpp index 5596ca4..58a3d28 100644 --- a/src/gui/widgets/qtoolbar.cpp +++ b/src/gui/widgets/qtoolbar.cpp @@ -396,7 +396,7 @@ bool QToolBarPrivate::mouseMoveEvent(QMouseEvent *event) void QToolBarPrivate::unplug(const QRect &_r) { Q_Q(QToolBar); - layout->setExpanded(false, false); + layout->setExpanded(false); QRect r = _r; r.moveTopLeft(q->mapToGlobal(QPoint(0, 0))); setWindowState(true, true, r); diff --git a/src/gui/widgets/qtoolbararealayout.cpp b/src/gui/widgets/qtoolbararealayout.cpp index de11625..b7e985c 100644 --- a/src/gui/widgets/qtoolbararealayout.cpp +++ b/src/gui/widgets/qtoolbararealayout.cpp @@ -480,7 +480,7 @@ void QToolBarAreaLayoutInfo::moveToolBar(QToolBar *toolbar, int pos) } -QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const +QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos, int *minDistance) const { int p = pick(o, pos); @@ -509,12 +509,19 @@ QList<int> QToolBarAreaLayoutInfo::gapIndex(const QPoint &pos) const QList<int> result; result << j << k; + *minDistance = 0; //we found a perfect match + return result; + } + } else { + const int dist = distance(pos); + //it will only return a path if the minDistance is higher than the current distance + if (dist >= 0 && *minDistance > dist) { + *minDistance = dist; + + QList<int> result; + result << lines.count() << 0; return result; } - } else if (appendLineDropRect().contains(pos)) { - QList<int> result; - result << lines.count() << 0; - return result; } return QList<int>(); @@ -587,32 +594,20 @@ QRect QToolBarAreaLayoutInfo::itemRect(const QList<int> &path) const return result; } -QRect QToolBarAreaLayoutInfo::appendLineDropRect() const +int QToolBarAreaLayoutInfo::distance(const QPoint &pos) const { - QRect result; - switch (dockPos) { case QInternal::LeftDock: - result = QRect(rect.right(), rect.top(), - EmptyDockAreaSize, rect.height()); - break; + return pos.x() - rect.right(); case QInternal::RightDock: - result = QRect(rect.left() - EmptyDockAreaSize, rect.top(), - EmptyDockAreaSize, rect.height()); - break; + return rect.left() - pos.x(); case QInternal::TopDock: - result = QRect(rect.left(), rect.bottom() + 1, - rect.width(), EmptyDockAreaSize); - break; + return pos.y() - rect.bottom(); case QInternal::BottomDock: - result = QRect(rect.left(), rect.top() - EmptyDockAreaSize, - rect.width(), EmptyDockAreaSize); - break; + return rect.top() - pos.y(); default: - break; + return -1; } - - return result; } /****************************************************************************** @@ -1022,21 +1017,24 @@ QList<int> QToolBarAreaLayout::indexOf(QWidget *toolBar) const return result; } +//this functions returns the path to the possible gapindex for the position pos QList<int> QToolBarAreaLayout::gapIndex(const QPoint &pos) const { Qt::LayoutDirection dir = mainWindow->layoutDirection(); + int minDistance = 80; // when a dock area is empty, how "wide" is it? + QList<int> ret; //return value for (int i = 0; i < QInternal::DockCount; ++i) { QPoint p = pos; if (docks[i].o == Qt::Horizontal) p = QStyle::visualPos(dir, docks[i].rect, p); - QList<int> result = docks[i].gapIndex(p); + QList<int> result = docks[i].gapIndex(p, &minDistance); if (!result.isEmpty()) { result.prepend(i); - return result; + ret = result; } } - return QList<int>(); + return ret; } QList<int> QToolBarAreaLayout::currentGapIndex() const diff --git a/src/gui/widgets/qtoolbararealayout_p.h b/src/gui/widgets/qtoolbararealayout_p.h index 1e113b7..f0ab80c 100644 --- a/src/gui/widgets/qtoolbararealayout_p.h +++ b/src/gui/widgets/qtoolbararealayout_p.h @@ -155,8 +155,6 @@ public: class QToolBarAreaLayoutInfo { public: - enum { EmptyDockAreaSize = 80 }; // when a dock area is empty, how "wide" is it? - QToolBarAreaLayoutInfo(QInternal::DockPosition pos = QInternal::TopDock); QList<QToolBarAreaLayoutLine> lines; @@ -173,11 +171,11 @@ public: void removeToolBarBreak(QToolBar *before); void moveToolBar(QToolBar *toolbar, int pos); - QList<int> gapIndex(const QPoint &pos) const; + QList<int> gapIndex(const QPoint &pos, int *maxDistance) const; bool insertGap(const QList<int> &path, QLayoutItem *item); void clear(); QRect itemRect(const QList<int> &path) const; - QRect appendLineDropRect() const; + int distance(const QPoint &pos) const; QRect rect; Qt::Orientation o; diff --git a/src/gui/widgets/qtoolbarlayout.cpp b/src/gui/widgets/qtoolbarlayout.cpp index 7dc1e01..0afe5d8 100644 --- a/src/gui/widgets/qtoolbarlayout.cpp +++ b/src/gui/widgets/qtoolbarlayout.cpp @@ -642,7 +642,7 @@ QSize QToolBarLayout::expandedSize(const QSize &size) const return result; } -void QToolBarLayout::setExpanded(bool exp, bool animated) +void QToolBarLayout::setExpanded(bool exp) { if (exp == expanded) return; @@ -654,7 +654,6 @@ void QToolBarLayout::setExpanded(bool exp, bool animated) if (!tb) return; if (QMainWindow *win = qobject_cast<QMainWindow*>(tb->parentWidget())) { - animating = true; QMainWindowLayout *layout = qobject_cast<QMainWindowLayout*>(win->layout()); if (expanded) { tb->raise(); @@ -665,7 +664,7 @@ void QToolBarLayout::setExpanded(bool exp, bool animated) layoutActions(rect.size()); } } - layout->layoutState.toolBarAreaLayout.apply(animated); + layout->layoutState.toolBarAreaLayout.apply(win->isAnimated()); } } diff --git a/src/gui/widgets/qtoolbarlayout_p.h b/src/gui/widgets/qtoolbarlayout_p.h index d49a5df..afd0227 100644 --- a/src/gui/widgets/qtoolbarlayout_p.h +++ b/src/gui/widgets/qtoolbarlayout_p.h @@ -112,7 +112,7 @@ public: bool hasExpandFlag() const; public Q_SLOTS: - void setExpanded(bool b, bool animated = true); + void setExpanded(bool b); private: QList<QToolBarItem*> items; |