diff options
Diffstat (limited to 'src/widgets')
| -rw-r--r-- | src/widgets/accessible/qaccessiblecolorwell.cpp | 5 | ||||
| -rw-r--r-- | src/widgets/doc/src/external-resources.qdoc | 6 | ||||
| -rw-r--r-- | src/widgets/kernel/qtooltip.cpp | 10 | ||||
| -rw-r--r-- | src/widgets/kernel/qwidget.cpp | 6 | ||||
| -rw-r--r-- | src/widgets/styles/qcommonstyle.cpp | 9 | ||||
| -rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 12 | ||||
| -rw-r--r-- | src/widgets/widgets/qtabbar.cpp | 66 | ||||
| -rw-r--r-- | src/widgets/widgets/qtabbar_p.h | 3 |
8 files changed, 69 insertions, 48 deletions
diff --git a/src/widgets/accessible/qaccessiblecolorwell.cpp b/src/widgets/accessible/qaccessiblecolorwell.cpp index ca08e511e9a..64fcd2a7fd1 100644 --- a/src/widgets/accessible/qaccessiblecolorwell.cpp +++ b/src/widgets/accessible/qaccessiblecolorwell.cpp @@ -3,6 +3,8 @@ #include "private/qaccessiblecolorwell_p.h" +#include <QtCore/qcoreapplication.h> + QT_REQUIRE_CONFIG(accessibility); #if QT_CONFIG(colordialog) @@ -14,6 +16,7 @@ class QAccessibleColorWellItem : public QAccessibleInterface { QAccessibleColorWell *m_parent; + Q_DECLARE_TR_FUNCTIONS(QAccessibleColorWellItem) public: QAccessibleColorWellItem(QAccessibleColorWell *parent); @@ -79,7 +82,7 @@ QString QAccessibleColorWellItem::text(QAccessible::Text t) const if (t == QAccessible::Name) { QRgb color = m_parent->colorWell()->rgbValues()[m_parent->indexOfChild(this)]; //: Color specified via its 3 RGB components (red, green, blue) - return QObject::tr("RGB %1, %2, %3") + return tr("RGB %1, %2, %3") .arg(QString::number(qRed(color)), QString::number(qGreen(color)), QString::number(qBlue(color))); } diff --git a/src/widgets/doc/src/external-resources.qdoc b/src/widgets/doc/src/external-resources.qdoc index 96117546a29..0eccc3b19d4 100644 --- a/src/widgets/doc/src/external-resources.qdoc +++ b/src/widgets/doc/src/external-resources.qdoc @@ -1,12 +1,6 @@ // Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only - -/*! - \externalpage http://developer.apple.com/documentation/UserExperience/Conceptual/OSXHIGuidelines/index.html - \title Apple Human Interface Guidelines -*/ - /*! \externalpage https://rk.nvg.ntnu.no/sinclair/computers/zxspectrum/zxspectrum.htm \title Sinclair Spectrum diff --git a/src/widgets/kernel/qtooltip.cpp b/src/widgets/kernel/qtooltip.cpp index 3417d93d587..97332cd7d5d 100644 --- a/src/widgets/kernel/qtooltip.cpp +++ b/src/widgets/kernel/qtooltip.cpp @@ -6,15 +6,12 @@ #include <qapplication.h> #include <qevent.h> -#include <qpointer.h> #include <qstyle.h> #include <qstyleoption.h> #include <qstylepainter.h> #if QT_CONFIG(effects) #include <private/qeffects_p.h> #endif -#include <qtextdocument.h> -#include <qdebug.h> #include <qpa/qplatformscreen.h> #include <qpa/qplatformcursor.h> #if QT_CONFIG(style_stylesheet) @@ -23,12 +20,9 @@ #include <qpa/qplatformwindow.h> #include <qpa/qplatformwindow_p.h> -#include <qlabel.h> #include <QtWidgets/private/qlabel_p.h> #include <QtGui/private/qhighdpiscaling_p.h> #include <qtooltip.h> - -#include <QtCore/qbasictimer.h> #include <QtWidgets/private/qtooltip_p.h> QT_BEGIN_NAMESPACE @@ -190,10 +184,10 @@ void QTipLabel::resizeEvent(QResizeEvent *e) void QTipLabel::mouseMoveEvent(QMouseEvent *e) { if (!rect.isNull()) { - QPoint pos = e->globalPosition().toPoint(); + QPointF pos = e->globalPosition(); if (widget) pos = widget->mapFromGlobal(pos); - if (!rect.contains(pos)) + if (!rect.contains(pos.toPoint())) hideTip(); } QLabel::mouseMoveEvent(e); diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp index 9499c88af12..bd2b5be11aa 100644 --- a/src/widgets/kernel/qwidget.cpp +++ b/src/widgets/kernel/qwidget.cpp @@ -32,7 +32,7 @@ #include "private/qwidgetwindow_p.h" #include "qpainter.h" #if QT_CONFIG(tooltip) -#include "qtooltip.h" +#include "private/qtooltip_p.h" #endif #if QT_CONFIG(whatsthis) #include "qwhatsthis.h" @@ -1435,7 +1435,9 @@ void QWidgetPrivate::createTLSysExtra() if (extra->topextra->opacity != 255 && q->isWindow()) extra->topextra->window->setOpacity(qreal(extra->topextra->opacity) / qreal(255)); - const bool isTipLabel = q->inherits("QTipLabel"); +#if QT_CONFIG(tooltip) + const bool isTipLabel = qobject_cast<const QTipLabel *>(q) != nullptr; +#endif const bool isAlphaWidget = !isTipLabel && q->inherits("QAlphaWidget"); #ifdef Q_OS_WIN // Pass on native parent handle for Widget embedded into Active X. diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 90c1cfb4b86..592b70ef8ba 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1994,12 +1994,9 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, tr = proxy()->subElementRect(SE_TabBarTabText, opt, widget); if (!tab->icon.isNull()) { - QPixmap tabIcon = tab->icon.pixmap(tab->iconSize, QStyleHelper::getDpr(p), - (tab->state & State_Enabled) ? QIcon::Normal - : QIcon::Disabled, - (tab->state & State_Selected) ? QIcon::On - : QIcon::Off); - p->drawPixmap(iconRect.x(), iconRect.y(), tabIcon); + const auto mode = (tab->state & State_Enabled) ? QIcon::Normal : QIcon::Disabled; + const auto state = (tab->state & State_Selected) ? QIcon::On : QIcon::Off; + tab->icon.paint(p, iconRect, Qt::AlignCenter, mode, state); } proxy()->drawItemText(p, tr, alignment, tab->palette, tab->state & State_Enabled, tab->text, diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 25b048db65e..e0fdd56e6d8 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -35,7 +35,7 @@ #include <qabstractscrollarea.h> #include "private/qabstractscrollarea_p.h" #if QT_CONFIG(tooltip) -#include <qtooltip.h> +#include "private/qtooltip_p.h" #endif #include <qshareddata.h> #if QT_CONFIG(toolbutton) @@ -950,7 +950,7 @@ QRenderRule::QRenderRule(const QList<Declaration> &declarations, const QObject * hasFont = v.extractFont(&font, &adj); #if QT_CONFIG(tooltip) - if (object && qstrcmp(object->metaObject()->className(), "QTipLabel") == 0) + if (qobject_cast<const QTipLabel *>(object) != nullptr) palette = QToolTip::palette(); #endif @@ -1495,7 +1495,7 @@ bool QRenderRule::hasModification() const static inline QObject *parentObject(const QObject *obj) { #if QT_CONFIG(tooltip) - if (qobject_cast<const QLabel *>(obj) && qstrcmp(obj->metaObject()->className(), "QTipLabel") == 0) { + if (qobject_cast<const QTipLabel *>(obj) != nullptr) { QObject *p = qvariant_cast<QObject *>(obj->property("_q_stylesheet_parent")); if (p) return p; @@ -1515,7 +1515,7 @@ public: return QStringList(); const QMetaObject *metaObject = OBJECT_PTR(node)->metaObject(); #if QT_CONFIG(tooltip) - if (qstrcmp(metaObject->className(), "QTipLabel") == 0) + if (metaObject == &QTipLabel::staticMetaObject) return QStringList("QToolTip"_L1); #endif QStringList result; @@ -1581,7 +1581,7 @@ public: return false; const QMetaObject *metaObject = OBJECT_PTR(node)->metaObject(); #if QT_CONFIG(tooltip) - if (qstrcmp(metaObject->className(), "QTipLabel") == 0) + if (metaObject == &QTipLabel::staticMetaObject) return nodeName == "QToolTip"_L1; #endif do { @@ -1747,7 +1747,7 @@ int QStyleSheetStyle::nativeFrameWidth(const QWidget *w) } #endif - if (qstrcmp(w->metaObject()->className(), "QTipLabel") == 0) + if (w->metaObject() == &QTipLabel::staticMetaObject) return base->pixelMetric(QStyle::PM_ToolTipLabelFrameWidth, nullptr, w); return base->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, w); diff --git a/src/widgets/widgets/qtabbar.cpp b/src/widgets/widgets/qtabbar.cpp index 0f0abb6e1d5..44218d41ded 100644 --- a/src/widgets/widgets/qtabbar.cpp +++ b/src/widgets/widgets/qtabbar.cpp @@ -52,6 +52,14 @@ public: void enterEvent(QEnterEvent *event) override; void leaveEvent(QEvent *event) override; void paintEvent(QPaintEvent *event) override; + + void setParentClipRect(const QRect &clipRect) + { + m_parentClipRect = clipRect; + } + +protected: + QRect m_parentClipRect; }; } @@ -598,10 +606,11 @@ QRect QTabBarPrivate::normalizedScrollRect(int index) q->initStyleOption(&opt, currentIndex); opt.rect = q->rect(); - QRect scrollButtonLeftRect = q->style()->subElementRect(QStyle::SE_TabBarScrollLeftButton, &opt, q); - QRect scrollButtonRightRect = q->style()->subElementRect(QStyle::SE_TabBarScrollRightButton, &opt, q); - QRect tearLeftRect = q->style()->subElementRect(QStyle::SE_TabBarTearIndicatorLeft, &opt, q); - QRect tearRightRect = q->style()->subElementRect(QStyle::SE_TabBarTearIndicatorRight, &opt, q); + const auto style = q->style(); + QRect scrollButtonLeftRect = style->subElementRect(QStyle::SE_TabBarScrollLeftButton, &opt, q); + QRect scrollButtonRightRect = style->subElementRect(QStyle::SE_TabBarScrollRightButton, &opt, q); + QRect tearLeftRect = style->subElementRect(QStyle::SE_TabBarTearIndicatorLeft, &opt, q); + QRect tearRightRect = style->subElementRect(QStyle::SE_TabBarTearIndicatorRight, &opt, q); if (verticalTabs(shape)) { int topEdge, bottomEdge; @@ -739,7 +748,7 @@ void QTabBarPrivate::layoutTab(int index) if (tab->leftWidget) { QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabLeftButton, &opt, q); QPoint p = rect.topLeft(); - if ((index == pressedIndex) || paintWithOffsets) { + if (index == pressedIndex) { if (vertical) p.setY(p.y() + tab->dragOffset); else @@ -750,7 +759,7 @@ void QTabBarPrivate::layoutTab(int index) if (tab->rightWidget) { QRect rect = q->style()->subElementRect(QStyle::SE_TabBarTabRightButton, &opt, q); QPoint p = rect.topLeft(); - if ((index == pressedIndex) || paintWithOffsets) { + if (index == pressedIndex) { if (vertical) p.setY(p.y() + tab->dragOffset); else @@ -1004,8 +1013,13 @@ int QTabBar::insertTab(int index, const QIcon& icon, const QString &text) } if (isVisible() && tabAt(d->mousePosition) == index) { - d->hoverIndex = index; - d->hoverRect = tabRect(index); + if (d->normalizedScrollRect(index).contains(d->mousePosition)) { + d->hoverIndex = index; + d->hoverRect = tabRect(index); + } else { + d->hoverIndex = -1; + d->hoverRect = QRect(); + } } tabInserted(index); @@ -1096,11 +1110,13 @@ void QTabBar::removeTab(int index) if (d->hoverRect.isValid()) { update(d->hoverRect); d->hoverIndex = tabAt(d->mousePosition); - if (d->validIndex(d->hoverIndex)) { + if (d->validIndex(d->hoverIndex) + && d->normalizedScrollRect(d->hoverIndex).contains(d->mousePosition)) { d->hoverRect = tabRect(d->hoverIndex); update(d->hoverRect); } else { d->hoverRect = QRect(); + d->hoverIndex = -1; } } tabRemoved(index); @@ -1692,15 +1708,18 @@ bool QTabBar::event(QEvent *event) case QEvent::HoverEnter: { QHoverEvent *he = static_cast<QHoverEvent *>(event); d->mousePosition = he->position().toPoint(); - if (!d->hoverRect.contains(d->mousePosition)) { + const auto sr = d->normalizedScrollRect(); + const auto oldHoverRect = d->hoverRect & sr; + if (!oldHoverRect.contains(d->mousePosition)) { if (d->hoverRect.isValid()) update(d->hoverRect); d->hoverIndex = tabAt(d->mousePosition); - if (d->validIndex(d->hoverIndex)) { + if (d->validIndex(d->hoverIndex) && sr.contains(d->mousePosition)) { d->hoverRect = tabRect(d->hoverIndex); update(d->hoverRect); } else { d->hoverRect = QRect(); + d->hoverIndex = -1; } } return true; @@ -1845,10 +1864,14 @@ void QTabBar::paintEvent(QPaintEvent *) QStyleOption opt; opt.initFrom(this); QRegion buttonRegion; - if (d->leftB->isVisible()) - buttonRegion |= style()->subElementRect(QStyle::SE_TabBarScrollLeftButton, &opt, this); - if (d->rightB->isVisible()) - buttonRegion |= style()->subElementRect(QStyle::SE_TabBarScrollRightButton, &opt, this); + if (d->leftB->isVisible()) { + const auto r = style()->subElementRect(QStyle::SE_TabBarScrollLeftButton, &opt, this); + buttonRegion |= r; + } + if (d->rightB->isVisible()) { + const auto r = style()->subElementRect(QStyle::SE_TabBarScrollRightButton, &opt, this); + buttonRegion |= r; + } if (!buttonRegion.isEmpty()) p.setClipRegion(QRegion(rect()) - buttonRegion); } @@ -1857,9 +1880,13 @@ void QTabBar::paintEvent(QPaintEvent *) const auto tab = d->tabList.at(i); if (!tab->visible) continue; + for (const auto side : { QTabBar::LeftSide, QTabBar::RightSide }) { + if (auto closeButton = qobject_cast<CloseButton *>(tabButton(i, side))) + closeButton->setParentClipRect(scrollRect); + } QStyleOptionTab tabOption; initStyleOption(&tabOption, i); - if (d->paintWithOffsets && tab->dragOffset != 0) { + if (tab->dragOffset != 0) { if (vertical) { tabOption.rect.moveTop(tabOption.rect.y() + tab->dragOffset); } else { @@ -1901,7 +1928,7 @@ void QTabBar::paintEvent(QPaintEvent *) const auto tab = d->tabList.at(selected); initStyleOption(&tabOption, selected); - if (d->paintWithOffsets && tab->dragOffset != 0) { + if (tab->dragOffset != 0) { // if the drag offset is != 0, a move is in progress (drag or animation) // => set the tab position to Moving to preserve the rect tabOption.position = QStyleOptionTab::TabPosition::Moving; @@ -2934,6 +2961,11 @@ void CloseButton::paintEvent(QPaintEvent *) opt.state |= QStyle::State_Selected; } + if (m_parentClipRect.isValid()) { + auto tl = mapFromParent(m_parentClipRect.topLeft()); + auto br = mapFromParent(m_parentClipRect.bottomRight()); + p.setClipRect(QRect(tl, br)); + } style()->drawPrimitive(QStyle::PE_IndicatorTabClose, &opt, &p, this); } diff --git a/src/widgets/widgets/qtabbar_p.h b/src/widgets/widgets/qtabbar_p.h index 38fbde76470..5b31926253f 100644 --- a/src/widgets/widgets/qtabbar_p.h +++ b/src/widgets/widgets/qtabbar_p.h @@ -56,7 +56,7 @@ public: QTabBarPrivate() : layoutDirty(false), drawBase(true), elideModeSetByUser(false), useScrollButtons(false), useScrollButtonsSetByUser(false), expanding(true), closeButtonOnTabs(false), - paintWithOffsets(true), movable(false), dragInProgress(false), documentMode(false), + movable(false), dragInProgress(false), documentMode(false), autoHide(false), changeCurrentOnDrag(false) {} ~QTabBarPrivate() @@ -95,7 +95,6 @@ public: bool useScrollButtonsSetByUser : 1; bool expanding : 1; bool closeButtonOnTabs : 1; - bool paintWithOffsets : 1; bool movable : 1; bool dragInProgress : 1; bool documentMode : 1; |
