diff options
Diffstat (limited to 'src/quick/items/qquickpaletteproviderprivatebase_p.h')
-rw-r--r-- | src/quick/items/qquickpaletteproviderprivatebase_p.h | 97 |
1 files changed, 37 insertions, 60 deletions
diff --git a/src/quick/items/qquickpaletteproviderprivatebase_p.h b/src/quick/items/qquickpaletteproviderprivatebase_p.h index b1b5958329..869e86c954 100644 --- a/src/quick/items/qquickpaletteproviderprivatebase_p.h +++ b/src/quick/items/qquickpaletteproviderprivatebase_p.h @@ -1,38 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: http://www.qt.io/licensing/ -** -** This file is part of the QtQuick 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$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QQUICKPALETTEPROVIDERPRIVATEBASE_H #define QQUICKPALETTEPROVIDERPRIVATEBASE_H @@ -49,7 +16,7 @@ #include <QtQuick/private/qquickpalette_p.h> #include <QtQuick/private/qquickabstractpaletteprovider_p.h> - +#include <QtGui/qwindow.h> #include <QtQml/private/qlazilyallocated_p.h> QT_BEGIN_NAMESPACE @@ -120,16 +87,16 @@ public: /*! \internal - A default palette for this component. + The default palette for this component. */ QPalette defaultPalette() const override; /*! \internal - A parent palette for this component. Can be null. + The parent palette for this component. Can be null. */ - QPalette parentPalette() const override; + QPalette parentPalette(const QPalette &fallbackPalette) const override; /*! \internal @@ -150,6 +117,9 @@ public: */ virtual void updateChildrenPalettes(const QPalette &parentPalette); +protected: + void setCurrentColorGroup(); + private: using PalettePtr = std::unique_ptr<QQuickPalette>; using Self = QQuickPaletteProviderPrivateBase<I, Impl>; @@ -160,7 +130,6 @@ private: QQuickPalette *windowPalette() const; - void setCurrentColorGroup(); void connectItem(); @@ -245,14 +214,14 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::registerPalette(PalettePtr palet m_palette = std::move(palette); m_palette->setPaletteProvider(this); - m_palette->inheritPalette(parentPalette()); + m_palette->inheritPalette(parentPalette(defaultPalette())); setCurrentColorGroup(); // In order to avoid extra noise, we should connect // the following signals only after everything is already setup I::connect(paletteData(), &QQuickPalette::changed, itemWithPalette(), &I::paletteChanged); - I::connect(paletteData(), &QQuickPalette::changed, [this]{ updateChildrenPalettes(toQPalette()); }); + I::connect(paletteData(), &QQuickPalette::changed, itemWithPalette(), [this]{ updateChildrenPalettes(toQPalette()); }); } template<class T> struct dependent_false : std::false_type {}; @@ -261,9 +230,9 @@ template<class Impl, class I> decltype(auto) getPrivateImpl(I &t) { return Impl: template <class T> decltype(auto) getPrivate(T &item) { - if constexpr (std::is_same_v<T, QQuickWindow>) { + if constexpr (std::is_base_of_v<T, QQuickWindow>) { return getPrivateImpl<QQuickWindowPrivate>(item); - } else if constexpr (std::is_same_v<T, QQuickItem>) { + } else if constexpr (std::is_base_of_v<T, QQuickItem>) { return getPrivateImpl<QQuickItemPrivate>(item); } else { static_assert (dependent_false<T>::value, "Extend please."); @@ -285,15 +254,18 @@ QQuickPalette *QQuickPaletteProviderPrivateBase<I, Impl>::windowPalette() const } template<class I, class Impl> -QPalette QQuickPaletteProviderPrivateBase<I, Impl>::parentPalette() const +QPalette QQuickPaletteProviderPrivateBase<I, Impl>::parentPalette(const QPalette &fallbackPalette) const { if constexpr (!isRootWindow<I>()) { - for (auto parentItem = itemWithPalette()->parentItem(); parentItem; - parentItem = parentItem->parentItem()) { - - // Don't allocate a new palette here. Use only if it's already pre allocated - if (parentItem && getPrivate(*parentItem)->providesPalette()) { - return getPrivate(*parentItem)->palette()->toQPalette(); + // Popups should always inherit from their window, even child popups: QTBUG-115707. + if (!std::is_base_of_v<QQuickPopup, I>) { + for (auto parentItem = itemWithPalette()->parentItem(); parentItem; + parentItem = parentItem->parentItem()) { + + // Don't allocate a new palette here. Use only if it's already pre allocated + if (parentItem && getPrivate(*parentItem)->providesPalette()) { + return getPrivate(*parentItem)->palette()->toQPalette(); + } } } @@ -302,7 +274,7 @@ QPalette QQuickPaletteProviderPrivateBase<I, Impl>::parentPalette() const } } - return defaultPalette(); + return fallbackPalette; } template<class I> @@ -310,7 +282,7 @@ const QQuickItem* rootItem(const I &item) { if constexpr (isRootWindow<I>()) { return item.contentItem(); - } else if constexpr (std::is_same_v<QQuickPopup, I>) { + } else if constexpr (std::is_base_of_v<QQuickPopup, I>) { return nullptr; } else { return &item; @@ -334,9 +306,12 @@ template<class I, class Impl> void QQuickPaletteProviderPrivateBase<I, Impl>::setCurrentColorGroup() { if constexpr (!isRootWindow<I>()) { - if (paletteData()) { + if (providesPalette()) { const bool enabled = itemWithPalette()->isEnabled(); - paletteData()->setCurrentGroup(enabled ? QPalette::Active : QPalette::Disabled); + const auto window = itemWithPalette()->window(); + const bool active = window ? window->isActive() : true; + palette()->setCurrentGroup(enabled ? (active ? QPalette::Active : QPalette::Inactive) + : QPalette::Disabled); } } } @@ -351,8 +326,7 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::updateChildrenPalettes(const QPa * nothing in this instantiation of updateChildrenPalettes and instead add an override in * QQuickWindowPrivate, which does the correct thing. */ - Q_UNREACHABLE(); // You are not supposed to call this function - return; + Q_UNREACHABLE_RETURN(); // You are not supposed to call this function } else { if (auto root = rootItem(*itemWithPalette())) { for (auto &&child : root->childItems()) { @@ -371,9 +345,12 @@ void QQuickPaletteProviderPrivateBase<I, Impl>::connectItem() if constexpr (!isRootWindow<I>()) { // Item with palette has the same lifetime as its implementation that inherits this class - I::connect(itemWithPalette(), &I::parentChanged , [this]() { inheritPalette(parentPalette()); }); - I::connect(itemWithPalette(), &I::windowChanged , [this]() { inheritPalette(parentPalette()); }); - I::connect(itemWithPalette(), &I::enabledChanged, [this]() { setCurrentColorGroup(); }); + I::connect(itemWithPalette(), &I::parentChanged, + itemWithPalette(), [this]() { inheritPalette(parentPalette(defaultPalette())); }); + I::connect(itemWithPalette(), &I::windowChanged, + itemWithPalette(), [this]() { inheritPalette(parentPalette(defaultPalette())); }); + I::connect(itemWithPalette(), &I::enabledChanged, + itemWithPalette(), [this]() { setCurrentColorGroup(); }); } } |