diff options
Diffstat (limited to 'src/gui/painting/qcolor.h')
-rw-r--r-- | src/gui/painting/qcolor.h | 84 |
1 files changed, 28 insertions, 56 deletions
diff --git a/src/gui/painting/qcolor.h b/src/gui/painting/qcolor.h index 06b264eacf..2d6db1a14c 100644 --- a/src/gui/painting/qcolor.h +++ b/src/gui/painting/qcolor.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtGui module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 https://www.qt.io/terms-conditions. For further -** information use the contact form at https://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.LGPL3 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-3.0.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 (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.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 QCOLOR_H #define QCOLOR_H @@ -66,6 +30,8 @@ Q_GUI_EXPORT QDataStream &operator>>(QDataStream &, QColor &); class Q_GUI_EXPORT QColor { public: + // ### Qt7: make this "enum Spec: quint8 {...}" and reorder the members below for tighter + // struct packing. QColor could fit into the inline storage of a QVariant on 32bit. enum Spec { Invalid, Rgb, Hsv, Cmyk, Hsl, ExtendedRgb }; enum NameFormat { HexRgb, HexArgb }; @@ -81,25 +47,28 @@ public: 0) {} QColor(QRgb rgb) noexcept; QColor(QRgba64 rgba64) noexcept; -#if QT_STRINGVIEW_LEVEL < 2 inline QColor(const QString& name); -#endif explicit inline QColor(QStringView name); - inline QColor(const char *aname) : QColor(QLatin1String(aname)) {} - inline QColor(QLatin1String name); + inline QColor(const char *aname); + inline QColor(QLatin1StringView name); QColor(Spec spec) noexcept; + static QColor fromString(QAnyStringView name) noexcept; + QColor &operator=(Qt::GlobalColor color) noexcept; bool isValid() const noexcept; QString name(NameFormat format = HexRgb) const; -#if QT_STRINGVIEW_LEVEL < 2 +#if QT_DEPRECATED_SINCE(6, 6) + QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.") void setNamedColor(const QString& name); -#endif + QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.") void setNamedColor(QStringView name); - void setNamedColor(QLatin1String name); + QT_DEPRECATED_VERSION_X_6_6("Use fromString() instead.") + void setNamedColor(QLatin1StringView name); +#endif static QStringList colorNames(); @@ -223,17 +192,19 @@ public: operator QVariant() const; -#if QT_STRINGVIEW_LEVEL < 2 +#if QT_DEPRECATED_SINCE(6, 6) + QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.") static bool isValidColor(const QString &name); -#endif + QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.") static bool isValidColor(QStringView) noexcept; - static bool isValidColor(QLatin1String) noexcept; + QT_DEPRECATED_VERSION_X_6_6("Use isValidColorName() instead.") + static bool isValidColor(QLatin1StringView) noexcept; +#endif + static bool isValidColorName(QAnyStringView) noexcept; private: void invalidate() noexcept; - template <typename String> - bool setColorFromString(String name); static constexpr bool isRgbaValid(int r, int g, int b, int a = 255) noexcept Q_DECL_CONST_FUNCTION { @@ -299,16 +270,17 @@ public: // can't give friendship to a namespace, so it needs to be public }; Q_DECLARE_TYPEINFO(QColor, Q_RELOCATABLE_TYPE); -inline QColor::QColor(QLatin1String aname) -{ setNamedColor(aname); } +inline QColor::QColor(QLatin1StringView aname) + : QColor(fromString(aname)) {} inline QColor::QColor(QStringView aname) -{ setNamedColor(aname); } + : QColor(fromString(aname)) {} -#if QT_STRINGVIEW_LEVEL < 2 inline QColor::QColor(const QString& aname) -{ setNamedColor(aname); } -#endif + : QColor(fromString(aname)) {} + +inline QColor::QColor(const char *aname) + : QColor(fromString(aname)) {} inline bool QColor::isValid() const noexcept { return cspec != Invalid; } |