Commit 12e0376f authored by Cyril Rossi's avatar Cyril Rossi Committed by Nate Graham
Browse files

KCM KWin VirtualDesktop highlight settings

Currently the highlight is only for the items. KCModuleData will come in another MR.
This is more simple implementation than the one I previously made.

Some default value are hardcoded in the KCM such as Rows count (2) and the number
of virtual desktop, on revert to default, it keeps only the first one.
parent c5e91b94
......@@ -19,13 +19,14 @@ AnimationsModel::AnimationsModel(QObject *parent)
{
connect(this, &EffectsModel::loaded, this,
[this] {
setEnabled(modelCurrentEnabled());
setCurrentIndex(modelCurrentIndex());
setAnimationEnabled(modelAnimationEnabled());
setAnimationIndex(modelAnimationIndex());
loadDefaults();
}
);
connect(this, &AnimationsModel::currentIndexChanged, this,
connect(this, &AnimationsModel::animationIndexChanged, this,
[this] {
const QModelIndex index_ = index(m_currentIndex, 0);
const QModelIndex index_ = index(m_animationIndex, 0);
if (!index_.isValid()) {
return;
}
......@@ -38,29 +39,29 @@ AnimationsModel::AnimationsModel(QObject *parent)
);
}
bool AnimationsModel::enabled() const
bool AnimationsModel::animationEnabled() const
{
return m_enabled;
return m_animationEnabled;
}
void AnimationsModel::setEnabled(bool enabled)
void AnimationsModel::setAnimationEnabled(bool enabled)
{
if (m_enabled != enabled) {
m_enabled = enabled;
emit enabledChanged();
if (m_animationEnabled != enabled) {
m_animationEnabled = enabled;
emit animationEnabledChanged();
}
}
int AnimationsModel::currentIndex() const
int AnimationsModel::animationIndex() const
{
return m_currentIndex;
return m_animationIndex;
}
void AnimationsModel::setCurrentIndex(int index)
void AnimationsModel::setAnimationIndex(int index)
{
if (m_currentIndex != index) {
m_currentIndex = index;
emit currentIndexChanged();
if (m_animationIndex != index) {
m_animationIndex = index;
emit animationIndexChanged();
}
}
......@@ -69,6 +70,16 @@ bool AnimationsModel::currentConfigurable() const
return m_currentConfigurable;
}
bool AnimationsModel::defaultAnimationEnabled() const
{
return m_defaultAnimationEnabled;
}
int AnimationsModel::defaultAnimationIndex() const
{
return m_defaultAnimationIndex;
}
bool AnimationsModel::shouldStore(const EffectData &data) const
{
return data.untranslatedCategory.contains(
......@@ -80,7 +91,21 @@ EffectsModel::Status AnimationsModel::status(int row) const
return Status(data(index(row, 0), static_cast<int>(StatusRole)).toInt());
}
bool AnimationsModel::modelCurrentEnabled() const
void AnimationsModel::loadDefaults()
{
for (int i = 0; i < rowCount(); ++i) {
const QModelIndex rowIndex = index(i, 0);
if (rowIndex.data(EnabledByDefaultRole).toBool()) {
m_defaultAnimationEnabled = true;
m_defaultAnimationIndex = i;
emit defaultAnimationEnabledChanged();
emit defaultAnimationIndexChanged();
break;
}
}
}
bool AnimationsModel::modelAnimationEnabled() const
{
for (int i = 0; i < rowCount(); ++i) {
if (status(i) != Status::Disabled) {
......@@ -91,7 +116,7 @@ bool AnimationsModel::modelCurrentEnabled() const
return false;
}
int AnimationsModel::modelCurrentIndex() const
int AnimationsModel::modelAnimationIndex() const
{
for (int i = 0; i < rowCount(); ++i) {
if (status(i) != Status::Disabled) {
......@@ -110,7 +135,7 @@ void AnimationsModel::load()
void AnimationsModel::save()
{
for (int i = 0; i < rowCount(); ++i) {
const auto status = (m_enabled && i == m_currentIndex)
const auto status = (m_animationEnabled && i == m_animationIndex)
? EffectsModel::Status::Enabled
: EffectsModel::Status::Disabled;
updateEffectStatus(index(i, 0), status);
......@@ -122,14 +147,14 @@ void AnimationsModel::save()
void AnimationsModel::defaults()
{
EffectsModel::defaults();
setEnabled(modelCurrentEnabled());
setCurrentIndex(modelCurrentIndex());
setAnimationEnabled(modelAnimationEnabled());
setAnimationIndex(modelAnimationIndex());
}
bool AnimationsModel::isDefaults() const
{
// effect at m_currentIndex index may not be the current saved selected effect
const bool enabledByDefault = index(m_currentIndex, 0).data(EnabledByDefaultRole).toBool();
// effect at m_animationIndex index may not be the current saved selected effect
const bool enabledByDefault = index(m_animationIndex, 0).data(EnabledByDefaultRole).toBool();
return enabledByDefault;
}
......@@ -143,7 +168,7 @@ bool AnimationsModel::needsSave() const
index_.data(ServiceNameRole).toString() + QLatin1String("Enabled"),
index_.data(EnabledByDefaultRole).toBool()
);
const bool enabled = (m_enabled && i == m_currentIndex);
const bool enabled = (m_animationEnabled && i == m_animationIndex);
if (enabled != enabledConfig) {
return true;
......
......@@ -17,21 +17,26 @@ namespace KWin
class AnimationsModel : public EffectsModel
{
Q_OBJECT
Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
Q_PROPERTY(int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged)
Q_PROPERTY(bool animationEnabled READ animationEnabled WRITE setAnimationEnabled NOTIFY animationEnabledChanged)
Q_PROPERTY(int animationIndex READ animationIndex WRITE setAnimationIndex NOTIFY animationIndexChanged)
Q_PROPERTY(bool currentConfigurable READ currentConfigurable NOTIFY currentConfigurableChanged)
Q_PROPERTY(bool defaultAnimationEnabled READ defaultAnimationEnabled NOTIFY defaultAnimationEnabledChanged)
Q_PROPERTY(int defaultAnimationIndex READ defaultAnimationIndex NOTIFY defaultAnimationIndexChanged)
public:
explicit AnimationsModel(QObject *parent = nullptr);
bool enabled() const;
void setEnabled(bool enabled);
bool animationEnabled() const;
void setAnimationEnabled(bool enabled);
int currentIndex() const;
void setCurrentIndex(int index);
int animationIndex() const;
void setAnimationIndex(int index);
bool currentConfigurable() const;
bool defaultAnimationEnabled() const;
int defaultAnimationIndex() const;
void load();
void save();
void defaults();
......@@ -39,20 +44,25 @@ public:
bool needsSave() const;
Q_SIGNALS:
void enabledChanged();
void currentIndexChanged();
void animationEnabledChanged();
void animationIndexChanged();
void currentConfigurableChanged();
void defaultAnimationEnabledChanged();
void defaultAnimationIndexChanged();
protected:
bool shouldStore(const EffectData &data) const override;
private:
Status status(int row) const;
bool modelCurrentEnabled() const;
int modelCurrentIndex() const;
bool m_enabled = false;
int m_currentIndex = -1;
void loadDefaults();
bool modelAnimationEnabled() const;
int modelAnimationIndex() const;
bool m_animationEnabled = false;
bool m_defaultAnimationEnabled = false;
int m_animationIndex = -1;
int m_defaultAnimationIndex = -1;
bool m_currentConfigurable = false;
Q_DISABLE_COPY(AnimationsModel)
......
......@@ -121,6 +121,9 @@ QVariant DesktopsModel::data(const QModelIndex &index, int role) const
return (index.row() / perRow) + 1;
} else if (role == IsDefault) {
// According to defaults(), first desktop is default
return index.row() == 0;
}
return QVariant();
......@@ -176,6 +179,11 @@ void DesktopsModel::setRows(int rows)
}
}
int DesktopsModel::desktopCount() const
{
return rowCount();
}
void DesktopsModel::createDesktop(const QString &name)
{
if (!ready()) {
......@@ -190,6 +198,7 @@ void DesktopsModel::createDesktop(const QString &name)
m_names[dummyId] = name;
endInsertRows();
emit desktopCountChanged();
updateModifiedState();
}
......@@ -208,6 +217,7 @@ void DesktopsModel::removeDesktop(const QString &id)
m_names.remove(id);
endRemoveRows();
emit desktopCountChanged();
updateModifiedState();
}
......@@ -384,7 +394,7 @@ void DesktopsModel::defaults()
const auto desktop = m_desktops.takeLast();
m_names.remove(desktop);
}
m_rows = 2;
setRows(2);
endResetModel();
......@@ -397,7 +407,7 @@ void DesktopsModel::load()
beginResetModel();
m_desktops = m_serverSideDesktops;
m_names = m_serverSideNames;
m_rows = m_serverSideRows;
setRows(m_serverSideRows);
endResetModel();
m_userModified = true;
......
......@@ -51,11 +51,13 @@ class DesktopsModel : public QAbstractListModel
Q_PROPERTY(bool userModified READ userModified NOTIFY userModifiedChanged)
Q_PROPERTY(bool serverModified READ serverModified NOTIFY serverModifiedChanged)
Q_PROPERTY(int rows READ rows WRITE setRows NOTIFY rowsChanged)
Q_PROPERTY(int desktopCount READ desktopCount NOTIFY desktopCountChanged)
public:
enum AdditionalRoles {
Id = Qt::UserRole + 1,
DesktopRow
DesktopRow,
IsDefault,
};
Q_ENUM(AdditionalRoles)
......@@ -76,6 +78,8 @@ public:
int rows() const;
void setRows(int rows);
int desktopCount() const;
Q_INVOKABLE void createDesktop(const QString &name);
Q_INVOKABLE void removeDesktop(const QString &id);
Q_INVOKABLE void setDesktopName(const QString &id, const QString &name);
......@@ -93,6 +97,7 @@ Q_SIGNALS:
void userModifiedChanged() const;
void serverModifiedChanged() const;
void rowsChanged() const;
void desktopCountChanged();
protected Q_SLOTS:
void reset();
......
......@@ -8,13 +8,13 @@ import QtQuick 2.5
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.1
import org.kde.kcm 1.2
import org.kde.kcm 1.5 as KCM
import org.kde.kirigami 2.10 as Kirigami
ScrollViewKCM {
KCM.ScrollViewKCM {
id: root
ConfigModule.quickHelp: i18n("This module lets you configure the navigation, number and layout of virtual desktops.")
KCM.ConfigModule.quickHelp: i18n("This module lets you configure the navigation, number and layout of virtual desktops.")
Connections {
target: kcm.desktopsModel
......@@ -49,7 +49,7 @@ ScrollViewKCM {
Layout.alignment: Qt.AlignVCenter
text: model.display
text: model ? model.display : ""
readOnly: true
......@@ -58,11 +58,21 @@ ScrollViewKCM {
Qt.callLater(kcm.desktopsModel.setDesktopName, model.Id, text);
}
}
Rectangle {
id: defaultIndicator
radius: width * 0.5
implicitWidth: Kirigami.Units.largeSpacing
implicitHeight: Kirigami.Units.largeSpacing
visible: kcm.defaultsIndicatorsVisible
opacity: model ? !model.IsDefault : 0.0
color: Kirigami.Theme.neutralTextColor
}
}
actions: [
Kirigami.Action {
enabled: !model.IsMissing
enabled: model && !model.IsMissing
iconName: "edit-rename"
tooltip: i18nc("@info:tooltip", "Rename")
onTriggered: {
......@@ -72,7 +82,7 @@ ScrollViewKCM {
}
},
Kirigami.Action {
enabled: !model.IsMissing
enabled: model && !model.IsMissing
iconName: "edit-delete-remove"
tooltip: i18nc("@info:tooltip", "Remove")
onTriggered: kcm.desktopsModel.removeDesktop(model.Id)
......@@ -92,7 +102,7 @@ ScrollViewKCM {
text: kcm.desktopsModel.error
visible: kcm.desktopsModel.error != ""
visible: kcm.desktopsModel.error !== ""
}
Kirigami.InlineMessage {
......@@ -143,11 +153,16 @@ ScrollViewKCM {
from: 1
to: 20
editable: true
value: kcm.desktopsModel.rows
textFromValue: function(value, locale) { return i18np("1 Row", "%1 Rows", value)}
valueFromText: function(text, locale) { return parseInt(text, 10); }
onValueModified: kcm.desktopsModel.rows = value
KCM.SettingHighlighter {
highlight: kcm.desktopsModel.rows !== 2
}
}
}
......@@ -162,6 +177,11 @@ ScrollViewKCM {
enabled: !kcm.virtualDesktopsSettings.isImmutable("rollOverDesktops")
checked: kcm.virtualDesktopsSettings.rollOverDesktops
onToggled: kcm.virtualDesktopsSettings.rollOverDesktops = checked
KCM.SettingStateBinding {
configObject: kcm.virtualDesktopsSettings
settingName: "rollOverDesktops"
}
}
RowLayout {
......@@ -175,9 +195,13 @@ ScrollViewKCM {
text: i18n("Show animation when switching:")
checked: kcm.animationsModel.enabled
checked: kcm.animationsModel.animationEnabled
onToggled: kcm.animationsModel.animationEnabled = checked
onToggled: kcm.animationsModel.enabled = checked
KCM.SettingHighlighter {
highlight: kcm.animationsModel.animationEnabled !== kcm.animationsModel.defaultAnimationEnabled
}
}
QQC2.ComboBox {
......@@ -185,8 +209,12 @@ ScrollViewKCM {
model: kcm.animationsModel
textRole: "NameRole"
currentIndex: kcm.animationsModel.currentIndex
onActivated: kcm.animationsModel.currentIndex = currentIndex
currentIndex: kcm.animationsModel.animationIndex
onActivated: kcm.animationsModel.animationIndex = currentIndex
KCM.SettingHighlighter {
highlight: kcm.animationsModel.animationIndex !== kcm.animationsModel.defaultAnimationIndex
}
}
QQC2.Button {
......@@ -218,18 +246,19 @@ ScrollViewKCM {
text: i18n("Show on-screen display when switching:")
enabled: !kcm.virtualDesktopsSettings.isImmutable("desktopChangeOsdEnabled")
checked: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled
onToggled: kcm.virtualDesktopsSettings.desktopChangeOsdEnabled = checked
KCM.SettingStateBinding {
configObject: kcm.virtualDesktopsSettings
settingName: "desktopChangeOsdEnabled"
}
}
QQC2.SpinBox {
id: osdDuration
enabled: osdEnabled.checked && !kcm.virtualDesktopsSettings.isImmutable("popupHideDelay")
from: 0
to: 10000
stepSize: 100
......@@ -239,6 +268,12 @@ ScrollViewKCM {
value: kcm.virtualDesktopsSettings.popupHideDelay
onValueModified: kcm.virtualDesktopsSettings.popupHideDelay = value
KCM.SettingStateBinding {
configObject: kcm.virtualDesktopsSettings
settingName: "popupHideDelay"
extraEnabledConditions: osdEnabled.checked
}
}
}
......@@ -251,10 +286,15 @@ ScrollViewKCM {
QQC2.CheckBox {
id: osdTextOnly
enabled: osdEnabled.checked && !kcm.virtualDesktopsSettings.isImmutable("textOnly")
text: i18n("Show desktop layout indicators")
checked: !kcm.virtualDesktopsSettings.textOnly
onToggled: kcm.virtualDesktopsSettings.textOnly = !checked
KCM.SettingStateBinding {
configObject: kcm.virtualDesktopsSettings
settingName: "textOnly"
extraEnabledConditions: osdEnabled.checked
}
}
}
}
......
......@@ -38,9 +38,9 @@ VirtualDesktops::VirtualDesktops(QObject *parent, const QVariantList &args)
QObject::connect(m_desktopsModel, &KWin::DesktopsModel::userModifiedChanged,
this, &VirtualDesktops::settingsChanged);
connect(m_animationsModel, &AnimationsModel::enabledChanged,
connect(m_animationsModel, &AnimationsModel::animationEnabledChanged,
this, &VirtualDesktops::settingsChanged);
connect(m_animationsModel, &AnimationsModel::currentIndexChanged,
connect(m_animationsModel, &AnimationsModel::animationIndexChanged,
this, &VirtualDesktops::settingsChanged);
}
......@@ -98,7 +98,7 @@ bool VirtualDesktops::isDefaults() const
void VirtualDesktops::configureAnimation()
{
const QModelIndex index = m_animationsModel->index(m_animationsModel->currentIndex(), 0);
const QModelIndex index = m_animationsModel->index(m_animationsModel->animationIndex(), 0);
if (!index.isValid()) {
return;
}
......@@ -108,7 +108,7 @@ void VirtualDesktops::configureAnimation()
void VirtualDesktops::showAboutAnimation()
{
const QModelIndex index = m_animationsModel->index(m_animationsModel->currentIndex(), 0);
const QModelIndex index = m_animationsModel->index(m_animationsModel->animationIndex(), 0);
if (!index.isValid()) {
return;
}
......
Supports Markdown
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