diff options
author | Liang Qi <liang.qi@qt.io> | 2017-04-20 11:19:14 +0200 |
---|---|---|
committer | Liang Qi <liang.qi@qt.io> | 2017-04-20 12:31:27 +0200 |
commit | 7950b6b283549c98f1e0f981c84b68071a13b616 (patch) | |
tree | cf7281872045ebd57c68e10064ff0f400084aa13 /src/widgets | |
parent | 58d2927861d3e57cac4f6db599e209d2bfb17a2c (diff) | |
parent | 0794d61c822585530243f638687b8a75f0a15d0c (diff) |
Merge remote-tracking branch 'origin/5.9' into dev
Conflicts:
src/corelib/tools/qbytearray.h
src/corelib/tools/qdatetime.h
src/corelib/tools/qstring.h
src/corelib/tools/qversionnumber.h
src/plugins/platforms/android/qandroidplatformintegration.cpp
tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp
Change-Id: Iefd92a435e687a76cd593099e40d9a9620a1454d
Diffstat (limited to 'src/widgets')
-rw-r--r-- | src/widgets/configure.json | 4 | ||||
-rw-r--r-- | src/widgets/effects/qpixmapfilter.cpp | 9 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsitem.cpp | 1 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsscene.cpp | 4 | ||||
-rw-r--r-- | src/widgets/kernel/qdesktopwidget.cpp | 5 | ||||
-rw-r--r-- | src/widgets/kernel/qlayout.cpp | 31 | ||||
-rw-r--r-- | src/widgets/kernel/qsizepolicy.h | 3 | ||||
-rw-r--r-- | src/widgets/kernel/qwidget.cpp | 8 | ||||
-rw-r--r-- | src/widgets/styles/qfusionstyle.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qlineedit_p.cpp | 11 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu.cpp | 143 | ||||
-rw-r--r-- | src/widgets/widgets/qmenu_p.h | 15 | ||||
-rw-r--r-- | src/widgets/widgets/qsplitter.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qtextedit.cpp | 2 | ||||
-rw-r--r-- | src/widgets/widgets/qwidgettextcontrol.cpp | 1 |
15 files changed, 173 insertions, 70 deletions
diff --git a/src/widgets/configure.json b/src/widgets/configure.json index 152c204613..b1a301c7d0 100644 --- a/src/widgets/configure.json +++ b/src/widgets/configure.json @@ -19,9 +19,9 @@ "libraries": { "gtk3": { - "label": "GTK+", + "label": "GTK+ >= 3.6", "sources": [ - { "type": "pkgConfig", "args": "gtk+-3.0" } + { "type": "pkgConfig", "args": "gtk+-3.0 >= 3.6" } ] } }, diff --git a/src/widgets/effects/qpixmapfilter.cpp b/src/widgets/effects/qpixmapfilter.cpp index 1ff4f8e88a..999e551af4 100644 --- a/src/widgets/effects/qpixmapfilter.cpp +++ b/src/widgets/effects/qpixmapfilter.cpp @@ -719,6 +719,7 @@ void expblur(QImage &img, qreal radius, bool improvedQuality = false, int transp } QImage temp(img.height(), img.width(), img.format()); + temp.setDevicePixelRatio(img.devicePixelRatioF()); if (transposed >= 0) { if (img.depth() == 8) { qt_memrotate270(reinterpret_cast<const quint8*>(img.bits()), @@ -780,6 +781,7 @@ Q_WIDGETS_EXPORT QImage qt_halfScaled(const QImage &source) if (source.format() == QImage::Format_Indexed8 || source.format() == QImage::Format_Grayscale8) { // assumes grayscale QImage dest(source.width() / 2, source.height() / 2, srcImage.format()); + dest.setDevicePixelRatio(source.devicePixelRatioF()); const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits()); int sx = srcImage.bytesPerLine(); @@ -801,6 +803,7 @@ Q_WIDGETS_EXPORT QImage qt_halfScaled(const QImage &source) return dest; } else if (source.format() == QImage::Format_ARGB8565_Premultiplied) { QImage dest(source.width() / 2, source.height() / 2, srcImage.format()); + dest.setDevicePixelRatio(source.devicePixelRatioF()); const uchar *src = reinterpret_cast<const uchar*>(const_cast<const QImage &>(srcImage).bits()); int sx = srcImage.bytesPerLine(); @@ -837,6 +840,7 @@ Q_WIDGETS_EXPORT QImage qt_halfScaled(const QImage &source) } QImage dest(source.width() / 2, source.height() / 2, srcImage.format()); + dest.setDevicePixelRatio(source.devicePixelRatioF()); const quint32 *src = reinterpret_cast<const quint32*>(const_cast<const QImage &>(srcImage).bits()); int sx = srcImage.bytesPerLine() >> 2; @@ -881,7 +885,7 @@ Q_WIDGETS_EXPORT void qt_blurImage(QPainter *p, QImage &blurImage, qreal radius, if (p) { p->scale(scale, scale); p->setRenderHint(QPainter::SmoothPixmapTransform); - p->drawImage(QRect(0, 0, blurImage.width(), blurImage.height()), blurImage); + p->drawImage(QRect(QPoint(0, 0), blurImage.size() / blurImage.devicePixelRatioF()), blurImage); } } @@ -1111,6 +1115,7 @@ void QPixmapColorizeFilter::draw(QPainter *painter, const QPointF &dest, const Q srcImage = srcImage.convertToFormat(srcImage.hasAlphaChannel() ? QImage::Format_ARGB32_Premultiplied : QImage::Format_RGB32); destImage = QImage(rect.size(), srcImage.format()); } + destImage.setDevicePixelRatio(src.devicePixelRatioF()); // do colorizing QPainter destPainter(&destImage); @@ -1315,6 +1320,7 @@ void QPixmapDropShadowFilter::draw(QPainter *p, return; QImage tmp(px.size(), QImage::Format_ARGB32_Premultiplied); + tmp.setDevicePixelRatio(px.devicePixelRatioF()); tmp.fill(0); QPainter tmpPainter(&tmp); tmpPainter.setCompositionMode(QPainter::CompositionMode_Source); @@ -1323,6 +1329,7 @@ void QPixmapDropShadowFilter::draw(QPainter *p, // blur the alpha channel QImage blurred(tmp.size(), QImage::Format_ARGB32_Premultiplied); + blurred.setDevicePixelRatio(px.devicePixelRatioF()); blurred.fill(0); QPainter blurPainter(&blurred); qt_blurImage(&blurPainter, tmp, d->radius, false, true); diff --git a/src/widgets/graphicsview/qgraphicsitem.cpp b/src/widgets/graphicsview/qgraphicsitem.cpp index f2b8b66fed..3ce9c835db 100644 --- a/src/widgets/graphicsview/qgraphicsitem.cpp +++ b/src/widgets/graphicsview/qgraphicsitem.cpp @@ -2981,6 +2981,7 @@ QRectF QGraphicsItemPrivate::effectiveBoundingRect(QGraphicsItem *topMostEffectI return brect; #else //QT_NO_GRAPHICSEFFECT + Q_UNUSED(topMostEffectItem); return q_ptr->boundingRect(); #endif //QT_NO_GRAPHICSEFFECT diff --git a/src/widgets/graphicsview/qgraphicsscene.cpp b/src/widgets/graphicsview/qgraphicsscene.cpp index e6726285d9..35f6298a8a 100644 --- a/src/widgets/graphicsview/qgraphicsscene.cpp +++ b/src/widgets/graphicsview/qgraphicsscene.cpp @@ -1225,15 +1225,15 @@ bool QGraphicsScenePrivate::filterEvent(QGraphicsItem *item, QEvent *event) */ bool QGraphicsScenePrivate::sendEvent(QGraphicsItem *item, QEvent *event) { +#if QT_CONFIG(gestures) if (QGraphicsObject *object = item->toGraphicsObject()) { -#ifndef QT_NO_GESTURES QGestureManager *gestureManager = QApplicationPrivate::instance()->gestureManager; if (gestureManager) { if (gestureManager->filterEvent(object, event)) return true; } -#endif // QT_NO_GESTURES } +#endif // QT_CONFIG(gestures) if (filterEvent(item, event)) return false; diff --git a/src/widgets/kernel/qdesktopwidget.cpp b/src/widgets/kernel/qdesktopwidget.cpp index eee818b685..1e6fbfd239 100644 --- a/src/widgets/kernel/qdesktopwidget.cpp +++ b/src/widgets/kernel/qdesktopwidget.cpp @@ -269,12 +269,13 @@ int QDesktopWidget::screenNumber(const QWidget *w) const QRect frame = w->frameGeometry(); if (!w->isWindow()) frame.moveTopLeft(w->mapToGlobal(QPoint(0, 0))); - const QRect nativeFrame = QHighDpi::toNativePixels(frame, winHandle); QScreen *widgetScreen = Q_NULLPTR; int largestArea = 0; foreach (QScreen *screen, screens) { - const QRect intersected = screen->handle()->geometry().intersected(nativeFrame); + const QRect deviceIndependentScreenGeometry = + QHighDpi::fromNativePixels(screen->handle()->geometry(), screen); + const QRect intersected = deviceIndependentScreenGeometry.intersected(frame); int area = intersected.width() * intersected.height(); if (largestArea < area) { widgetScreen = screen; diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index f88ed350c7..129c12885a 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -641,21 +641,11 @@ void QLayout::childEvent(QChildEvent *e) if (!d->enabled) return; - if (e->type() == QEvent::ChildRemoved) { - QChildEvent *c = (QChildEvent*)e; - int i = 0; - - QLayoutItem *item; - while ((item = itemAt(i))) { - if (item == static_cast<QLayout*>(c->child())) { - takeAt(i); - invalidate(); - break; - } else { - ++i; - } - } - } + if (e->type() != QEvent::ChildRemoved) + return; + + if (QLayout *childLayout = qobject_cast<QLayout *>(e->child())) + removeItem(childLayout); } /*! @@ -766,13 +756,10 @@ QSize QLayout::totalMaximumSize() const QLayout::~QLayout() { Q_D(QLayout); - /* - This function may be called during the QObject destructor, - when the parent no longer is a QWidget. - */ - if (d->topLevel && parent() && parent()->isWidgetType() && - ((QWidget*)parent())->layout() == this) - ((QWidget*)parent())->d_func()->layout = 0; + if (d->topLevel && parent() && parent()->isWidgetType() && parentWidget()->layout() == this) + parentWidget()->d_func()->layout = 0; + else if (QLayout *parentLayout = qobject_cast<QLayout *>(parent())) + parentLayout->removeItem(this); } diff --git a/src/widgets/kernel/qsizepolicy.h b/src/widgets/kernel/qsizepolicy.h index 6cb4e147e9..dba742dec5 100644 --- a/src/widgets/kernel/qsizepolicy.h +++ b/src/widgets/kernel/qsizepolicy.h @@ -159,10 +159,11 @@ public: Q_DECL_RELAXED_CONSTEXPR void setRetainSizeWhenHidden(bool retainSize) Q_DECL_NOTHROW { bits.retainSizeWhenHidden = retainSize; } Q_DECL_RELAXED_CONSTEXPR void transpose() Q_DECL_NOTHROW { *this = transposed(); } + Q_REQUIRED_RESULT #ifndef Q_QDOC QT_SIZEPOLICY_CONSTEXPR_AND_UNIFORM_INIT #endif - QSizePolicy transposed() const Q_DECL_NOTHROW Q_REQUIRED_RESULT + QSizePolicy transposed() const Q_DECL_NOTHROW { return QSizePolicy(bits.transposed()); } diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index e26e9af2c5..7112e1c783 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -340,10 +340,6 @@ QWidgetPrivate::~QWidgetPrivate() if (extra) deleteExtra(); - -#ifndef QT_NO_GRAPHICSEFFECT - delete graphicsEffect; -#endif //QT_NO_GRAPHICSEFFECT } /*! @@ -1717,6 +1713,10 @@ QWidget::~QWidget() } QT_CATCH(const std::exception&) { // if this fails we can't do anything about it but at least we are not allowed to throw. } + +#if QT_CONFIG(graphicseffect) + delete d->graphicsEffect; +#endif } int QWidgetPrivate::instanceCounter = 0; // Current number of widget instances diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index c874b12e45..123aa351cd 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -1956,10 +1956,10 @@ void QFusionStyle::drawComplexControl(ComplexControl control, const QStyleOption #if QT_CONFIG(spinbox) || QT_CONFIG(slider) QColor buttonColor = d->buttonColor(option->palette); + QColor gradientStopColor = buttonColor; #endif #if QT_CONFIG(slider) QColor gradientStartColor = buttonColor.lighter(118); - QColor gradientStopColor = buttonColor; #endif QColor outline = d->outline(option->palette); diff --git a/src/widgets/widgets/qlineedit_p.cpp b/src/widgets/widgets/qlineedit_p.cpp index 7c5ba79cb6..e1c7a4e280 100644 --- a/src/widgets/widgets/qlineedit_p.cpp +++ b/src/widgets/widgets/qlineedit_p.cpp @@ -533,6 +533,17 @@ QWidget *QLineEditPrivate::addAction(QAction *newAction, QAction *before, QLineE return nullptr; #endif } + + // QTBUG-59957: clear button should be the leftmost action. + if (!before && !(flags & SideWidgetClearButton) && position == QLineEdit::TrailingPosition) { + for (const SideWidgetEntry &e : trailingSideWidgets) { + if (e.flags & SideWidgetClearButton) { + before = e.action; + break; + } + } + } + // If there is a 'before' action, it takes preference // There's a bug in GHS compiler that causes internal error on the following code. diff --git a/src/widgets/widgets/qmenu.cpp b/src/widgets/widgets/qmenu.cpp index a06b9b404f..8498835a34 100644 --- a/src/widgets/widgets/qmenu.cpp +++ b/src/widgets/widgets/qmenu.cpp @@ -84,18 +84,38 @@ class QTornOffMenu : public QMenu Q_OBJECT class QTornOffMenuPrivate : public QMenuPrivate { - Q_DECLARE_PUBLIC(QMenu) + Q_DECLARE_PUBLIC(QTornOffMenu) public: - QTornOffMenuPrivate(QMenu *p) : causedMenu(p) { + QTornOffMenuPrivate(QMenu *p) : causedMenu(p), initialized(false) { tornoff = 1; causedPopup.widget = 0; - causedPopup.action = ((QTornOffMenu*)p)->d_func()->causedPopup.action; - causedStack = ((QTornOffMenu*)p)->d_func()->calcCausedStack(); + causedPopup.action = p->d_func()->causedPopup.action; + causedStack = p->d_func()->calcCausedStack(); + } + + void setMenuSize(const QSize &menuSize) { + Q_Q(QTornOffMenu); + QSize size = menuSize; + const QPoint p = (!initialized) ? causedMenu->pos() : q->pos(); + QRect screen = popupGeometry(QApplication::desktop()->screenNumber(p)); + const int desktopFrame = q->style()->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, 0, q); + const int titleBarHeight = q->style()->pixelMetric(QStyle::PM_TitleBarHeight, 0, q); + if (scroll && (size.height() > screen.height() - titleBarHeight || size.width() > screen.width())) { + const int fw = q->style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, q); + const int hmargin = q->style()->pixelMetric(QStyle::PM_MenuHMargin, 0, q); + scroll->scrollFlags |= uint(QMenuPrivate::QMenuScroller::ScrollDown); + size.setWidth(qMin(actionRects.at(getLastVisibleAction()).right() + fw + hmargin + rightmargin + 1, screen.width())); + size.setHeight(screen.height() - desktopFrame * 2 - titleBarHeight); + } + q->setFixedSize(size); } + QVector<QPointer<QWidget> > calcCausedStack() const Q_DECL_OVERRIDE { return causedStack; } QPointer<QMenu> causedMenu; QVector<QPointer<QWidget> > causedStack; + bool initialized; }; + public: QTornOffMenu(QMenu *p) : QMenu(*(new QTornOffMenuPrivate(p))) { @@ -109,11 +129,22 @@ public: setAttribute(Qt::WA_X11NetWmWindowTypeMenu, true); setWindowTitle(p->windowTitle()); setEnabled(p->isEnabled()); +#if QT_CONFIG(cssparser) + setStyleSheet(p->styleSheet()); +#endif + if (style() != p->style()) + setStyle(p->style()); + int leftMargin, topMargin, rightMargin, bottomMargin; + p->getContentsMargins(&leftMargin, &topMargin, &rightMargin, &bottomMargin); + setContentsMargins(leftMargin, topMargin, rightMargin, bottomMargin); + setLayoutDirection(p->layoutDirection()); //QObject::connect(this, SIGNAL(triggered(QAction*)), this, SLOT(onTrigger(QAction*))); //QObject::connect(this, SIGNAL(hovered(QAction*)), this, SLOT(onHovered(QAction*))); QList<QAction*> items = p->actions(); for(int i = 0; i < items.count(); i++) addAction(items.at(i)); + d->setMenuSize(sizeHint()); + d->initialized = true; } void syncWithMenu(QMenu *menu, QActionEvent *act) { @@ -127,12 +158,17 @@ public: } void actionEvent(QActionEvent *e) Q_DECL_OVERRIDE { + Q_D(QTornOffMenu); QMenu::actionEvent(e); - setFixedSize(sizeHint()); + if (d->initialized) { + d->setMenuSize(sizeHint()); + } } + public slots: void onTrigger(QAction *action) { d_func()->activateAction(action, QAction::Trigger, false); } void onHovered(QAction *action) { d_func()->activateAction(action, QAction::Hover, false); } + private: Q_DECLARE_PRIVATE(QTornOffMenu) friend class QMenuPrivate; @@ -267,9 +303,6 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const int lastVisibleAction = getLastVisibleAction(); - int max_column_width = 0, - dh = screen.height(), - y = 0; QStyle *style = q->style(); QStyleOption opt; opt.init(q); @@ -279,6 +312,10 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q); const int deskFw = style->pixelMetric(QStyle::PM_MenuDesktopFrameWidth, &opt, q); const int tearoffHeight = tearoff ? style->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q) : 0; + const int base_y = vmargin + fw + topmargin + (scroll ? scroll->scrollOffset : 0) + tearoffHeight; + int max_column_width = 0; + int dh = screen.height(); + int y = base_y; //for compatibility now - will have to refactor this away tabWidth = 0; @@ -356,25 +393,25 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const max_column_width = qMax(max_column_width, sz.width()); //wrapping if (!scroll && - y+sz.height()+vmargin > dh - (deskFw * 2)) { + y + sz.height() + vmargin + bottommargin + fw > dh - (deskFw * 2)) { ncols++; - y = vmargin; + y = base_y; + } else { + y += sz.height(); } - y += sz.height(); //update the item actionRects[i] = QRect(0, 0, sz.width(), sz.height()); } } max_column_width += tabWidth; //finally add in the tab width - const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, &opt, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width(); - const int min_column_width = q->minimumWidth() - (sfcMargin + leftmargin + rightmargin + 2 * (fw + hmargin)); - max_column_width = qMax(min_column_width, max_column_width); + if (!tornoff || (tornoff && scroll)) { // exclude non-scrollable tear-off menu since the tear-off menu has a fixed size + const int sfcMargin = style->sizeFromContents(QStyle::CT_Menu, &opt, QApplication::globalStrut(), q).width() - QApplication::globalStrut().width(); + const int min_column_width = q->minimumWidth() - (sfcMargin + leftmargin + rightmargin + 2 * (fw + hmargin)); + max_column_width = qMax(min_column_width, max_column_width); + } //calculate position - const int base_y = vmargin + fw + topmargin + - (scroll ? scroll->scrollOffset : 0) + - tearoffHeight; int x = hmargin + fw + leftmargin; y = base_y; @@ -383,7 +420,7 @@ void QMenuPrivate::updateActionRects(const QRect &screen) const if (rect.isNull()) continue; if (!scroll && - y+rect.height() > dh - deskFw * 2) { + y + rect.height() + vmargin + bottommargin + fw > dh - deskFw * 2) { x += max_column_width + hmargin; y = base_y; } @@ -632,6 +669,7 @@ void QMenuSloppyState::reset() m_enabled = false; m_first_mouse = true; m_init_guard = false; + m_use_reset_action = true; m_uni_dir_discarded_count = 0; m_time.stop(); m_reset_action = Q_NULLPTR; @@ -684,6 +722,7 @@ void QMenuSloppyState::setSubMenuPopup(const QRect &actionRect, QAction *resetAc { m_enabled = true; m_init_guard = true; + m_use_reset_action = true; m_time.stop(); m_action_rect = actionRect; m_sub_menu = subMenu; @@ -744,10 +783,12 @@ void QMenuSloppyState::timeout() if (m_sub_menu) menu_priv->hideMenu(m_sub_menu); - if (reallyHasMouse) - menu_priv->setCurrentAction(m_reset_action,0); - else + if (reallyHasMouse) { + if (m_use_reset_action) + menu_priv->setCurrentAction(m_reset_action, 0); + } else { menu_priv->setCurrentAction(Q_NULLPTR, 0); + } } //return the top causedPopup.widget that is not a QMenu @@ -761,7 +802,7 @@ QWidget *QMenuPrivate::topCausedWidget() const QAction *QMenuPrivate::actionAt(QPoint p) const { - if (!q_func()->rect().contains(p)) //sanity check + if (!rect().contains(p)) //sanity check return 0; for(int i = 0; i < actionRects.count(); i++) { @@ -855,6 +896,19 @@ void QMenuPrivate::drawTearOff(QPainter *painter, const QRect &rect) q->style()->drawControl(QStyle::CE_MenuTearoff, &menuOpt, painter, q); } +QRect QMenuPrivate::rect() const +{ + Q_Q(const QMenu); + QStyle *style = q->style(); + QStyleOption opt(0); + opt.init(q); + const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, &opt, q); + const int vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, &opt, q); + const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q); + return (q->rect().adjusted(hmargin + fw + leftmargin, vmargin + fw + topmargin, + -(hmargin + fw + rightmargin), -(vmargin + fw + bottommargin))); +} + QMenuPrivate::ScrollerTearOffItem::ScrollerTearOffItem(QMenuPrivate::ScrollerTearOffItem::Type type, QMenuPrivate *mPrivate, QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f), menuPrivate(mPrivate), scrollType(type) { @@ -989,7 +1043,9 @@ void QMenuPrivate::scrollMenu(QAction *action, QMenuScroller::ScrollLocation loc } if (!(newScrollFlags & QMenuScroller::ScrollDown) && (scroll->scrollFlags & QMenuScroller::ScrollDown)) { - newOffset = q->height() - (saccum - newOffset) - fw*2 - vmargin; //last item at bottom + newOffset = q->height() - (saccum - newOffset) - fw*2 - vmargin - topmargin - bottommargin; //last item at bottom + if (tearoff) + newOffset -= q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q); } if (!(newScrollFlags & QMenuScroller::ScrollUp) && (scroll->scrollFlags & QMenuScroller::ScrollUp)) { @@ -1141,15 +1197,23 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) { Q_Q(QMenu); QPoint pos = q->mapFromGlobal(e->globalPos()); + + QStyle *style = q->style(); + QStyleOption opt(0); + opt.init(q); + const int hmargin = style->pixelMetric(QStyle::PM_MenuHMargin, &opt, q); + const int vmargin = style->pixelMetric(QStyle::PM_MenuVMargin, &opt, q); + const int fw = style->pixelMetric(QStyle::PM_MenuPanelWidth, &opt, q); + if (scroll && !activeMenu) { //let the scroller "steal" the event bool isScroll = false; if (pos.x() >= 0 && pos.x() < q->width()) { - for(int dir = QMenuScroller::ScrollUp; dir <= QMenuScroller::ScrollDown; dir = dir << 1) { + for (int dir = QMenuScroller::ScrollUp; dir <= QMenuScroller::ScrollDown; dir = dir << 1) { if (scroll->scrollFlags & dir) { if (dir == QMenuScroller::ScrollUp) - isScroll = (pos.y() <= scrollerHeight()); + isScroll = (pos.y() <= scrollerHeight() + fw + vmargin + topmargin); else if (dir == QMenuScroller::ScrollDown) - isScroll = (pos.y() >= q->height() - scrollerHeight()); + isScroll = (pos.y() >= q->height() - scrollerHeight() - fw - vmargin - bottommargin); if (isScroll) { scroll->scrollDirection = dir; break; @@ -1166,7 +1230,8 @@ bool QMenuPrivate::mouseEventTaken(QMouseEvent *e) } if (tearoff) { //let the tear off thingie "steal" the event.. - QRect tearRect(0, 0, q->width(), q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, q)); + QRect tearRect(leftmargin + hmargin + fw, topmargin + vmargin + fw, q->width() - fw * 2 - hmargin * 2 -leftmargin - rightmargin, + q->style()->pixelMetric(QStyle::PM_MenuTearoffHeight, &opt, q)); if (scroll && scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) tearRect.translate(0, scrollerHeight()); q->update(tearRect); @@ -2615,21 +2680,28 @@ void QMenu::paintEvent(QPaintEvent *e) //calculate the scroll up / down rect const int fw = style()->pixelMetric(QStyle::PM_MenuPanelWidth, 0, this); + const int hmargin = style()->pixelMetric(QStyle::PM_MenuHMargin,0, this); + const int vmargin = style()->pixelMetric(QStyle::PM_MenuVMargin, 0, this); + QRect scrollUpRect, scrollDownRect; + const int leftmargin = fw + hmargin + d->leftmargin; + const int topmargin = fw + vmargin + d->topmargin; + const int bottommargin = fw + vmargin + d->bottommargin; + const int contentWidth = width() - (fw + hmargin) * 2 - d->leftmargin - d->rightmargin; if (d->scroll) { if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) - scrollUpRect.setRect(fw, fw, width() - (fw * 2), d->scrollerHeight()); + scrollUpRect.setRect(leftmargin, topmargin, contentWidth, d->scrollerHeight()); if (d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollDown) - scrollDownRect.setRect(fw, height() - d->scrollerHeight() - fw, width() - (fw * 2), - d->scrollerHeight()); + scrollDownRect.setRect(leftmargin, height() - d->scrollerHeight() - bottommargin, + contentWidth, d->scrollerHeight()); } //calculate the tear off rect QRect tearOffRect; if (d->tearoff) { - tearOffRect.setRect(fw, fw, width() - (fw * 2), - style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this)); + tearOffRect.setRect(leftmargin, topmargin, contentWidth, + style()->pixelMetric(QStyle::PM_MenuTearoffHeight, 0, this)); if (d->scroll && d->scroll->scrollFlags & QMenuPrivate::QMenuScroller::ScrollUp) tearOffRect.translate(0, d->scrollerHeight()); } @@ -2646,6 +2718,12 @@ void QMenu::paintEvent(QPaintEvent *e) emptyArea -= QRegion(actionRect); QRect adjustedActionRect = actionRect; + if (!scrollUpTearOffRect.isEmpty() && adjustedActionRect.bottom() <= scrollUpTearOffRect.top()) + continue; + + if (!scrollDownRect.isEmpty() && adjustedActionRect.top() >= scrollDownRect.bottom()) + continue; + if (adjustedActionRect.intersects(scrollUpTearOffRect)) { if (adjustedActionRect.bottom() <= scrollUpTearOffRect.bottom()) continue; @@ -3476,7 +3554,6 @@ void QMenu::actionEvent(QActionEvent *e) } if (isVisible()) { - d->updateActionRects(); resize(sizeHint()); update(); } diff --git a/src/widgets/widgets/qmenu_p.h b/src/widgets/widgets/qmenu_p.h index 898fa3161b..2f04fac3c0 100644 --- a/src/widgets/widgets/qmenu_p.h +++ b/src/widgets/widgets/qmenu_p.h @@ -95,6 +95,7 @@ public: , m_select_other_actions(false) , m_first_mouse(true) , m_init_guard(false) + , m_use_reset_action(true) , m_uni_dir_discarded_count(0) , m_uni_dir_fail_at_count(0) , m_timeout(0) @@ -182,9 +183,17 @@ public: QSetValueOnDestroy<bool> setFirstMouse(m_first_mouse, false); QSetValueOnDestroy<QPointF> setPreviousPoint(m_previous_point, mousePos); - if (resetAction && resetAction->isSeparator()) + if (resetAction && resetAction->isSeparator()) { m_reset_action = Q_NULLPTR; - else { + m_use_reset_action = true; + } else if (m_reset_action != resetAction) { + if (m_use_reset_action && resetAction) { + const QList<QAction *> actions = m_menu->actions(); + const int resetIdx = actions.indexOf(resetAction); + const int originIdx = actions.indexOf(m_origin_action); + if (resetIdx > -1 && originIdx > -1 && qAbs(resetIdx - originIdx) > 1) + m_use_reset_action = false; + } m_reset_action = resetAction; } @@ -249,6 +258,7 @@ private: bool m_init_guard; bool m_discard_state_when_entering_parent; bool m_dont_start_time_on_leave; + bool m_use_reset_action; short m_uni_dir_discarded_count; short m_uni_dir_fail_at_count; short m_timeout; @@ -463,6 +473,7 @@ public: void drawScroller(QPainter *painter, ScrollerTearOffItem::Type type, const QRect &rect); void drawTearOff(QPainter *painter, const QRect &rect); + QRect rect() const; }; #endif // QT_NO_MENU diff --git a/src/widgets/widgets/qsplitter.cpp b/src/widgets/widgets/qsplitter.cpp index e92347c65c..1676c188a6 100644 --- a/src/widgets/widgets/qsplitter.cpp +++ b/src/widgets/widgets/qsplitter.cpp @@ -1145,6 +1145,10 @@ void QSplitter::insertWidget(int index, QWidget *widget) \note The splitter takes ownership of \a widget and sets the parent of the replaced widget to null. + \note Because \a widget gets \l{QWidget::setParent()}{reparented} into the splitter, + its \l{QWidget::}{geometry} may not be set right away, but only after \a widget will + receive the appropriate events. + \sa insertWidget(), indexOf() */ QWidget *QSplitter::replaceWidget(int index, QWidget *widget) diff --git a/src/widgets/widgets/qtextedit.cpp b/src/widgets/widgets/qtextedit.cpp index 66bf2919eb..1abc9bef8e 100644 --- a/src/widgets/widgets/qtextedit.cpp +++ b/src/widgets/widgets/qtextedit.cpp @@ -2578,6 +2578,8 @@ void QTextEdit::setText(const QString &text) if (format == Qt::RichText) setHtml(text); else +#else + Q_UNUSED(format); #endif setPlainText(text); } diff --git a/src/widgets/widgets/qwidgettextcontrol.cpp b/src/widgets/widgets/qwidgettextcontrol.cpp index 0d34fae78f..116855c8d3 100644 --- a/src/widgets/widgets/qwidgettextcontrol.cpp +++ b/src/widgets/widgets/qwidgettextcontrol.cpp @@ -3119,6 +3119,7 @@ void QWidgetTextControlPrivate::append(const QString &text, Qt::TextFormat forma tmp.insertText(text); } #else + Q_UNUSED(format); tmp.insertText(text); #endif // QT_NO_TEXTHTMLPARSER if (!cursor.hasSelection()) |