Move palette helper functions to QPalettePrivate
We want to use the bitPosition function in Qt Quick, in order to be able to unset a bit in the resolve mask for a specific color group and role. This patch, solves this by adding a new qpalette_p.h header, which declares QPalettePrivate, allowing those helper functions to be accessed anywhere internally in the qt framework. Change-Id: Iecb28b48289d6bcabf0936274964a05d3c44efc0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 417878904b39b444632df18f7dd37bcb073c0467) Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
This commit is contained in:
parent
4caf69d65a
commit
79da2a10c6
@ -101,7 +101,7 @@ qt_internal_add_module(Gui
|
|||||||
kernel/qoffscreensurface_platform.h
|
kernel/qoffscreensurface_platform.h
|
||||||
kernel/qopenglcontext.h
|
kernel/qopenglcontext.h
|
||||||
kernel/qpaintdevicewindow.cpp kernel/qpaintdevicewindow.h kernel/qpaintdevicewindow_p.h
|
kernel/qpaintdevicewindow.cpp kernel/qpaintdevicewindow.h kernel/qpaintdevicewindow_p.h
|
||||||
kernel/qpalette.cpp kernel/qpalette.h
|
kernel/qpalette.cpp kernel/qpalette.h kernel/qpalette_p.h
|
||||||
kernel/qpixelformat.cpp kernel/qpixelformat.h
|
kernel/qpixelformat.cpp kernel/qpixelformat.h
|
||||||
kernel/qplatformclipboard.cpp kernel/qplatformclipboard.h
|
kernel/qplatformclipboard.cpp kernel/qplatformclipboard.h
|
||||||
kernel/qplatformcursor.cpp kernel/qplatformcursor.h
|
kernel/qplatformcursor.cpp kernel/qplatformcursor.h
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 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
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
|
||||||
|
|
||||||
#include "qpalette.h"
|
#include "qpalette_p.h"
|
||||||
#include "qguiapplication.h"
|
|
||||||
#include "qguiapplication_p.h"
|
#include "qguiapplication_p.h"
|
||||||
#include "qdatastream.h"
|
#include "qdatastream.h"
|
||||||
#include "qvariant.h"
|
#include "qvariant.h"
|
||||||
@ -12,16 +11,14 @@
|
|||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
static int qt_palette_count = 1;
|
constexpr QPalette::ResolveMask QPalettePrivate::colorRoleOffset(QPalette::ColorGroup colorGroup)
|
||||||
|
|
||||||
static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup)
|
|
||||||
{
|
{
|
||||||
// Exclude NoRole; that bit is used for Accent
|
// Exclude NoRole; that bit is used for Accent
|
||||||
return (qToUnderlying(QPalette::NColorRoles) - 1) * qToUnderlying(colorGroup);
|
return (qToUnderlying(QPalette::NColorRoles) - 1) * qToUnderlying(colorGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup,
|
constexpr QPalette::ResolveMask QPalettePrivate::bitPosition(QPalette::ColorGroup colorGroup,
|
||||||
QPalette::ColorRole colorRole)
|
QPalette::ColorRole colorRole)
|
||||||
{
|
{
|
||||||
// Map Accent into NoRole for resolving purposes
|
// Map Accent into NoRole for resolving purposes
|
||||||
if (colorRole == QPalette::Accent)
|
if (colorRole == QPalette::Accent)
|
||||||
@ -30,47 +27,11 @@ static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGro
|
|||||||
return colorRole + colorRoleOffset(colorGroup);
|
return colorRole + colorRoleOffset(colorGroup);
|
||||||
}
|
}
|
||||||
|
|
||||||
static_assert(bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1),
|
static_assert(QPalettePrivate::bitPosition(QPalette::ColorGroup(QPalette::NColorGroups - 1),
|
||||||
QPalette::ColorRole(QPalette::NColorRoles - 1))
|
QPalette::ColorRole(QPalette::NColorRoles - 1))
|
||||||
< sizeof(QPalette::ResolveMask) * CHAR_BIT,
|
< sizeof(QPalette::ResolveMask) * CHAR_BIT,
|
||||||
"The resolve mask type is not wide enough to fit the entire bit mask.");
|
"The resolve mask type is not wide enough to fit the entire bit mask.");
|
||||||
|
|
||||||
class QPalettePrivate
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
class Data : public QSharedData {
|
|
||||||
public:
|
|
||||||
// Every instance of Data has to have a unique serial number, even
|
|
||||||
// if it gets created by copying another - we wouldn't create a copy
|
|
||||||
// in the first place if the serial number should be the same!
|
|
||||||
Data(const Data &other)
|
|
||||||
: QSharedData(other)
|
|
||||||
{
|
|
||||||
for (int grp = 0; grp < int(QPalette::NColorGroups); grp++) {
|
|
||||||
for (int role = 0; role < int(QPalette::NColorRoles); role++)
|
|
||||||
br[grp][role] = other.br[grp][role];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Data() = default;
|
|
||||||
|
|
||||||
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles];
|
|
||||||
const int ser_no = qt_palette_count++;
|
|
||||||
};
|
|
||||||
|
|
||||||
QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data)
|
|
||||||
: ref(1), data(data)
|
|
||||||
{ }
|
|
||||||
QPalettePrivate()
|
|
||||||
: QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data))
|
|
||||||
{ }
|
|
||||||
|
|
||||||
QAtomicInt ref;
|
|
||||||
QPalette::ResolveMask resolveMask = {0};
|
|
||||||
static inline int qt_palette_private_count = 0;
|
|
||||||
int detach_no = ++qt_palette_private_count;
|
|
||||||
QExplicitlySharedDataPointer<Data> data;
|
|
||||||
};
|
|
||||||
|
|
||||||
static QColor qt_mix_colors(QColor a, QColor b)
|
static QColor qt_mix_colors(QColor a, QColor b)
|
||||||
{
|
{
|
||||||
return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
|
return QColor((a.red() + b.red()) / 2, (a.green() + b.green()) / 2,
|
||||||
@ -849,7 +810,7 @@ void QPalette::setBrush(ColorGroup cg, ColorRole cr, const QBrush &b)
|
|||||||
cg = Active;
|
cg = Active;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto newResolveMask = d->resolveMask | ResolveMask(1) << bitPosition(cg, cr);
|
const auto newResolveMask = d->resolveMask | ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr);
|
||||||
const auto valueChanged = d->data->br[cg][cr] != b;
|
const auto valueChanged = d->data->br[cg][cr] != b;
|
||||||
|
|
||||||
if (valueChanged) {
|
if (valueChanged) {
|
||||||
@ -896,7 +857,7 @@ bool QPalette::isBrushSet(ColorGroup cg, ColorRole cr) const
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return d->resolveMask & (ResolveMask(1) << bitPosition(cg, cr));
|
return d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(cg, cr));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -1005,7 +966,7 @@ static constexpr QPalette::ResolveMask allResolveMask()
|
|||||||
QPalette::ResolveMask mask = {0};
|
QPalette::ResolveMask mask = {0};
|
||||||
for (int role = 0; role < int(QPalette::NColorRoles); ++role) {
|
for (int role = 0; role < int(QPalette::NColorRoles); ++role) {
|
||||||
for (int grp = 0; grp < int(QPalette::NColorGroups); ++grp) {
|
for (int grp = 0; grp < int(QPalette::NColorGroups); ++grp) {
|
||||||
mask |= (QPalette::ResolveMask(1) << bitPosition(QPalette::ColorGroup(grp), QPalette::ColorRole(role)));
|
mask |= (QPalette::ResolveMask(1) << QPalettePrivate::bitPosition(QPalette::ColorGroup(grp), QPalette::ColorRole(role)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return mask;
|
return mask;
|
||||||
@ -1036,7 +997,7 @@ QPalette QPalette::resolve(const QPalette &other) const
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
for (int grp = 0; grp < int(NColorGroups); ++grp) {
|
for (int grp = 0; grp < int(NColorGroups); ++grp) {
|
||||||
if (!(d->resolveMask & (ResolveMask(1) << bitPosition(ColorGroup(grp), ColorRole(role))))) {
|
if (!(d->resolveMask & (ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(grp), ColorRole(role))))) {
|
||||||
palette.d->data.detach();
|
palette.d->data.detach();
|
||||||
palette.d->data->br[grp][role] = other.d->data->br[grp][role];
|
palette.d->data->br[grp][role] = other.d->data->br[grp][role];
|
||||||
}
|
}
|
||||||
@ -1221,10 +1182,10 @@ void QPalette::setColorGroup(ColorGroup cg, const QBrush &windowText, const QBru
|
|||||||
for (int cr = Highlight; cr <= LinkVisited; ++cr) {
|
for (int cr = Highlight; cr <= LinkVisited; ++cr) {
|
||||||
if (cg == All) {
|
if (cg == All) {
|
||||||
for (int group = Active; group < NColorGroups; ++group) {
|
for (int group = Active; group < NColorGroups; ++group) {
|
||||||
d->resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(group), ColorRole(cr)));
|
d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(group), ColorRole(cr)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
d->resolveMask &= ~(ResolveMask(1) << bitPosition(ColorGroup(cg), ColorRole(cr)));
|
d->resolveMask &= ~(ResolveMask(1) << QPalettePrivate::bitPosition(ColorGroup(cg), ColorRole(cr)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
64
src/gui/kernel/qpalette_p.h
Normal file
64
src/gui/kernel/qpalette_p.h
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
// Copyright (C) 2023 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 QPALETTE_P_H
|
||||||
|
#define QPALETTE_P_H
|
||||||
|
|
||||||
|
//
|
||||||
|
// W A R N I N G
|
||||||
|
// -------------
|
||||||
|
//
|
||||||
|
// This file is not part of the Qt API. It exists purely as an
|
||||||
|
// implementation detail. This header file may change from version to
|
||||||
|
// version without notice, or even be removed.
|
||||||
|
//
|
||||||
|
// We mean it.
|
||||||
|
//
|
||||||
|
|
||||||
|
#include "qpalette.h"
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
|
||||||
|
class QPalettePrivate
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
class Data : public QSharedData {
|
||||||
|
public:
|
||||||
|
// Every instance of Data has to have a unique serial number, even
|
||||||
|
// if it gets created by copying another - we wouldn't create a copy
|
||||||
|
// in the first place if the serial number should be the same!
|
||||||
|
Data(const Data &other)
|
||||||
|
: QSharedData(other)
|
||||||
|
{
|
||||||
|
for (int grp = 0; grp < int(QPalette::NColorGroups); grp++) {
|
||||||
|
for (int role = 0; role < int(QPalette::NColorRoles); role++)
|
||||||
|
br[grp][role] = other.br[grp][role];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Data() = default;
|
||||||
|
|
||||||
|
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles];
|
||||||
|
const int ser_no = qt_palette_count++;
|
||||||
|
};
|
||||||
|
|
||||||
|
QPalettePrivate(const QExplicitlySharedDataPointer<Data> &data)
|
||||||
|
: ref(1), data(data)
|
||||||
|
{ }
|
||||||
|
QPalettePrivate()
|
||||||
|
: QPalettePrivate(QExplicitlySharedDataPointer<Data>(new Data))
|
||||||
|
{ }
|
||||||
|
|
||||||
|
static constexpr QPalette::ResolveMask colorRoleOffset(QPalette::ColorGroup colorGroup);
|
||||||
|
static constexpr QPalette::ResolveMask bitPosition(QPalette::ColorGroup colorGroup,
|
||||||
|
QPalette::ColorRole colorRole);
|
||||||
|
QAtomicInt ref;
|
||||||
|
QPalette::ResolveMask resolveMask = {0};
|
||||||
|
static inline int qt_palette_count = 0;
|
||||||
|
static inline int qt_palette_private_count = 0;
|
||||||
|
int detach_no = ++qt_palette_private_count;
|
||||||
|
QExplicitlySharedDataPointer<Data> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
|
#endif // QPALETTE_P_H
|
Loading…
x
Reference in New Issue
Block a user