Commit 6cc205e3 authored by Benjamin Port's avatar Benjamin Port
Browse files

In sidebar mode show if a module is in default state or not

Summary:
{F8221036}

{F8221038}

Depends on D28460

Reviewers: #plasma, ervin, meven, crossi, hchain, #vdg, mart

Subscribers: mart, ngraham, abetts, filipf, The-Feren-OS-Dev, ndavis, broulik, plasma-devel

Tags: #plasma

Differential Revision: https://phabricator.kde.org/D28461
parent 19649460
......@@ -25,6 +25,7 @@
#include <QString>
#include <KCModuleInfo>
#include <KCMUtils/KCModuleLoader>
static bool childIsLessThan( MenuItem *left, MenuItem *right )
{
......@@ -43,6 +44,7 @@ public:
int weight;
KService::Ptr service;
KCModuleInfo item;
bool showDefaultIndicator;
};
MenuItem::MenuItem( bool isMenu, MenuItem * itsParent )
......@@ -50,6 +52,7 @@ MenuItem::MenuItem( bool isMenu, MenuItem * itsParent )
{
d->parent = itsParent;
d->menu = isMenu;
d->showDefaultIndicator = false;
if ( d->parent ) {
d->parent->children().append( this );
......@@ -140,6 +143,24 @@ void MenuItem::setService( const KService::Ptr& service )
}
}
bool MenuItem::showDefaultIndicator() const
{
return d->showDefaultIndicator;
}
void MenuItem::updateDefaultIndicator()
{
d->showDefaultIndicator = !KCModuleLoader::isDefaults(d->item);
if (menu()) {
for (auto child : children()) {
d->showDefaultIndicator |= child->showDefaultIndicator();
}
}
if (d->parent) {
d->parent->updateDefaultIndicator();
}
}
MenuItem *MenuItem::descendantForModule(const QString &moduleName)
{
if (d->service && d->service->desktopEntryName() == moduleName) {
......
......@@ -157,6 +157,10 @@ public:
MenuItem *descendantForModule(const QString &moduleName);
bool showDefaultIndicator() const;
void updateDefaultIndicator();
private:
class Private;
Private *const d;
......
......@@ -50,6 +50,7 @@ QHash<int, QByteArray> MenuModel::roleNames() const
QHash<int, QByteArray> names = QAbstractItemModel::roleNames();
names[DepthRole] = "DepthRole";
names[IsCategoryRole] = "IsCategoryRole";
names[DefaultIndicatorRole] = "showDefaultIndicator";
return names;
}
......@@ -131,6 +132,9 @@ QVariant MenuModel::data( const QModelIndex &index, int role ) const
case MenuModel::IsCategoryRole:
theData.setValue( mi->menu() );
break;
case MenuModel::DefaultIndicatorRole:
theData.setValue(mi->showDefaultIndicator());
break;
default:
break;
}
......
......@@ -56,7 +56,9 @@ public:
DepthRole,
IsCategoryRole
IsCategoryRole,
DefaultIndicatorRole
};
/**
......
......@@ -297,6 +297,7 @@ bool ModuleView::moduleSave(KCModuleProxy *module)
}
module->save();
emit moduleSaved();
return true;
}
......@@ -481,8 +482,8 @@ bool ModuleView::isResetVisible() const
void ModuleView::moduleShowDefaultsIndicators(bool show)
{
d->mDefaultsIndicatorsVisible = show;
KCModuleProxy * activeModule = d->mPages.value( d->mPageWidget->currentPage() );
if( activeModule ) {
KCModuleProxy * activeModule = d->mPages.value(d->mPageWidget->currentPage());
if (activeModule) {
activeModule->setDefaultsIndicatorsVisible(show);
}
}
......@@ -193,6 +193,11 @@ Q_SIGNALS:
*/
void moduleChanged( bool state );
/**
* Emitted after the currently active module was saved.
*/
void moduleSaved();
/**
* Emitted when the ModuleView is asked to close.\n
*/
......
......@@ -361,6 +361,7 @@ void SidebarMode::initEvent()
d->mainLayout->setContentsMargins(0, 0, 0, 0);
d->moduleView = new ModuleView( d->mainWidget );
connect( d->moduleView, &ModuleView::moduleChanged, this, &SidebarMode::moduleLoaded );
connect(d->moduleView, &ModuleView::moduleSaved, this, &SidebarMode::updateDefaults);
d->quickWidget = nullptr;
moduleView()->setFaceType(KPageView::Plain);
if (applicationMode() == BaseMode::InfoCenter) {
......@@ -566,6 +567,24 @@ void SidebarMode::moduleLoaded()
}
}
void SidebarMode::updateDefaults()
{
QModelIndex categoryIdx = d->categorizedModel->index(d->activeCategoryRow, 0);
auto item = categoryIdx.data(Qt::UserRole).value<MenuItem*>();
Q_ASSERT(item);
// If subcategory exist update from subcategory
if (!item->children().isEmpty()) {
item = item->child(d->activeSubCategoryRow);
}
item->updateDefaultIndicator();
auto sourceIdx = d->categorizedModel->mapToSource(categoryIdx);
emit d->model->dataChanged(sourceIdx, sourceIdx);
auto subCateogryIdx = d->subCategoryModel->index(d->activeSubCategoryRow, 0);
emit d->subCategoryModel->dataChanged(subCateogryIdx, subCateogryIdx);
}
int SidebarMode::activeSearchRow() const
{
return d->activeSearchRow;
......@@ -611,6 +630,34 @@ void SidebarMode::toggleDefaultsIndicatorsVisibility()
{
d->m_defaultsIndicatorsVisible = !d->m_defaultsIndicatorsVisible;
d->moduleView->moduleShowDefaultsIndicators(d->m_defaultsIndicatorsVisible);
if (d->m_defaultsIndicatorsVisible) {
for (int i = 0; i < d->flatModel->rowCount(); ++i) {
QModelIndex idx = d->flatModel->index(i, 0);
auto item = idx.data(MenuModel::MenuItemRole).value<MenuItem *>();
if (item->menu()) {
continue;
}
const bool showIndicator = item->showDefaultIndicator();
item->updateDefaultIndicator();
if (showIndicator == item->showDefaultIndicator()) {
continue;
}
auto itemIdx = d->model->indexForItem(item);
emit d->model->dataChanged(itemIdx, itemIdx);
MenuItem *parent = item->parent();
while (parent) {
auto parentIdx = d->model->indexForItem(parent);
if (parentIdx.isValid()) {
emit d->model->dataChanged(parentIdx, parentIdx);
parent = parent->parent();
} else {
parent = nullptr;
}
}
}
}
emit defaultsIndicatorsVisibleChanged();
}
......
......@@ -124,6 +124,7 @@ protected:
private Q_SLOTS:
void moduleLoaded();
void updateDefaults();
void initWidget();
Q_SIGNALS:
......
......@@ -178,23 +178,7 @@ Kirigami.ScrollablePage {
highlighted: categoryView.currentIndex == index
Keys.onEnterPressed: clicked();
Keys.onReturnPressed: clicked();
contentItem: RowLayout {
id: layout
spacing: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
Kirigami.Icon {
id: icon
source: model.decoration
Layout.preferredHeight: Layout.preferredWidth
Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
Layout.leftMargin: (model.DepthRole-1) * (icon.width + layout.spacing)
}
QQC2.Label {
Layout.fillWidth: true
text: model.display
color: (delegate.highlighted || delegate.checked || (delegate.pressed && delegate.supportsMouseEvents)) ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
elide: Text.ElideRight
}
}
contentItem: CategoryItem {}
}
}
......@@ -210,7 +194,7 @@ Kirigami.ScrollablePage {
margins: Kirigami.Units.smallSpacing
}
text: i18nc("Action to show indicators for settings with custom data", "Highlight Changed Settings")
icon.name: "tools"
icon.name: "draw-highlight"
onClicked: systemsettings.toggleDefaultsIndicatorsVisibility()
checkable: true
checked: systemsettings.defaultsIndicatorsVisible
......
import QtQuick 2.5
import QtQuick.Controls 2.5 as QQC2
import QtQuick.Layouts 1.1
import org.kde.kirigami 2.10 as Kirigami
RowLayout {
id: layout
spacing: Kirigami.Settings.tabletMode ? Kirigami.Units.largeSpacing : Kirigami.Units.smallSpacing
Kirigami.Icon {
id: icon
source: model.decoration
Layout.preferredHeight: Layout.preferredWidth
Layout.preferredWidth: Kirigami.Units.iconSizes.smallMedium
Layout.leftMargin: model.DepthRole > 1 ? (model.DepthRole - 1) * (Kirigami.Units.iconSizes.smallMedium + layout.spacing) : 0
}
QQC2.Label {
Layout.fillWidth: true
text: model.display
color: (delegate.highlighted || delegate.checked || (delegate.pressed && delegate.supportsMouseEvents)) ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
elide: Text.ElideRight
}
Rectangle {
id: defaultIndicator
radius: width * 0.5
implicitWidth: Kirigami.Units.largeSpacing
implicitHeight: Kirigami.Units.largeSpacing
visible: model.showDefaultIndicator && systemsettings.defaultsIndicatorsVisible
Kirigami.Theme.colorSet: Kirigami.Theme.View
color: Kirigami.Theme.neutralTextColor
}
}
......@@ -155,10 +155,8 @@ Kirigami.ScrollablePage {
}
}
delegate: Kirigami.BasicListItem {
delegate: Kirigami.AbstractListItem {
id: delegate
icon: model.decoration
label: model.display
onClicked: {
systemsettings.loadModule(subCategoryView.model.index(index, 0));
}
......@@ -177,6 +175,7 @@ Kirigami.ScrollablePage {
highlighted: systemsettings.activeSubCategoryRow == index
Keys.onEnterPressed: clicked();
Keys.onReturnPressed: clicked();
contentItem: CategoryItem {}
}
}
......@@ -193,7 +192,7 @@ Kirigami.ScrollablePage {
margins: Kirigami.Units.smallSpacing
}
text: i18nc("Action to show indicators for settings with custom data", "Highlight Changed Settings")
icon.name: "tools"
icon.name: "draw-highlight"
onClicked: systemsettings.toggleDefaultsIndicatorsVisibility()
checkable: true
checked: systemsettings.defaultsIndicatorsVisible
......
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