diff options
-rw-r--r-- | examples/controls/gallery/gallery.qml | 1 | ||||
-rw-r--r-- | src/imports/controls/material/ComboBox.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/material/MenuItem.qml | 2 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialtheme.cpp | 30 | ||||
-rw-r--r-- | src/imports/controls/material/qquickmaterialtheme_p.h | 5 | ||||
-rw-r--r-- | src/templates/qquickapplicationwindow.cpp | 12 | ||||
-rw-r--r-- | src/templates/qquickcontrol.cpp | 55 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p.h | 1 | ||||
-rw-r--r-- | src/templates/qquickcontrol_p_p.h | 3 | ||||
-rw-r--r-- | src/templates/qquickmenu.cpp | 1 | ||||
-rw-r--r-- | src/templates/qquickmenu_p_p.h | 1 | ||||
-rw-r--r-- | src/templates/qquickpage.cpp | 8 | ||||
-rw-r--r-- | src/templates/qquickpopup.cpp | 277 | ||||
-rw-r--r-- | src/templates/qquickpopup_p_p.h | 24 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_combobox.qml | 91 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_popup.qml | 594 |
16 files changed, 886 insertions, 221 deletions
diff --git a/examples/controls/gallery/gallery.qml b/examples/controls/gallery/gallery.qml index 1e089230..fd019c65 100644 --- a/examples/controls/gallery/gallery.qml +++ b/examples/controls/gallery/gallery.qml @@ -176,7 +176,6 @@ ApplicationWindow { initialItem: Pane { id: pane - anchors.fill: parent Image { id: logo diff --git a/src/imports/controls/material/ComboBox.qml b/src/imports/controls/material/ComboBox.qml index b87034c5..5529c546 100644 --- a/src/imports/controls/material/ComboBox.qml +++ b/src/imports/controls/material/ComboBox.qml @@ -54,7 +54,7 @@ T.ComboBox { padding: 12 //! [delegate] - delegate: ItemDelegate { + delegate: MenuItem { width: control.width text: control.textRole ? (Array.isArray(control.model) ? modelData[control.textRole] : model[control.textRole]) : modelData highlighted: control.highlightedIndex === index diff --git a/src/imports/controls/material/MenuItem.qml b/src/imports/controls/material/MenuItem.qml index c09e9912..e2042894 100644 --- a/src/imports/controls/material/MenuItem.qml +++ b/src/imports/controls/material/MenuItem.qml @@ -146,7 +146,7 @@ T.MenuItem { background: Rectangle { implicitWidth: 200 visible: control.pressed || control.highlighted - color: control.pressed ? control.Material.flatButtonPressColor : control.Material.backgroundColor + color: control.pressed ? control.Material.flatButtonPressColor : control.Material.listHighlightColor } //! [background] } diff --git a/src/imports/controls/material/qquickmaterialtheme.cpp b/src/imports/controls/material/qquickmaterialtheme.cpp index 4124735a..c373c61b 100644 --- a/src/imports/controls/material/qquickmaterialtheme.cpp +++ b/src/imports/controls/material/qquickmaterialtheme.cpp @@ -50,11 +50,23 @@ QQuickMaterialTheme::QQuickMaterialTheme(QPlatformTheme *theme) if (font.exactMatch()) { systemFont.setFamily(font.family()); - tabButtonFont.setFamily(font.family()); + buttonFont.setFamily(font.family()); + toolButtonFont.setFamily(font.family()); + itemViewFont.setFamily(font.family()); + menuItemFont.setFamily(font.family()); } - tabButtonFont.setPixelSize(14); - tabButtonFont.setCapitalization(QFont::AllUppercase); + buttonFont.setPixelSize(14); + buttonFont.setCapitalization(QFont::AllUppercase); + buttonFont.setWeight(QFont::Medium); + + toolButtonFont.setPixelSize(14); + toolButtonFont.setCapitalization(QFont::AllUppercase); + + itemViewFont.setPixelSize(14); + itemViewFont.setWeight(QFont::Medium); + + menuItemFont.setPixelSize(16); } QQuickMaterialTheme::~QQuickMaterialTheme() @@ -65,7 +77,17 @@ const QFont *QQuickMaterialTheme::font(QPlatformTheme::Font type) const { switch (type) { case QPlatformTheme::TabButtonFont: - return &tabButtonFont; + case QPlatformTheme::PushButtonFont: + return &buttonFont; + case QPlatformTheme::ToolButtonFont: + return &toolButtonFont; + case QPlatformTheme::ItemViewFont: + return &itemViewFont; + case QPlatformTheme::MenuItemFont: + case QPlatformTheme::ComboMenuItemFont: + case QPlatformTheme::CheckBoxFont: + case QPlatformTheme::RadioButtonFont: + return &menuItemFont; default: return &systemFont; } diff --git a/src/imports/controls/material/qquickmaterialtheme_p.h b/src/imports/controls/material/qquickmaterialtheme_p.h index e144233c..27ffdddc 100644 --- a/src/imports/controls/material/qquickmaterialtheme_p.h +++ b/src/imports/controls/material/qquickmaterialtheme_p.h @@ -65,7 +65,10 @@ public: private: QFont systemFont; - QFont tabButtonFont; + QFont buttonFont; + QFont toolButtonFont; + QFont itemViewFont; + QFont menuItemFont; }; QT_END_NAMESPACE diff --git a/src/templates/qquickapplicationwindow.cpp b/src/templates/qquickapplicationwindow.cpp index 12d8133d..7756a7bf 100644 --- a/src/templates/qquickapplicationwindow.cpp +++ b/src/templates/qquickapplicationwindow.cpp @@ -81,6 +81,10 @@ QT_BEGIN_NAMESPACE } \endqml + ApplicationWindow supports popups via its \l overlay property, which + ensures that popups are displayed above other content and that the + background is dimmed when a modal popup is visible. + \note By default, an ApplicationWindow is not visible. \labs @@ -249,8 +253,10 @@ void QQuickApplicationWindow::setHeader(QQuickItem *header) if (d->header == header) return; - if (d->header) + if (d->header) { QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->header->setParentItem(nullptr); + } d->header = header; if (header) { header->setParentItem(contentItem()); @@ -291,8 +297,10 @@ void QQuickApplicationWindow::setFooter(QQuickItem *footer) if (d->footer == footer) return; - if (d->footer) + if (d->footer) { QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->footer->setParentItem(nullptr); + } d->footer = footer; if (footer) { footer->setParentItem(contentItem()); diff --git a/src/templates/qquickcontrol.cpp b/src/templates/qquickcontrol.cpp index 5bf42da0..6ec9b4a4 100644 --- a/src/templates/qquickcontrol.cpp +++ b/src/templates/qquickcontrol.cpp @@ -44,6 +44,8 @@ #include "qquicktextarea_p_p.h" #include "qquicktextfield_p.h" #include "qquicktextfield_p_p.h" +#include "qquickpopup_p.h" +#include "qquickpopup_p_p.h" #include "qquickapplicationwindow_p.h" #include <QtGui/private/qguiapplication_p.h> @@ -223,7 +225,12 @@ QFont QQuickControlPrivate::naturalControlFont(const QQuickItem *q) QQuickItem *p = q->parentItem(); bool found = false; while (p) { - if (QQuickControl *qc = qobject_cast<QQuickControl *>(p)) { + if (QQuickPopupItem *qpi = qobject_cast<QQuickPopupItem *>(p)) { + if (const QQuickPopup *qp = qobject_cast<const QQuickPopup *>(qpi->parent())) { + p = qp->parentItem(); + continue; + } + } else if (QQuickControl *qc = qobject_cast<QQuickControl *>(p)) { naturalFont = qc->font(); found = true; break; @@ -297,6 +304,13 @@ void QQuickControlPrivate::updateFontRecur(QQuickItem *item, const QFont &f) else QQuickControlPrivate::updateFontRecur(child, f); } + + foreach (QObject *child, item->children()) { + if (QQuickPopup *qp = qobject_cast<QQuickPopup *>(child)) { + if (QQuickPopupItem *qpi = qobject_cast<QQuickPopupItem *>(qp->popupItem())) + QQuickControlPrivate::updateFontRecur(qpi, f); + } + } } QString QQuickControl::accessibleName() const @@ -353,13 +367,6 @@ QQuickControl::QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent) : { } -void QQuickControl::classBegin() -{ - Q_D(QQuickControl); - QQuickItem::classBegin(); - d->resolveFont(); -} - void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem::ItemChangeData &value) { Q_D(QQuickControl); @@ -367,7 +374,7 @@ void QQuickControl::itemChange(QQuickItem::ItemChange change, const QQuickItem:: if (change == ItemParentHasChanged && isComponentComplete()) { d->resolveFont(); if (!d->hasLocale) - d->locale = d->calcLocale(); + d->locale = QQuickControlPrivate::calcLocale(d->parentItem); } } @@ -646,14 +653,20 @@ void QQuickControl::resetLocale() if (!d->hasLocale) return; - d->updateLocale(d->calcLocale(), false); // explicit=false + d->updateLocale(QQuickControlPrivate::calcLocale(d->parentItem), false); // explicit=false } -QLocale QQuickControlPrivate::calcLocale() const +QLocale QQuickControlPrivate::calcLocale(QQuickItem *q) { - Q_Q(const QQuickControl); - QQuickItem *p = q->parentItem(); + QQuickItem *p = q; while (p) { + if (QQuickPopupItem *qpi = qobject_cast<QQuickPopupItem *>(p)) { + if (const QQuickPopup *qp = qobject_cast<const QQuickPopup *>(qpi->parent())) { + p = qp->parentItem(); + continue; + } + } + if (QQuickControl *qc = qobject_cast<QQuickControl *>(p)) return qc->locale(); @@ -664,8 +677,10 @@ QLocale QQuickControlPrivate::calcLocale() const p = p->parentItem(); } - if (QQuickApplicationWindow *w = qobject_cast<QQuickApplicationWindow *>(q->window())) - return w->locale(); + if (q) { + if (QQuickApplicationWindow *w = qobject_cast<QQuickApplicationWindow *>(q->window())) + return w->locale(); + } return QLocale(); } @@ -698,6 +713,13 @@ void QQuickControlPrivate::updateLocaleRecur(QQuickItem *item, const QLocale &l) else updateLocaleRecur(child, l); } + + foreach (QObject *child, item->children()) { + if (QQuickPopup *qp = qobject_cast<QQuickPopup *>(child)) { + if (QQuickPopupItem *qpi = qobject_cast<QQuickPopupItem *>(qp->popupItem())) + updateLocaleRecur(qpi, l); + } + } } /*! @@ -821,6 +843,9 @@ void QQuickControl::componentComplete() { Q_D(QQuickControl); QQuickItem::componentComplete(); + d->resolveFont(); + if (!d->hasLocale) + d->locale = QQuickControlPrivate::calcLocale(d->parentItem); #ifndef QT_NO_ACCESSIBILITY if (!d->accessibleAttached && QAccessible::isActive()) accessibilityActiveChanged(true); diff --git a/src/templates/qquickcontrol_p.h b/src/templates/qquickcontrol_p.h index 648a140b..c658ff74 100644 --- a/src/templates/qquickcontrol_p.h +++ b/src/templates/qquickcontrol_p.h @@ -144,7 +144,6 @@ protected: QQuickControl(QQuickControlPrivate &dd, QQuickItem *parent); - void classBegin() override; void componentComplete() override; void itemChange(ItemChange change, const ItemChangeData &value) override; diff --git a/src/templates/qquickcontrol_p_p.h b/src/templates/qquickcontrol_p_p.h index 1450184b..e32af257 100644 --- a/src/templates/qquickcontrol_p_p.h +++ b/src/templates/qquickcontrol_p_p.h @@ -104,8 +104,7 @@ public: static QFont themeFont(QPlatformTheme::Font type); void updateLocale(const QLocale &l, bool e); static void updateLocaleRecur(QQuickItem *item, const QLocale &l); - - QLocale calcLocale() const; + static QLocale calcLocale(QQuickItem *); QFont font; bool hasTopPadding; diff --git a/src/templates/qquickmenu.cpp b/src/templates/qquickmenu.cpp index acfcdb70..2a45b6df 100644 --- a/src/templates/qquickmenu.cpp +++ b/src/templates/qquickmenu.cpp @@ -484,6 +484,7 @@ void QQuickMenu::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) QObjectPrivate::connect(d->dummyFocusItem.data(), &QQuickItem::activeFocusChanged, d, &QQuickMenuPrivate::maybeUnsetDummyFocusOnTab); } + d->contentItem = newItem; } bool QQuickMenu::eventFilter(QObject *object, QEvent *event) diff --git a/src/templates/qquickmenu_p_p.h b/src/templates/qquickmenu_p_p.h index 505f3cb9..366dbc35 100644 --- a/src/templates/qquickmenu_p_p.h +++ b/src/templates/qquickmenu_p_p.h @@ -89,6 +89,7 @@ public: static QObject *contentData_at(QQmlListProperty<QObject> *prop, int index); static void contentData_clear(QQmlListProperty<QObject> *prop); + QQuickItem *contentItem; // TODO: cleanup QVector<QObject *> contentData; QQmlObjectModel *contentModel; QPointer<QQuickItem> dummyFocusItem; diff --git a/src/templates/qquickpage.cpp b/src/templates/qquickpage.cpp index bf1fc42d..a4225028 100644 --- a/src/templates/qquickpage.cpp +++ b/src/templates/qquickpage.cpp @@ -167,8 +167,10 @@ void QQuickPage::setHeader(QQuickItem *header) if (d->header == header) return; - if (d->header) + if (d->header) { QQuickItemPrivate::get(d->header)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->header->setParentItem(nullptr); + } d->header = header; if (header) { header->setParentItem(this); @@ -209,8 +211,10 @@ void QQuickPage::setFooter(QQuickItem *footer) if (d->footer == footer) return; - if (d->footer) + if (d->footer) { QQuickItemPrivate::get(d->footer)->removeItemChangeListener(d, QQuickItemPrivate::ImplicitWidth | QQuickItemPrivate::ImplicitHeight); + d->footer->setParentItem(nullptr); + } d->footer = footer; if (footer) { footer->setParentItem(this); diff --git a/src/templates/qquickpopup.cpp b/src/templates/qquickpopup.cpp index 8214df8a..4b953fc6 100644 --- a/src/templates/qquickpopup.cpp +++ b/src/templates/qquickpopup.cpp @@ -38,6 +38,7 @@ #include "qquickpopup_p_p.h" #include "qquickapplicationwindow_p.h" #include "qquickoverlay_p.h" +#include "qquickcontrol_p_p.h" #include <QtQml/qqmlinfo.h> #include <QtQuick/qquickitem.h> @@ -54,7 +55,40 @@ QT_BEGIN_NAMESPACE \ingroup qtlabscontrols-popups \brief The base type of popup-like user interface controls. - Popup is the base type of popup-like user interface controls. + Popup is the base type of popup-like user interface controls. It can be + used with Window or ApplicationWindow. + + \qml + import QtQuick.Window 2.2 + import Qt.labs.controls 1.0 + + Window { + id: window + width: 400 + height: 400 + visible: true + + Button { + text: "Open" + onClicked: popup.open() + } + + Popup { + id: popup + x: 100 + y: 100 + width: 200 + height: 300 + modal: true + focus: true + closePolicy: Popup.OnEscape | Popup.OnPressOutside + } + } + \endqml + + In order to ensure that a popup is displayed above other items in the + scene, it is recommended to use ApplicationWindow. ApplicationWindow also + provides background dimming effects. \labs */ @@ -75,26 +109,15 @@ QQuickPopupPrivate::QQuickPopupPrivate() , hasLeftMargin(false) , hasRightMargin(false) , hasBottomMargin(false) - , hasTopPadding(false) - , hasLeftPadding(false) - , hasRightPadding(false) - , hasBottomPadding(false) , margins(0) , topMargin(0) , leftMargin(0) , rightMargin(0) , bottomMargin(0) - , padding(0) - , topPadding(0) - , leftPadding(0) - , rightPadding(0) - , bottomPadding(0) , contentWidth(0) , contentHeight(0) , closePolicy(QQuickPopup::OnEscape) , parentItem(nullptr) - , background(nullptr) - , contentItem(nullptr) , enter(nullptr) , exit(nullptr) , popupItem(nullptr) @@ -108,6 +131,7 @@ void QQuickPopupPrivate::init() Q_Q(QQuickPopup); popupItem = new QQuickPopupItem(q); q->setParentItem(qobject_cast<QQuickItem *>(parent)); + QObject::connect(popupItem, &QQuickControl::paddingChanged, q, &QQuickPopup::paddingChanged); } bool QQuickPopupPrivate::tryClose(QQuickItem *item, QMouseEvent *event) @@ -146,31 +170,6 @@ void QQuickPopupPrivate::finalizeExitTransition() popupItem->setVisible(false); } -void QQuickPopupPrivate::resizeBackground() -{ - Q_Q(QQuickPopup); - if (background) { - QQuickItemPrivate *p = QQuickItemPrivate::get(background); - if (!p->widthValid && qFuzzyIsNull(background->x())) { - background->setWidth(q->width()); - p->widthValid = false; - } - if (!p->heightValid && qFuzzyIsNull(background->y())) { - background->setHeight(q->height()); - p->heightValid = false; - } - } -} - -void QQuickPopupPrivate::resizeContent() -{ - Q_Q(QQuickPopup); - if (contentItem) { - contentItem->setPosition(QPointF(q->leftPadding(), q->topPadding())); - contentItem->setSize(QSizeF(q->availableWidth(), q->availableHeight())); - } -} - QMarginsF QQuickPopupPrivate::getMargins() const { Q_Q(const QQuickPopup); @@ -229,63 +228,7 @@ void QQuickPopupPrivate::setBottomMargin(qreal value, bool reset) } } -void QQuickPopupPrivate::setTopPadding(qreal value, bool reset) -{ - Q_Q(QQuickPopup); - qreal oldPadding = q->topPadding(); - topPadding = value; - hasTopPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { - emit q->topPaddingChanged(); - emit q->availableHeightChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, oldPadding, rightPadding, bottomPadding)); - } -} - -void QQuickPopupPrivate::setLeftPadding(qreal value, bool reset) -{ - Q_Q(QQuickPopup); - qreal oldPadding = q->leftPadding(); - leftPadding = value; - hasLeftPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { - emit q->leftPaddingChanged(); - emit q->availableWidthChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(oldPadding, topPadding, rightPadding, bottomPadding)); - } -} - -void QQuickPopupPrivate::setRightPadding(qreal value, bool reset) -{ - Q_Q(QQuickPopup); - qreal oldPadding = q->rightPadding(); - rightPadding = value; - hasRightPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { - emit q->rightPaddingChanged(); - emit q->availableWidthChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, topPadding, oldPadding, bottomPadding)); - } -} - -void QQuickPopupPrivate::setBottomPadding(qreal value, bool reset) -{ - Q_Q(QQuickPopup); - qreal oldPadding = q->bottomPadding(); - bottomPadding = value; - hasBottomPadding = !reset; - if ((!reset && !qFuzzyCompare(oldPadding, value)) || (reset && !qFuzzyCompare(oldPadding, padding))) { - emit q->bottomPaddingChanged(); - emit q->availableHeightChanged(); - q->paddingChange(QMarginsF(leftPadding, topPadding, rightPadding, bottomPadding), - QMarginsF(leftPadding, topPadding, rightPadding, oldPadding)); - } -} - -class QQuickPopupItemPrivate : public QQuickItemPrivate +class QQuickPopupItemPrivate : public QQuickControlPrivate { Q_DECLARE_PUBLIC(QQuickPopupItem) @@ -305,16 +248,18 @@ QQuickPopupItemPrivate::QQuickPopupItemPrivate(QQuickPopup *popup) : popup(popup void QQuickPopupItemPrivate::implicitWidthChanged() { + QQuickControlPrivate::implicitWidthChanged(); emit popup->implicitHeightChanged(); } void QQuickPopupItemPrivate::implicitHeightChanged() { + QQuickControlPrivate::implicitHeightChanged(); emit popup->implicitHeightChanged(); } QQuickPopupItem::QQuickPopupItem(QQuickPopup *popup) : - QQuickItem(*(new QQuickPopupItemPrivate(popup))) + QQuickControl(*(new QQuickPopupItemPrivate(popup)), nullptr) { setParent(popup); setVisible(false); @@ -382,16 +327,24 @@ void QQuickPopupItem::wheelEvent(QWheelEvent *event) d->popup->wheelEvent(event); } +void QQuickPopupItem::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) +{ + Q_D(QQuickPopupItem); + QQuickControl::contentItemChange(newItem, oldItem); + d->popup->contentItemChange(newItem, oldItem); +} + void QQuickPopupItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickPopupItem); + QQuickControl::geometryChanged(newGeometry, oldGeometry); d->popup->geometryChanged(newGeometry, oldGeometry); } void QQuickPopupItem::itemChange(ItemChange change, const ItemChangeData &data) { Q_D(QQuickPopupItem); - QQuickItem::itemChange(change, data); + QQuickControl::itemChange(change, data); switch (change) { case ItemVisibleHasChanged: emit d->popup->visibleChanged(); @@ -407,6 +360,13 @@ void QQuickPopupItem::itemChange(ItemChange change, const ItemChangeData &data) } } +void QQuickPopupItem::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) +{ + Q_D(QQuickPopupItem); + QQuickControl::paddingChange(newPadding, oldPadding); + d->popup->paddingChange(newPadding, oldPadding); +} + QQuickPopupPositioner::QQuickPopupPositioner(QQuickPopupPrivate *popup) : m_x(0), m_y(0), @@ -895,7 +855,8 @@ void QQuickPopup::setContentHeight(qreal height) */ qreal QQuickPopup::availableWidth() const { - return qMax<qreal>(0.0, width() - leftPadding() - rightPadding()); + Q_D(const QQuickPopup); + return d->popupItem->availableWidth(); } /*! @@ -908,7 +869,8 @@ qreal QQuickPopup::availableWidth() const */ qreal QQuickPopup::availableHeight() const { - return qMax<qreal>(0.0, height() - topPadding() - bottomPadding()); + Q_D(const QQuickPopup); + return d->popupItem->availableHeight(); } /*! @@ -1067,36 +1029,19 @@ void QQuickPopup::resetBottomMargin() qreal QQuickPopup::padding() const { Q_D(const QQuickPopup); - return d->padding; + return d->popupItem->padding(); } void QQuickPopup::setPadding(qreal padding) { Q_D(QQuickPopup); - if (qFuzzyCompare(d->padding, padding)) - return; - QMarginsF oldPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); - d->padding = padding; - emit paddingChanged(); - QMarginsF newPadding(leftPadding(), topPadding(), rightPadding(), bottomPadding()); - if (!qFuzzyCompare(newPadding.top(), oldPadding.top())) - emit topPaddingChanged(); - if (!qFuzzyCompare(newPadding.left(), oldPadding.left())) - emit leftPaddingChanged(); - if (!qFuzzyCompare(newPadding.right(), oldPadding.right())) - emit rightPaddingChanged(); - if (!qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) - emit bottomPaddingChanged(); - if (!qFuzzyCompare(newPadding.top(), oldPadding.top()) || !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom())) - emit availableHeightChanged(); - if (!qFuzzyCompare(newPadding.left(), oldPadding.left()) || !qFuzzyCompare(newPadding.right(), oldPadding.right())) - emit availableWidthChanged(); - paddingChange(newPadding, oldPadding); + d->popupItem->setPadding(padding); } void QQuickPopup::resetPadding() { - setPadding(0); + Q_D(QQuickPopup); + d->popupItem->resetPadding(); } /*! @@ -1109,21 +1054,19 @@ void QQuickPopup::resetPadding() qreal QQuickPopup::topPadding() const { Q_D(const QQuickPopup); - if (d->hasTopPadding) - return d->topPadding; - return d->padding; + return d->popupItem->topPadding(); } void QQuickPopup::setTopPadding(qreal padding) { Q_D(QQuickPopup); - d->setTopPadding(padding); + d->popupItem->setTopPadding(padding); } void QQuickPopup::resetTopPadding() { Q_D(QQuickPopup); - d->setTopPadding(0, true); + d->popupItem->resetTopPadding(); } /*! @@ -1136,21 +1079,19 @@ void QQuickPopup::resetTopPadding() qreal QQuickPopup::leftPadding() const { Q_D(const QQuickPopup); - if (d->hasLeftPadding) - return d->leftPadding; - return d->padding; + return d->popupItem->leftPadding(); } void QQuickPopup::setLeftPadding(qreal padding) { Q_D(QQuickPopup); - d->setLeftPadding(padding); + d->popupItem->setLeftPadding(padding); } void QQuickPopup::resetLeftPadding() { Q_D(QQuickPopup); - d->setLeftPadding(0, true); + d->popupItem->resetLeftPadding(); } /*! @@ -1163,21 +1104,19 @@ void QQuickPopup::resetLeftPadding() qreal QQuickPopup::rightPadding() const { Q_D(const QQuickPopup); - if (d->hasRightPadding) - return d->rightPadding; - return d->padding; + return d->popupItem->rightPadding(); } void QQuickPopup::setRightPadding(qreal padding) { Q_D(QQuickPopup); - d->setRightPadding(padding); + d->popupItem->setRightPadding(padding); } void QQuickPopup::resetRightPadding() { Q_D(QQuickPopup); - d->setRightPadding(0, true); + d->popupItem->resetRightPadding(); } /*! @@ -1190,21 +1129,19 @@ void QQuickPopup::resetRightPadding() qreal QQuickPopup::bottomPadding() const { Q_D(const QQuickPopup); - if (d->hasBottomPadding) - return d->bottomPadding; - return d->padding; + return d->popupItem->bottomPadding(); } void QQuickPopup::setBottomPadding(qreal padding) { Q_D(QQuickPopup); - d->setBottomPadding(padding); + d->popupItem->setBottomPadding(padding); } void QQuickPopup::resetBottomPadding() { Q_D(QQuickPopup); - d->setBottomPadding(0, true); + d->popupItem->resetBottomPadding(); } QQuickItem *QQuickPopup::popupItem() const @@ -1233,6 +1170,10 @@ void QQuickPopup::setParentItem(QQuickItem *parent) d->parentItem = parent; if (d->positioner.parentItem()) d->positioner.setParentItem(parent); + if (d->popupItem) { + QQuickControlPrivate::updateFontRecur(d->popupItem, QQuickControlPrivate::naturalControlFont(parent)); + QQuickControlPrivate::updateLocaleRecur(d->popupItem, QQuickControlPrivate::calcLocale(parent)); + } emit parentChanged(); } @@ -1248,24 +1189,16 @@ void QQuickPopup::setParentItem(QQuickItem *parent) QQuickItem *QQuickPopup::background() const { Q_D(const QQuickPopup); - return d->background; + return d->popupItem->background(); } void QQuickPopup::setBackground(QQuickItem *background) { Q_D(QQuickPopup); - if (d->background == background) + if (d->popupItem->background() == background) return; - delete d->background; - d->background = background; - if (background) { - background->setParentItem(d->popupItem); - if (qFuzzyIsNull(background->z())) - background->setZ(-1); - if (isComponentComplete()) - d->resizeBackground(); - } + d->popupItem->setBackground(background); emit backgroundChanged(); } @@ -1282,24 +1215,13 @@ void QQuickPopup::setBackground(QQuickItem *background) QQuickItem *QQuickPopup::contentItem() const { Q_D(const QQuickPopup); - return d->contentItem; + return d->popupItem->contentItem(); } void QQuickPopup::setContentItem(QQuickItem *item) { Q_D(QQuickPopup); - if (d->contentItem == item) - return; - - contentItemChange(item, d->contentItem); - delete d->contentItem; - d->contentItem = item; - if (item) { - item->setParentItem(d->popupItem); - if (isComponentComplete()) - d->resizeContent(); - } - emit contentItemChanged(); + d->popupItem->setContentItem(item); } /*! @@ -1313,7 +1235,7 @@ void QQuickPopup::setContentItem(QQuickItem *item) QQmlListProperty<QObject> QQuickPopup::contentData() { Q_D(QQuickPopup); - return QQmlListProperty<QObject>(d->contentItem, nullptr, + return QQmlListProperty<QObject>(d->popupItem->contentItem(), nullptr, QQuickItemPrivate::data_append, QQuickItemPrivate::data_count, QQuickItemPrivate::data_at, @@ -1330,7 +1252,7 @@ QQmlListProperty<QObject> QQuickPopup::contentData() QQmlListProperty<QQuickItem> QQuickPopup::contentChildren() { Q_D(QQuickPopup); - return QQmlListProperty<QQuickItem>(d->contentItem, nullptr, + return QQmlListProperty<QQuickItem>(d->popupItem->contentItem(), nullptr, QQuickItemPrivate::children_append, QQuickItemPrivate::children_count, QQuickItemPrivate::children_at, @@ -1667,13 +1589,12 @@ void QQuickPopup::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_UNUSED(newItem); Q_UNUSED(oldItem); + emit contentItemChanged(); } void QQuickPopup::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickPopup); - d->resizeBackground(); - d->resizeContent(); d->positioner.repositionPopup(); if (!qFuzzyCompare(newGeometry.width(), oldGeometry.width())) { emit widthChanged(); @@ -1695,10 +1616,24 @@ void QQuickPopup::marginsChange(const QMarginsF &newMargins, const QMarginsF &ol void QQuickPopup::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { - Q_D(QQuickPopup); - Q_UNUSED(newPadding); - Q_UNUSED(oldPadding); - d->resizeContent(); + const bool tp = !qFuzzyCompare(newPadding.top(), oldPadding.top()); + const bool lp = !qFuzzyCompare(newPadding.left(), oldPadding.left()); + const bool rp = !qFuzzyCompare(newPadding.right(), oldPadding.right()); + const bool bp = !qFuzzyCompare(newPadding.bottom(), oldPadding.bottom()); + + if (tp) + emit topPaddingChanged(); + if (lp) + emit leftPaddingChanged(); + if (rp) + emit rightPaddingChanged(); + if (bp) + emit bottomPaddingChanged(); + + if (lp || rp) + emit availableWidthChanged(); + if (tp || bp) + emit availableHeightChanged(); } QT_END_NAMESPACE diff --git a/src/templates/qquickpopup_p_p.h b/src/templates/qquickpopup_p_p.h index c576071b..ba1e90a8 100644 --- a/src/templates/qquickpopup_p_p.h +++ b/src/templates/qquickpopup_p_p.h @@ -49,6 +49,7 @@ // #include "qquickpopup_p.h" +#include "qquickcontrol_p.h" #include <QtCore/private/qobject_p.h> #include <QtQuick/qquickitem.h> @@ -83,7 +84,7 @@ private: QQuickPopupPrivate *popup; }; -class QQuickPopupItem : public QQuickItem +class QQuickPopupItem : public QQuickControl { Q_OBJECT @@ -102,8 +103,10 @@ protected: void mouseUngrabEvent() override; void wheelEvent(QWheelEvent *event) override; + void contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) override; void geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) override; void itemChange(ItemChange change, const ItemChangeData &data) override; + void paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) override; private: Q_DECLARE_PRIVATE(QQuickPopupItem) @@ -162,9 +165,6 @@ public: void finalizeEnterTransition(); void finalizeExitTransition(); - void resizeBackground(); - void resizeContent(); - QMarginsF getMargins() const; void setTopMargin(qreal value, bool reset = false); @@ -172,11 +172,6 @@ public: void setRightMargin(qreal value, bool reset = false); void setBottomMargin(qreal value, bool reset = false); - void setTopPadding(qreal value, bool reset = false); - void setLeftPadding(qreal value, bool reset = false); - void setRightPadding(qreal value, bool reset = false); - void setBottomPadding(qreal value, bool reset = false); - bool focus; bool modal; bool complete; @@ -184,26 +179,15 @@ public: bool hasLeftMargin; bool hasRightMargin; bool hasBottomMargin; - bool hasTopPadding; - bool hasLeftPadding; - bool hasRightPadding; - bool hasBottomPadding; qreal margins; qreal topMargin; qreal leftMargin; qreal rightMargin; qreal bottomMargin; - qreal padding; - qreal topPadding; - qreal leftPadding; - qreal rightPadding; - qreal bottomPadding; qreal contentWidth; qreal contentHeight; QQuickPopup::ClosePolicy closePolicy; QQuickItem *parentItem; - QQuickItem *background; - QQuickItem *contentItem; QQuickTransition *enter; QQuickTransition *exit; QQuickPopupItem *popupItem; diff --git a/tests/auto/controls/data/tst_combobox.qml b/tests/auto/controls/data/tst_combobox.qml index 55ac3e8d..b112f20c 100644 --- a/tests/auto/controls/data/tst_combobox.qml +++ b/tests/auto/controls/data/tst_combobox.qml @@ -626,4 +626,95 @@ TestCase { control.destroy() } + + Component { + id: component + Pane { + id: panel + property alias button: _button; + property alias combobox: _combobox; + font.pixelSize: 30 + Column { + Button { + id: _button + text: "Button" + font.pixelSize: 20 + } + ComboBox { + id: _combobox + model: ["ComboBox", "With"] + delegate: ItemDelegate { + width: _combobox.width + text: _combobox.textRole ? (Array.isArray(_combobox.model) ? modelData[_combobox.textRole] : model[_combobox.textRole]) : modelData + objectName: "delegate" + checkable: true + autoExclusive: true + checked: _combobox.currentIndex === index + highlighted: _combobox.highlightedIndex === index + pressed: highlighted && _combobox.pressed + } + } + } + } + } + + function getChild(control, objname, idx) { + var index = idx + for (var i = index+1; i < control.children.length; i++) + { + if (control.children[i].objectName === objname) { + index = i + break + } + } + return index + } + + function test_font() { // QTBUG_50984 + var control = component.createObject(window.contentItem) + verify(control) + verify(control.button) + verify(control.combobox) + + waitForRendering(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + compare(control.font.pixelSize, 30) + compare(control.button.font.pixelSize, 20) + compare(control.combobox.font.pixelSize, 30) + + verify(control.combobox.popup) + var popup = control.combobox.popup + popup.open() + + verify(popup.contentItem) + + var listview = popup.contentItem + verify(listview.contentItem) + waitForRendering(listview) + + var idx1 = getChild(listview.contentItem, "delegate", -1) + compare(listview.contentItem.children[idx1].font.pixelSize, 30) + var idx2 = getChild(listview.contentItem, "delegate", idx1) + compare(listview.contentItem.children[idx2].font.pixelSize, 30) + + control.font.pixelSize = control.font.pixelSize + 10 + compare(control.combobox.font.pixelSize, 40) + waitForRendering(listview) + compare(listview.contentItem.children[idx1].font.pixelSize, 40) + compare(listview.contentItem.children[idx2].font.pixelSize, 40) + + control.combobox.font.pixelSize = control.combobox.font.pixelSize + 5 + compare(control.combobox.font.pixelSize, 45) + waitForRendering(listview) + + idx1 = getChild(listview.contentItem, "delegate", -1) + compare(listview.contentItem.children[idx1].font.pixelSize, 45) + idx2 = getChild(listview.contentItem, "delegate", idx1) + compare(listview.contentItem.children[idx2].font.pixelSize, 45) + + control.destroy() + } } diff --git a/tests/auto/controls/data/tst_popup.qml b/tests/auto/controls/data/tst_popup.qml new file mode 100644 index 00000000..20859dac --- /dev/null +++ b/tests/auto/controls/data/tst_popup.qml @@ -0,0 +1,594 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.4 +import QtTest 1.0 +import Qt.labs.controls 1.0 +import Qt.labs.templates 1.0 as T + +TestCase { + id: testCase + width: 480 + height: 360 + visible: true + when: windowShown + name: "Popup" + + Component { + id: popup + T.Popup { } + } + + Component { + id: rect + Rectangle { } + } + + SignalSpy { + id: availableWidthSpy + signalName: "availableWidthChanged" + } + + SignalSpy { + id: availableHeightSpy + signalName: "availableHeightChanged" + } + + SignalSpy { + id: paddingSpy + signalName: "paddingChanged" + } + + SignalSpy { + id: topPaddingSpy + signalName: "topPaddingChanged" + } + + SignalSpy { + id: leftPaddingSpy + signalName: "leftPaddingChanged" + } + + SignalSpy { + id: rightPaddingSpy + signalName: "rightPaddingChanged" + } + + SignalSpy { + id: bottomPaddingSpy + signalName: "bottomPaddingChanged" + } + + function test_padding() { + var control = popup.createObject(testCase) + verify(control) + + paddingSpy.target = control + topPaddingSpy.target = control + leftPaddingSpy.target = control + rightPaddingSpy.target = control + bottomPaddingSpy.target = control + + verify(paddingSpy.valid) + verify(topPaddingSpy.valid) + verify(leftPaddingSpy.valid) + verify(rightPaddingSpy.valid) + verify(bottomPaddingSpy.valid) + + var paddingChanges = 0 + var topPaddingChanges = 0 + var leftPaddingChanges = 0 + var rightPaddingChanges = 0 + var bottomPaddingChanges = 0 + + compare(control.padding, 0) + compare(control.topPadding, 0) + compare(control.leftPadding, 0) + compare(control.rightPadding, 0) + compare(control.bottomPadding, 0) + compare(control.availableWidth, 0) + compare(control.availableHeight, 0) + + control.width = 100 + control.height = 100 + + control.padding = 10 + compare(control.padding, 10) + compare(control.topPadding, 10) + compare(control.leftPadding, 10) + compare(control.rightPadding, 10) + compare(control.bottomPadding, 10) + compare(paddingSpy.count, ++paddingChanges) + compare(topPaddingSpy.count, ++topPaddingChanges) + compare(leftPaddingSpy.count, ++leftPaddingChanges) + compare(rightPaddingSpy.count, ++rightPaddingChanges) + compare(bottomPaddingSpy.count, ++bottomPaddingChanges) + + control.topPadding = 20 + compare(control.padding, 10) + compare(control.topPadding, 20) + compare(control.leftPadding, 10) + compare(control.rightPadding, 10) + compare(control.bottomPadding, 10) + compare(paddingSpy.count, paddingChanges) + compare(topPaddingSpy.count, ++topPaddingChanges) + compare(leftPaddingSpy.count, leftPaddingChanges) + compare(rightPaddingSpy.count, rightPaddingChanges) + compare(bottomPaddingSpy.count, bottomPaddingChanges) + + control.leftPadding = 30 + compare(control.padding, 10) + compare(control.topPadding, 20) + compare(control.leftPadding, 30) + compare(control.rightPadding, 10) + compare(control.bottomPadding, 10) + compare(paddingSpy.count, paddingChanges) + compare(topPaddingSpy.count, topPaddingChanges) + compare(leftPaddingSpy.count, ++leftPaddingChanges) + compare(rightPaddingSpy.count, rightPaddingChanges) + compare(bottomPaddingSpy.count, bottomPaddingChanges) + + control.rightPadding = 40 + compare(control.padding, 10) + compare(control.topPadding, 20) + compare(control.leftPadding, 30) + compare(control.rightPadding, 40) + compare(control.bottomPadding, 10) + compare(paddingSpy.count, paddingChanges) + compare(topPaddingSpy.count, topPaddingChanges) + compare(leftPaddingSpy.count, leftPaddingChanges) + compare(rightPaddingSpy.count, ++rightPaddingChanges) + compare(bottomPaddingSpy.count, bottomPaddingChanges) + + control.bottomPadding = 50 + compare(control.padding, 10) + compare(control.topPadding, 20) + compare(control.leftPadding, 30) + compare(control.rightPadding, 40) + compare(control.bottomPadding, 50) + compare(paddingSpy.count, paddingChanges) + compare(topPaddingSpy.count, topPaddingChanges) + compare(leftPaddingSpy.count, leftPaddingChanges) + compare(rightPaddingSpy.count, rightPaddingChanges) + compare(bottomPaddingSpy.count, ++bottomPaddingChanges) + + control.padding = 60 + compare(control.padding, 60) + compare(control.topPadding, 20) + compare(control.leftPadding, 30) + compare(control.rightPadding, 40) + compare(control.bottomPadding, 50) + compare(paddingSpy.count, ++paddingChanges) + compare(topPaddingSpy.count, topPaddingChanges) + compare(leftPaddingSpy.count, leftPaddingChanges) + compare(rightPaddingSpy.count, rightPaddingChanges) + compare(bottomPaddingSpy.count, bottomPaddingChanges) + + control.destroy() + } + + function test_availableSize() { + var control = popup.createObject(testCase) + verify(control) + + availableWidthSpy.target = control + availableHeightSpy.target = control + + verify(availableWidthSpy.valid) + verify(availableHeightSpy.valid) + + var availableWidthChanges = 0 + var availableHeightChanges = 0 + + control.width = 100 + compare(control.availableWidth, 100) + compare(availableWidthSpy.count, ++availableWidthChanges) + compare(availableHeightSpy.count, availableHeightChanges) + + control.height = 100 + compare(control.availableHeight, 100) + compare(availableWidthSpy.count, availableWidthChanges) + compare(availableHeightSpy.count, ++availableHeightChanges) + + control.padding = 10 + compare(control.availableWidth, 80) + compare(control.availableHeight, 80) + compare(availableWidthSpy.count, ++availableWidthChanges) + compare(availableHeightSpy.count, ++availableHeightChanges) + + control.topPadding = 20 + compare(control.availableWidth, 80) + compare(control.availableHeight, 70) + compare(availableWidthSpy.count, availableWidthChanges) + compare(availableHeightSpy.count, ++availableHeightChanges) + + control.leftPadding = 30 + compare(control.availableWidth, 60) + compare(control.availableHeight, 70) + compare(availableWidthSpy.count, ++availableWidthChanges) + compare(availableHeightSpy.count, availableHeightChanges) + + control.rightPadding = 40 + compare(control.availableWidth, 30) + compare(control.availableHeight, 70) + compare(availableWidthSpy.count, ++availableWidthChanges) + compare(availableHeightSpy.count, availableHeightChanges) + + control.bottomPadding = 50 + compare(control.availableWidth, 30) + compare(control.availableHeight, 30) + compare(availableWidthSpy.count, availableWidthChanges) + compare(availableHeightSpy.count, ++availableHeightChanges) + + control.padding = 60 + compare(control.availableWidth, 30) + compare(control.availableHeight, 30) + compare(availableWidthSpy.count, availableWidthChanges) + compare(availableHeightSpy.count, availableHeightChanges) + + control.width = 0 + compare(control.availableWidth, 0) + compare(availableWidthSpy.count, ++availableWidthChanges) + compare(availableHeightSpy.count, availableHeightChanges) + + control.height = 0 + compare(control.availableHeight, 0) + compare(availableWidthSpy.count, availableWidthChanges) + compare(availableHeightSpy.count, ++availableHeightChanges) + + control.destroy() + } + + function test_background() { + var control = popup.createObject(testCase) + verify(control) + + control.background = rect.createObject(testCase) + + // background has no x or width set, so its width follows control's width + control.width = 320 + compare(control.background.width, control.width) + + // background has no y or height set, so its height follows control's height + compare(control.background.height, control.height) + control.height = 240 + + // has width => width does not follow + control.background.width /= 2 + control.width += 20 + verify(control.background.width !== control.width) + + // reset width => width follows again + control.background.width = undefined + control.width += 20 + compare(control.background.width, control.width) + + // has x => width does not follow + control.background.x = 10 + control.width += 20 + verify(control.background.width !== control.width) + + // has height => height does not follow + control.background.height /= 2 + control.height -= 20 + verify(control.background.height !== control.height) + + // reset height => height follows again + control.background.height = undefined + control.height -= 20 + compare(control.background.height, control.height) + + // has y => height does not follow + control.background.y = 10 + control.height -= 20 + verify(control.background.height !== control.height) + + control.destroy() + } + + function getChild(control, objname, idx) { + var index = idx + for (var i = index+1; i < control.children.length; i++) + { + if (control.children[i].objectName === objname) { + index = i + break + } + } + return index + } + + Component { + id: component + Pane { + id: panel + property alias button: _button; + property alias popup: _popup; + property alias listview: _listview + font.pixelSize: 30 + Column { + Button { + id: _button + text: "Button" + font.pixelSize: 20 + + Popup { + id: _popup + y: button.height + implicitHeight: Math.min(396, _listview.contentHeight) + contentItem: ListView { + id: _listview + height: _button.height * 20 + model: 2 + delegate: Button { + objectName: "delegate" + width: _button.width + height: _button.height + text: "N: " + index + checkable: true + autoExclusive: true + } + } + } + } + } + } + } + + function test_font() { // QTBUG_50984 + var control = component.createObject(testCase) + verify(control) + verify(control.button) + verify(control.popup) + verify(control.listview) + + waitForRendering(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + compare(control.font.pixelSize, 30) + compare(control.button.font.pixelSize, 20) + + var popup = control.popup + popup.open() + + verify(popup.contentItem) + + var listview = popup.contentItem + verify(listview.contentItem) + waitForRendering(listview) + + var idx1 = getChild(listview.contentItem, "delegate", -1) + compare(listview.contentItem.children[idx1].font.pixelSize, 20) + var idx2 = getChild(listview.contentItem, "delegate", idx1) + compare(listview.contentItem.children[idx2].font.pixelSize, 20) + + control.button.font.pixelSize = control.button.font.pixelSize + 10 + compare(control.button.font.pixelSize, 30) + waitForRendering(listview) + compare(listview.contentItem.children[idx1].font.pixelSize, 30) + compare(listview.contentItem.children[idx2].font.pixelSize, 30) + + control.destroy() + } + + Component { + id: localeComponent + Pane { + id: panel + property alias button: _button; + property alias popup: _popup; + property alias button1: _button1; + property alias button2: _button2; + locale: Qt.locale("en_US") + Column { + Button { + id: _button + text: "Button" + locale: Qt.locale("nb_NO") + Popup { + id: _popup + y: _button.height + implicitHeight: Math.min(396, _column.contentHeight) + contentItem: Column { + id: _column + Button { + id: _button1 + text: "Button 1" + } + Button { + id: _button2 + text: "Button 2" + } + } + } + } + } + } + } + + function test_locale() { // QTBUG_50984 + // test looking up natural locale from ancestors + var control = localeComponent.createObject(testCase) + verify(control) + verify(control.button) + verify(control.popup) + verify(control.button1) + verify(control.button2) + + waitForRendering(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + var popup = control.popup + popup.open() + + compare(control.locale.name, "en_US") + compare(control.button.locale.name, "nb_NO") + compare(control.button1.locale.name, "nb_NO") + compare(control.button2.locale.name, "nb_NO") + + control.destroy() + } + + Component { + id: localeComponent2 + Pane { + id: panel + property alias button: _button; + property alias popup: _popup; + property alias button1: _button1; + property alias button2: _button2; + property alias localespy: _lspy; + property alias mirroredspy: _mspy; + property alias localespy_1: _lspy_1; + property alias mirroredspy_1: _mspy_1; + property alias localespy_2: _lspy_2; + property alias mirroredspy_2: _mspy_2; + Column { + Button { + id: _button + text: "Button" + Popup { + id: _popup + y: _button.height + implicitHeight: Math.min(396, _column.contentHeight) + contentItem: Column { + id: _column + Button { + id: _button1 + text: "Button 1" + SignalSpy { + id: _lspy_1 + target: _button1 + signalName: "localeChanged" + } + SignalSpy { + id: _mspy_1 + target: _button1 + signalName: "mirroredChanged" + } + } + Button { + id: _button2 + text: "Button 2" + SignalSpy { + id: _lspy_2 + target: _button2 + signalName: "localeChanged" + } + SignalSpy { + id: _mspy_2 + target: _button2 + signalName: "mirroredChanged" + } + } + } + } + SignalSpy { + id: _lspy + target: _button + signalName: "localeChanged" + } + SignalSpy { + id: _mspy + target: _button + signalName: "mirroredChanged" + } + } + } + } + } + + function test_locale_2() { // QTBUG_50984 + // test default locale and locale inheritance + var control = localeComponent2.createObject(testCase) + verify(control) + verify(control.button) + verify(control.popup) + verify(control.button1) + verify(control.button2) + + waitForRendering(control) + + control.forceActiveFocus() + verify(control.activeFocus) + + var popup = control.popup + popup.open() + + var defaultLocale = Qt.locale() + + compare(control.locale.name, defaultLocale.name) + compare(control.button.locale.name, defaultLocale.name) + compare(control.button1.locale.name, defaultLocale.name) + compare(control.button2.locale.name, defaultLocale.name) + + control.locale = Qt.locale("nb_NO") + control.localespy.wait() + compare(control.localespy.count, 1) + compare(control.mirroredspy.count, 0) + compare(control.locale.name, "nb_NO") + compare(control.button.locale.name, "nb_NO") + compare(control.button1.locale.name, "nb_NO") + compare(control.button2.locale.name, "nb_NO") + compare(control.localespy_1.count, 1) + compare(control.mirroredspy_1.count, 0) + compare(control.localespy_2.count, 1) + compare(control.mirroredspy_2.count, 0) + + control.locale = Qt.locale("ar_EG") + control.localespy.wait() + compare(control.localespy.count, 2) + compare(control.mirroredspy.count, 1) + compare(control.locale.name, "ar_EG") + compare(control.button.locale.name, "ar_EG") + compare(control.button1.locale.name, "ar_EG") + compare(control.button2.locale.name, "ar_EG") + compare(control.localespy_1.count, 2) + compare(control.mirroredspy_1.count, 1) + compare(control.localespy_2.count, 2) + compare(control.mirroredspy_2.count, 1) + + control.destroy() + } +} |