diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-07 14:34:10 +0100 |
---|---|---|
committer | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-20 12:32:42 +0100 |
commit | 0911566625acb43c3c18a129ae67612dd3e10da5 (patch) | |
tree | d79aca05deab6591a4c7e2e27c731c0fb1718154 /src/designer/src/lib/shared | |
parent | e4f952fb82c202b6aec9c7717644eff23ce5bd47 (diff) | |
download | qttools-0911566625acb43c3c18a129ae67612dd3e10da5.tar.gz |
Qt Designer: Fix palette mask handling to consider single groups
Whereas the palette resolve mask in Qt 5 had one bit for all 3 colors
of a role, the mask is now a 64bit value with one bit for each
combination of role/group. Introduce helper functions (copied from
the QPalette source) to get the correct mask bits for each role/group
and for all groups of a role.
In the multiselection property helpers, check each role/group.
In the palette editor, use row masks to clear rows.
Pick-to: 6.5 6.4
Task-number: QTBUG-110963
Change-Id: I089a75d03828ff894527601fc111d5e39183e695
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Diffstat (limited to 'src/designer/src/lib/shared')
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_propertycommand.cpp | 66 | ||||
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_utils.cpp | 17 | ||||
-rw-r--r-- | src/designer/src/lib/shared/qdesigner_utils_p.h | 6 |
3 files changed, 53 insertions, 36 deletions
diff --git a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp index 866834a7e..814c439d3 100644 --- a/src/designer/src/lib/shared/qdesigner_propertycommand.cpp +++ b/src/designer/src/lib/shared/qdesigner_propertycommand.cpp @@ -251,36 +251,30 @@ quint64 compareSubProperties(const QFont & f1, const QFont & f2) return rc; } -// Compare colors of a role -bool roleColorChanged(const QPalette & p1, const QPalette & p2, QPalette::ColorRole role) -{ - for (int group = QPalette::Active; group < QPalette::NColorGroups; group++) { - const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group); - if (p1.color(pgroup, role) != p2.color(pgroup, role)) - return true; - } - return false; -} // find changed subproperties of a QPalette taking the [undocumented] resolve flags into account quint64 compareSubProperties(const QPalette & p1, const QPalette & p2) { quint64 rc = 0; - unsigned maskBit = 1u; // generate a mask for each role const auto p1Changed = p1.resolveMask(); const auto p2Changed = p2.resolveMask(); - for (int role = QPalette::WindowText; role < QPalette::NColorRoles; role++, maskBit <<= 1u) { - const bool p1RoleChanged = p1Changed & maskBit; - const bool p2RoleChanged = p2Changed & maskBit; - // Role has been set/reset in editor - if (p1RoleChanged != p2RoleChanged) { - rc |= maskBit; - } else { - // Was modified in both palettes: Compare values. - if (p1RoleChanged && p2RoleChanged && roleColorChanged(p1, p2, static_cast<QPalette::ColorRole>(role))) + + for (int r = 0; r < static_cast<int>(QPalette::NColorRoles); ++r) { + for (int g = 0; g < static_cast<int>(QPalette::NColorGroups); ++g) { + const auto role = static_cast<QPalette::ColorRole>(r); + const auto group = static_cast<QPalette::ColorGroup>(g); + const auto maskBit = qdesigner_internal::paletteResolveMask(group, role); + const bool p1RoleChanged = p1Changed & maskBit; + const bool p2RoleChanged = p2Changed & maskBit; + if (p1RoleChanged != p2RoleChanged // Role has been set/reset in editor + // Was modified in both palettes: Compare values. + || (p1RoleChanged && p2RoleChanged + && p1.brush(group, role).color() != p2.brush(group, role).color())) { rc |= maskBit; + } } } + return rc; } @@ -463,23 +457,23 @@ QPalette applyPaletteSubProperty(const QPalette &oldValue, const QPalette &newVa quint64 mask) { QPalette rc = oldValue; - // apply a mask for each role - quint64 maskBit = 1u; - for (int role = QPalette::WindowText; role < QPalette::NColorRoles; role++, maskBit <<= 1u) { - if (mask & maskBit) { - for (int group = QPalette::Active; group < QPalette::NColorGroups; group++) { - const QPalette::ColorGroup pgroup = static_cast<QPalette::ColorGroup>(group); - const QPalette::ColorRole prole = static_cast<QPalette::ColorRole>(role); - rc.setColor(pgroup, prole, newValue.color(pgroup, prole)); + // apply a mask for each role/group + for (int r = 0; r < static_cast<int>(QPalette::NColorRoles); ++r) { + for (int g = 0; g < static_cast<int>(QPalette::NColorGroups); ++g) { + const auto role = static_cast<QPalette::ColorRole>(r); + const auto group = static_cast<QPalette::ColorGroup>(g); + const auto maskBit = qdesigner_internal::paletteResolveMask(group, role); + if (mask & maskBit) { + rc.setColor(group, role, newValue.color(group, role)); + // Set the resolve bit from NewValue in return value + auto resolveMask = rc.resolveMask(); + const bool origFlag = newValue.resolveMask() & maskBit; + if (origFlag) + resolveMask |= maskBit; + else + resolveMask &= ~maskBit; + rc.setResolveMask(resolveMask); } - // Set the resolve bit from NewValue in return value - auto r = rc.resolveMask(); - const bool origFlag = newValue.resolveMask() & maskBit; - if (origFlag) - r |= maskBit; - else - r &= ~maskBit; - rc.setResolveMask(r); } } return rc; diff --git a/src/designer/src/lib/shared/qdesigner_utils.cpp b/src/designer/src/lib/shared/qdesigner_utils.cpp index 8913e6637..f8ab045f3 100644 --- a/src/designer/src/lib/shared/qdesigner_utils.cpp +++ b/src/designer/src/lib/shared/qdesigner_utils.cpp @@ -23,6 +23,7 @@ #include <QtWidgets/qapplication.h> #include <QtGui/qicon.h> +#include <QtGui/qpalette.h> #include <QtGui/qpixmap.h> #include <QtWidgets/qlistwidget.h> #include <QtWidgets/qtreewidget.h> @@ -776,6 +777,22 @@ namespace qdesigner_internal m_widget->setUpdatesEnabled(true); } +// from qpalette.cpp +quint64 paletteResolveMask(QPalette::ColorGroup colorGroup, + QPalette::ColorRole colorRole) +{ + const auto offset = quint64(QPalette::NColorRoles) * quint64(colorGroup); + const auto bitPos = quint64(colorRole) + offset; + return 1ull << bitPos; +} + +quint64 paletteResolveMask(QPalette::ColorRole colorRole) +{ + return paletteResolveMask(QPalette::Active, colorRole) + | paletteResolveMask(QPalette::Inactive, colorRole) + | paletteResolveMask(QPalette::Disabled, colorRole); +} + } // namespace qdesigner_internal QT_END_NAMESPACE diff --git a/src/designer/src/lib/shared/qdesigner_utils_p.h b/src/designer/src/lib/shared/qdesigner_utils_p.h index fec041cf6..0743abb29 100644 --- a/src/designer/src/lib/shared/qdesigner_utils_p.h +++ b/src/designer/src/lib/shared/qdesigner_utils_p.h @@ -443,6 +443,12 @@ private: const bool m_enabled; }; +// QPalette helpers: Mask for a single color role/group +QDESIGNER_SHARED_EXPORT quint64 paletteResolveMask(QPalette::ColorGroup colorGroup, + QPalette::ColorRole colorRole); +// Mask for the colors of a role in all groups (Active/Inactive/Disabled) +QDESIGNER_SHARED_EXPORT quint64 paletteResolveMask(QPalette::ColorRole colorRole); + namespace Utils { inline int valueOf(const QVariant &value, bool *ok = nullptr) |