/**************************************************************************** ** ** Copyright (C) 2017 The Qt Company Ltd. ** Contact: http://www.qt.io/licensing/ ** ** This file is part of the Qt Quick Templates 2 module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL3$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see http://www.qt.io/terms-conditions. For further ** information use the contact form at http://www.qt.io/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 3 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPLv3 included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 3 requirements ** will be met: https://www.gnu.org/licenses/lgpl.html. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 2.0 or later as published by the Free ** Software Foundation and appearing in the file LICENSE.GPL included in ** the packaging of this file. Please review the following information to ** ensure the GNU General Public License version 2.0 requirements will be ** met: http://www.gnu.org/licenses/gpl-2.0.html. ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qquickpopupitem_p_p.h" #include "qquickapplicationwindow_p.h" #include "qquickshortcutcontext_p_p.h" #include "qquickcontrol_p_p.h" #include "qquickpopup_p_p.h" #include #include QT_BEGIN_NAMESPACE class QQuickPopupItemPrivate : public QQuickControlPrivate { Q_DECLARE_PUBLIC(QQuickPopupItem) public: QQuickPopupItemPrivate(QQuickPopup *popup); void implicitWidthChanged() override; void implicitHeightChanged() override; void resolveFont() override; void resolvePalette() override; QQuickItem *getContentItem() override; int backId; int escapeId; QQuickPopup *popup; }; QQuickPopupItemPrivate::QQuickPopupItemPrivate(QQuickPopup *popup) : backId(0), escapeId(0), popup(popup) { isTabFence = true; } void QQuickPopupItemPrivate::implicitWidthChanged() { QQuickControlPrivate::implicitWidthChanged(); emit popup->implicitWidthChanged(); } void QQuickPopupItemPrivate::implicitHeightChanged() { QQuickControlPrivate::implicitHeightChanged(); emit popup->implicitHeightChanged(); } void QQuickPopupItemPrivate::resolveFont() { if (QQuickApplicationWindow *window = qobject_cast(popup->window())) inheritFont(window->font()); else inheritFont(themeFont(QPlatformTheme::SystemFont)); } void QQuickPopupItemPrivate::resolvePalette() { if (QQuickApplicationWindow *window = qobject_cast(popup->window())) inheritPalette(window->palette()); else inheritPalette(themePalette(QPlatformTheme::SystemPalette)); } QQuickItem *QQuickPopupItemPrivate::getContentItem() { Q_Q(QQuickPopupItem); if (!contentItem) return new QQuickItem(q); return contentItem; } QQuickPopupItem::QQuickPopupItem(QQuickPopup *popup) : QQuickControl(*(new QQuickPopupItemPrivate(popup)), nullptr) { setParent(popup); setFlag(ItemIsFocusScope); setAcceptedMouseButtons(Qt::AllButtons); #if QT_CONFIG(cursor) setCursor(Qt::ArrowCursor); #endif #if QT_CONFIG(quicktemplates2_hover) // TODO: switch to QStyleHints::useHoverEffects in Qt 5.8 setHoverEnabled(true); // setAcceptHoverEvents(QGuiApplication::styleHints()->useHoverEffects()); // connect(QGuiApplication::styleHints(), &QStyleHints::useHoverEffectsChanged, this, &QQuickItem::setAcceptHoverEvents); #endif } void QQuickPopupItem::grabShortcut() { #if QT_CONFIG(shortcut) Q_D(QQuickPopupItem); QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance(); if (!d->backId) d->backId = pApp->shortcutMap.addShortcut(this, Qt::Key_Back, Qt::WindowShortcut, QQuickShortcutContext::matcher); if (!d->escapeId) d->escapeId = pApp->shortcutMap.addShortcut(this, Qt::Key_Escape, Qt::WindowShortcut, QQuickShortcutContext::matcher); #endif } void QQuickPopupItem::ungrabShortcut() { #if QT_CONFIG(shortcut) Q_D(QQuickPopupItem); QGuiApplicationPrivate *pApp = QGuiApplicationPrivate::instance(); if (d->backId) { pApp->shortcutMap.removeShortcut(d->backId, this); d->backId = 0; } if (d->escapeId) { pApp->shortcutMap.removeShortcut(d->escapeId, this); d->escapeId = 0; } #endif } void QQuickPopupItem::updatePolish() { Q_D(QQuickPopupItem); return QQuickPopupPrivate::get(d->popup)->reposition(); } bool QQuickPopupItem::event(QEvent *event) { #if QT_CONFIG(shortcut) Q_D(QQuickPopupItem); if (event->type() == QEvent::Shortcut) { QShortcutEvent *se = static_cast(event); if (se->shortcutId() == d->escapeId || se->shortcutId() == d->backId) { QQuickPopupPrivate *p = QQuickPopupPrivate::get(d->popup); if (p->interactive) { p->closeOrReject(); return true; } } } #endif return QQuickItem::event(event); } bool QQuickPopupItem::childMouseEventFilter(QQuickItem *child, QEvent *event) { Q_D(QQuickPopupItem); return d->popup->childMouseEventFilter(child, event); } void QQuickPopupItem::focusInEvent(QFocusEvent *event) { Q_D(QQuickPopupItem); d->popup->focusInEvent(event); } void QQuickPopupItem::focusOutEvent(QFocusEvent *event) { Q_D(QQuickPopupItem); d->popup->focusOutEvent(event); } void QQuickPopupItem::keyPressEvent(QKeyEvent *event) { Q_D(QQuickPopupItem); d->popup->keyPressEvent(event); } void QQuickPopupItem::keyReleaseEvent(QKeyEvent *event) { Q_D(QQuickPopupItem); d->popup->keyReleaseEvent(event); } void QQuickPopupItem::mousePressEvent(QMouseEvent *event) { Q_D(QQuickPopupItem); d->popup->mousePressEvent(event); } void QQuickPopupItem::mouseMoveEvent(QMouseEvent *event) { Q_D(QQuickPopupItem); d->popup->mouseMoveEvent(event); } void QQuickPopupItem::mouseReleaseEvent(QMouseEvent *event) { Q_D(QQuickPopupItem); d->popup->mouseReleaseEvent(event); } void QQuickPopupItem::mouseDoubleClickEvent(QMouseEvent *event) { Q_D(QQuickPopupItem); d->popup->mouseDoubleClickEvent(event); } void QQuickPopupItem::mouseUngrabEvent() { Q_D(QQuickPopupItem); d->popup->mouseUngrabEvent(); } #if QT_CONFIG(quicktemplates2_multitouch) void QQuickPopupItem::touchEvent(QTouchEvent *event) { Q_D(QQuickPopupItem); d->popup->touchEvent(event); } void QQuickPopupItem::touchUngrabEvent() { Q_D(QQuickPopupItem); d->popup->touchUngrabEvent(); } #endif #if QT_CONFIG(wheelevent) void QQuickPopupItem::wheelEvent(QWheelEvent *event) { Q_D(QQuickPopupItem); d->popup->wheelEvent(event); } #endif void QQuickPopupItem::contentItemChange(QQuickItem *newItem, QQuickItem *oldItem) { Q_D(QQuickPopupItem); QQuickControl::contentItemChange(newItem, oldItem); d->popup->contentItemChange(newItem, oldItem); } void QQuickPopupItem::fontChange(const QFont &newFont, const QFont &oldFont) { Q_D(QQuickPopupItem); QQuickControl::fontChange(newFont, oldFont); d->popup->fontChange(newFont, oldFont); } void QQuickPopupItem::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { Q_D(QQuickPopupItem); QQuickControl::geometryChanged(newGeometry, oldGeometry); d->popup->geometryChanged(newGeometry, oldGeometry); } void QQuickPopupItem::localeChange(const QLocale &newLocale, const QLocale &oldLocale) { Q_D(QQuickPopupItem); QQuickControl::localeChange(newLocale, oldLocale); d->popup->localeChange(newLocale, oldLocale); } void QQuickPopupItem::mirrorChange() { Q_D(QQuickPopupItem); emit d->popup->mirroredChanged(); } void QQuickPopupItem::itemChange(ItemChange change, const ItemChangeData &data) { Q_D(QQuickPopupItem); QQuickControl::itemChange(change, data); d->popup->itemChange(change, data); } void QQuickPopupItem::paddingChange(const QMarginsF &newPadding, const QMarginsF &oldPadding) { Q_D(QQuickPopupItem); QQuickControl::paddingChange(newPadding, oldPadding); d->popup->paddingChange(newPadding, oldPadding); } void QQuickPopupItem::paletteChange(const QPalette &newPalette, const QPalette &oldPalette) { Q_D(QQuickPopupItem); QQuickControl::paletteChange(newPalette, oldPalette); d->popup->paletteChange(newPalette, oldPalette); } QFont QQuickPopupItem::defaultFont() const { Q_D(const QQuickPopupItem); return d->popup->defaultFont(); } QPalette QQuickPopupItem::defaultPalette() const { Q_D(const QQuickPopupItem); return d->popup->defaultPalette(); } #if QT_CONFIG(accessibility) QAccessible::Role QQuickPopupItem::accessibleRole() const { Q_D(const QQuickPopupItem); return d->popup->accessibleRole(); } void QQuickPopupItem::accessibilityActiveChanged(bool active) { Q_D(const QQuickPopupItem); QQuickControl::accessibilityActiveChanged(active); d->popup->accessibilityActiveChanged(active); } #endif QT_END_NAMESPACE