diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2023-02-07 14:34:10 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-02-20 12:02:36 +0000 |
commit | 495e6549de0f2bb43f5787cc2b2ff5343408969a (patch) | |
tree | 27ba3dd9ccebc408742f7030d2397ffecf7ac754 /src | |
parent | aa013b88b36fb0bd73767372dada550a73a79a10 (diff) | |
download | qttools-495e6549de0f2bb43f5787cc2b2ff5343408969a.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.
Task-number: QTBUG-110963
Change-Id: I089a75d03828ff894527601fc111d5e39183e695
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
(cherry picked from commit 0911566625acb43c3c18a129ae67612dd3e10da5)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
5 files changed, 72 insertions, 44 deletions
diff --git a/src/designer/src/components/propertyeditor/paletteeditor.cpp b/src/designer/src/components/propertyeditor/paletteeditor.cpp index ddf49245e..c15b3cf01 100644 --- a/src/designer/src/components/propertyeditor/paletteeditor.cpp +++ b/src/designer/src/components/propertyeditor/paletteeditor.cpp @@ -3,6 +3,7 @@ #include "paletteeditor.h" +#include <qdesigner_utils_p.h> #include <iconloader_p.h> #include <qtcolorbutton.h> @@ -357,6 +358,11 @@ void PaletteEditor::load() } ////////////////////// +// Column 0: Role name and reset button. Uses a boolean value indicating +// whether the role is modified for the edit role. +// Column 1: Color group Active +// Column 2: Color group Inactive (visibility depending on m_compute/detail radio group) +// Column 3: Color group Disabled PaletteModel::PaletteModel(QObject *parent) : QAbstractTableModel(parent) @@ -388,6 +394,12 @@ QBrush PaletteModel::brushAt(const QModelIndex &index) const return m_palette.brush(columnToGroup(index.column()), roleAt(index.row())); } +// Palette resolve mask with all group bits for a row/role +quint64 PaletteModel::rowMask(const QModelIndex &index) const +{ + return paletteResolveMask(roleAt(index.row())); +} + QVariant PaletteModel::data(const QModelIndex &index, int role) const { if (!index.isValid()) @@ -397,15 +409,11 @@ QVariant PaletteModel::data(const QModelIndex &index, int role) const if (index.column() < 0 || index.column() >= 4) return QVariant(); - if (index.column() == 0) { + if (index.column() == 0) { // Role name/bold print if changed if (role == Qt::DisplayRole) return m_roleEntries.at(index.row()).name; - if (role == Qt::EditRole) { - const uint mask = m_palette.resolveMask(); - if (mask & (1 << int(roleAt(index.row())))) - return true; - return false; - } + if (role == Qt::EditRole) + return (rowMask(index) & m_palette.resolveMask()) != 0; return QVariant(); } if (role == Qt::ToolTipRole) @@ -466,7 +474,7 @@ bool PaletteModel::setData(const QModelIndex &index, const QVariant &value, int if (index.column() == 0 && role == Qt::EditRole) { auto mask = m_palette.resolveMask(); const bool isMask = qvariant_cast<bool>(value); - const auto bitMask = 1ull << quint64(colorRole); + const auto bitMask = rowMask(index); if (isMask) { mask |= bitMask; } else { diff --git a/src/designer/src/components/propertyeditor/paletteeditor.h b/src/designer/src/components/propertyeditor/paletteeditor.h index 2eae4c3fd..5fadf5f85 100644 --- a/src/designer/src/components/propertyeditor/paletteeditor.h +++ b/src/designer/src/components/propertyeditor/paletteeditor.h @@ -96,6 +96,9 @@ public: QPalette::ColorRole colorRole() const { return QPalette::NoRole; } void setCompute(bool on) { m_compute = on; } + + quint64 rowMask(const QModelIndex &index) const; + signals: void paletteChanged(const QPalette &palette); private: 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) |