Commit 41c47566 authored by David Redondo's avatar David Redondo 🏎

[kcms/keys] Highlight changed settings

Manual implementation of change highlighting as done automatically in other
kcms. Highlighted items include: Collpased action delegates whose active key
sequences are different from the default, in the expaned state unset checkboxes
for default key sequences and keysequenceitems for added shortcuts are highlighted.
Finally in the components list, delegates who contain at least one action that is not
in a default state are higlighted in the same style as config modules in the
system settings sidebar.
parent 93764313
......@@ -38,7 +38,8 @@ void BaseModel::addShortcut(const QModelIndex &index, const QKeySequence &shortc
qCDebug(KCMKEYS) << "Adding shortcut" << index << shortcut;
Action &a = m_components[index.parent().row()].actions[index.row()];
a.activeShortcuts.insert(shortcut);
Q_EMIT dataChanged(index, index, {ActiveShortcutsRole, CustomShortcutsRole});
Q_EMIT dataChanged(index, index, {ActiveShortcutsRole, CustomShortcutsRole, IsDefaultRole});
Q_EMIT dataChanged(index.parent(), index.parent(), {IsDefaultRole});
}
void BaseModel::disableShortcut(const QModelIndex &index, const QKeySequence &shortcut)
......@@ -49,7 +50,8 @@ void BaseModel::disableShortcut(const QModelIndex &index, const QKeySequence &sh
qCDebug(KCMKEYS) << "Disabling shortcut" << index << shortcut;
Action &a = m_components[index.parent().row()].actions[index.row()];
a.activeShortcuts.remove(shortcut);
Q_EMIT dataChanged(index, index, {ActiveShortcutsRole, CustomShortcutsRole});
Q_EMIT dataChanged(index, index, {ActiveShortcutsRole, CustomShortcutsRole, IsDefaultRole});
Q_EMIT dataChanged(index.parent(), index.parent(), {IsDefaultRole});
}
......@@ -76,8 +78,9 @@ void BaseModel::defaults()
action_it->activeShortcuts = action_it->defaultShortcuts;
}
Q_EMIT dataChanged(index(0, 0, componentIndex), index(m_components[i].actions.size() - 1, 0, componentIndex),
{ActiveShortcutsRole, CustomShortcutsRole});
{ActiveShortcutsRole, CustomShortcutsRole, IsDefaultRole});
}
Q_EMIT dataChanged(index(0, 0), index(m_components.size() - 1, 0), {IsDefaultRole});
}
bool BaseModel::needsSave() const
......@@ -166,6 +169,8 @@ QVariant BaseModel::data(const QModelIndex &index, int role) const
auto shortcuts = action.activeShortcuts;
return QVariant::fromValue(shortcuts.subtract(action.defaultShortcuts));
}
case IsDefaultRole:
return action.activeShortcuts == action.defaultShortcuts;
}
return QVariant();
}
......@@ -183,6 +188,10 @@ QVariant BaseModel::data(const QModelIndex &index, int role) const
return component.checked;
case PendingDeletionRole:
return component.pendingDeletion;
case IsDefaultRole:
return std::all_of(component.actions.begin(), component.actions.end(), [] (const Action &action) {
return action.activeShortcuts == action.defaultShortcuts;
});
}
return QVariant();
}
......@@ -223,6 +232,7 @@ QHash<int, QByteArray> BaseModel::roleNames() const
{DefaultShortcutsRole, QByteArrayLiteral("defaultShortcuts")},
{CustomShortcutsRole, QByteArrayLiteral("customShortcuts")},
{CheckedRole, QByteArrayLiteral("checked")},
{PendingDeletionRole, QByteArrayLiteral("pendingDeletion")}
{PendingDeletionRole, QByteArrayLiteral("pendingDeletion")},
{IsDefaultRole, QByteArrayLiteral("isDefault")}
};
}
......@@ -59,7 +59,8 @@ public:
DefaultShortcutsRole,
CustomShortcutsRole,
CheckedRole,
PendingDeletionRole
PendingDeletionRole,
IsDefaultRole
};
Q_ENUM(Roles)
......
......@@ -22,7 +22,9 @@ import QtQuick.Controls 2.3 as QQC2
import org.kde.kirigami 2.10 as Kirigami
import org.kde.kquickcontrols 2.0
import org.kde.kcm 1.2 as KCM
import org.kde.kcm 1.5 as KCM
import org.kde.private.kcms.keys 2.0 as Private
Kirigami.AbstractListItem {
id: root
......@@ -66,6 +68,15 @@ Kirigami.AbstractListItem {
root.state == 'expanded' ? shortcutsList.selectedIndex = -1 : shortcutsList.selectedIndex = index
}
}
Rectangle {
id: defaultIndicator
radius: width * 0.5
implicitWidth: Kirigami.Units.largeSpacing
implicitHeight: Kirigami.Units.largeSpacing
visible: kcm.defaultsIndicatorsVisible
opacity: !model.isDefault
color: Kirigami.Theme.neutralTextColor
}
}
}
Loader {
......@@ -104,6 +115,9 @@ Kirigami.AbstractListItem {
originalIndex.model.disableShortcut(originalIndex, modelData)
}
}
KCM.SettingHighlighter {
highlight: !checked
}
}
}
}
......@@ -127,6 +141,9 @@ Kirigami.AbstractListItem {
onCaptureFinished: {
kcm.requestKeySequence(this, originalIndex, keySequence, modelData)
}
KCM.SettingHighlighter {
highlight: true
}
}
QQC2.Button {
icon.name: "edit-delete"
......
......@@ -150,6 +150,15 @@ KCM.SimpleKCM {
visible: exportActive
onToggled: model.checked = checked
}
Rectangle {
id: defaultIndicator
radius: width * 0.5
implicitWidth: Kirigami.Units.largeSpacing
implicitHeight: Kirigami.Units.largeSpacing
visible: kcm.defaultsIndicatorsVisible
opacity: !model.isDefault
color: Kirigami.Theme.neutralTextColor
}
}
}
section.property: "section"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment