Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 625bae01 authored by Marco Martin's avatar Marco Martin

preliminar for a new default systemsettings ui

sidebar mode: main categories are on a categorized sidebar on
the left, main content on the center area
parent df4b0260
......@@ -42,6 +42,7 @@ add_subdirectory(core)
add_subdirectory(app)
add_subdirectory(categories)
add_subdirectory(icons)
add_subdirectory(sidebar)
add_subdirectory(doc)
if(KF5KHtml_FOUND)
......
......@@ -108,6 +108,7 @@ void SettingsBase::initApplication()
for( int pluginsDone = 0; pluginsDone < nbPlugins ; ++pluginsDone ) {
KService::Ptr activeService = pluginObjects.at( pluginsDone );
QString error;
qWarning()<<"AAA"<<error<<activeService->library();
BaseMode * controller = activeService->createInstance<BaseMode>(this, QVariantList(), &error);
if( error.isEmpty() ) {
possibleViews.insert( activeService->library(), controller );
......@@ -388,6 +389,8 @@ void SettingsBase::changeToolBar( BaseMode::ToolBarItems toolbar )
quitBarActions << quitAction;
guiFactory()->plugActionList( this, "quit", quitBarActions );
}
toolBar()->setVisible(toolbar != BaseMode::NoItems);
}
void SettingsBase::changeAboutMenu( const KAboutData * menuAbout, QAction * menuItem, QString fallback )
......
......@@ -11,7 +11,7 @@
</entry>
<entry name="ActiveView" type="String">
<label>Internal name for the view used</label>
<default>icon_mode</default>
<default>systemsettings_sidebar_mode</default>
</entry>
</group>
</kcfg>
set( sidebar_mode_srcs
SidebarMode.cpp
CategoryDrawer.cpp
CategorizedView.cpp
)
add_library(systemsettings_sidebar_mode MODULE ${sidebar_mode_srcs})
target_link_libraries(systemsettings_sidebar_mode systemsettingsview
KF5::ItemViews
KF5::KCMUtils
KF5::I18n
KF5::KIOWidgets
KF5::Service
)
install( TARGETS systemsettings_sidebar_mode DESTINATION ${PLUGIN_INSTALL_DIR} )
install( FILES settings-sidebar-view.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
/***************************************************************************
* Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#include "CategorizedView.h"
#include <KFileItemDelegate>
#include <QScrollBar>
CategorizedView::CategorizedView( QWidget *parent )
: KCategorizedView( parent )
{
setWordWrap( true );
setViewportMargins(QMargins(0,0,-20,0));
}
void CategorizedView::setModel( QAbstractItemModel *model )
{
KCategorizedView::setModel( model );
}
void CategorizedView::wheelEvent(QWheelEvent* event)
{
// this is a workaround because scrolling by mouse wheel is broken in Qt list views for big items
// https://bugreports.qt-project.org/browse/QTBUG-7232
verticalScrollBar()->setSingleStep(10);
KCategorizedView::wheelEvent(event);
}
/***************************************************************************
* Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#ifndef CATEGORIZEDVIEW_H
#define CATEGORIZEDVIEW_H
#include <KCategorizedView>
class CategorizedView : public KCategorizedView
{
public:
CategorizedView( QWidget *parent = 0 );
virtual void setModel( QAbstractItemModel *model );
protected:
virtual void wheelEvent(QWheelEvent *);
};
#endif
/***************************************************************************
* Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#include "CategoryDrawer.h"
#include "MenuProxyModel.h"
#include <QPainter>
#include <QApplication>
#include <QStyleOption>
#include <QDebug>
CategoryDrawer::CategoryDrawer(KCategorizedView *view)
: KCategoryDrawer(view)
{
}
void CategoryDrawer::drawCategory(const QModelIndex &index,
int sortRole,
const QStyleOption &option,
QPainter *painter) const
{
Q_UNUSED( option )
Q_UNUSED( painter )
Q_UNUSED( sortRole )
painter->setRenderHint(QPainter::Antialiasing);
const QRect optRect = option.rect;
QFont font(QApplication::font());
font.setBold(true);
const QFontMetrics fontMetrics = QFontMetrics(font);
const int height = categoryHeight(index, option);
const QString category = index.model()->data(index, KCategorizedSortFilterProxyModel::CategoryDisplayRole).toString();
QRect textRect = QRect(option.rect.topLeft(), QSize(option.rect.width() - 2 - 3 - 3, height));
textRect.setLeft(textRect.left());
painter->save();
painter->setFont(font);
QColor penColor(option.palette.text().color());
penColor.setAlphaF(0.6);
painter->setPen(penColor);
if (index.row() > 0) {
textRect.setTop(textRect.top() + 10);
painter->save();
penColor.setAlphaF(0.3);
painter->fillRect(QRect(textRect.topLeft() + QPoint(0, -5), QSize(option.rect.width(),1)), penColor);
painter->restore();
}
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop, category);
painter->restore();
}
int CategoryDrawer::categoryHeight(const QModelIndex &index, const QStyleOption &option) const
{
Q_UNUSED( index );
Q_UNUSED( option );
QFont font(QApplication::font());
font.setBold(true);
const QFontMetrics fontMetrics = QFontMetrics(font);
if (index.row() == 0) return fontMetrics.height();
return fontMetrics.height() * 1.6 /* vertical spacing */;
}
int CategoryDrawer::leftMargin() const
{
return 0;
}
int CategoryDrawer::rightMargin() const
{
return 0;
}
/***************************************************************************
* Copyright (C) 2009 by Rafael Fernández López <ereslibre@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#ifndef CATEGORYDRAWER_H
#define CATEGORYDRAWER_H
#include <KCategoryDrawer>
class QPainter;
class QModelIndex;
class QStyleOption;
class CategoryDrawer : public KCategoryDrawer
{
Q_OBJECT
public:
CategoryDrawer(KCategorizedView *view);
virtual void drawCategory(const QModelIndex &index,
int sortRole,
const QStyleOption &option,
QPainter *painter) const;
virtual int categoryHeight(const QModelIndex &index, const QStyleOption &option) const;
virtual int leftMargin() const;
virtual int rightMargin() const;
};
#endif
/**************************************************************************
* Copyright (C) 2009 by Ben Cooksley <bcooksley@kde.org> *
* *
* This program is free software; you can redistribute it and/or *
* modify it under the terms of the GNU General Public License *
* as published by the Free Software Foundation; either version 2 *
* of the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA *
* 02110-1301, USA. *
***************************************************************************/
#include "SidebarMode.h"
#include "CategoryDrawer.h"
#include "CategorizedView.h"
#include "MenuItem.h"
#include "MenuModel.h"
#include "ModuleView.h"
#include "MenuProxyModel.h"
#include "BaseData.h"
#include <QHBoxLayout>
#include <QAction>
#include <KAboutData>
#include <KStandardAction>
#include <KFileItemDelegate>
#include <KLocalizedString>
#include <KIconLoader>
#include <KLineEdit>
#include <KServiceTypeTrader>
#include <QDebug>
K_PLUGIN_FACTORY( SidebarModeFactory, registerPlugin<SidebarMode>(); )
class SidebarMode::Private {
public:
Private() : categoryDrawer( 0 ), categoryView( 0 ), moduleView( 0 ) {}
virtual ~Private() {
delete aboutIcon;
}
KLineEdit * searchText;
KCategoryDrawer * categoryDrawer;
KCategorizedView * categoryView;
QWidget * mainWidget;
QHBoxLayout * mainLayout;
MenuProxyModel * proxyModel;
KAboutData * aboutIcon;
ModuleView * moduleView;
};
SidebarMode::SidebarMode( QObject *parent, const QVariantList& )
: BaseMode( parent )
, d( new Private() )
{
d->aboutIcon = new KAboutData( "SidebarView", i18n( "Sidebar View" ),
"1.0", i18n( "Provides a categorized sidebar for control modules." ),
KAboutLicense::GPL, i18n( "(c) 2017, Marco Martin" ) );
d->aboutIcon->addAuthor( i18n( "Marco Martin" ), i18n( "Author" ), "mart@kde.org" );
d->aboutIcon->addAuthor( i18n( "Ben Cooksley" ), i18n( "Author" ), "bcooksley@kde.org" );
d->aboutIcon->addAuthor( i18n( "Mathias Soeken" ), i18n( "Developer" ), "msoeken@informatik.uni-bremen.de" );
d->aboutIcon->setProgramIconName( "view-sidetree" );
}
SidebarMode::~SidebarMode()
{
delete d;
}
KAboutData * SidebarMode::aboutData()
{
return d->aboutIcon;
}
ModuleView * SidebarMode::moduleView() const
{
return d->moduleView;
}
QWidget * SidebarMode::mainWidget()
{
if( !d->categoryView ) {
initWidget();
}
return d->mainWidget;
}
QList<QAbstractItemView*> SidebarMode::views() const
{
QList<QAbstractItemView*> list;
list.append( d->categoryView );
return list;
}
void SidebarMode::initEvent()
{
MenuModel * model = new MenuModel( rootItem(), this );
foreach( MenuItem * child, rootItem()->children() ) {
model->addException( child );
}
d->proxyModel = new MenuProxyModel( this );
d->proxyModel->setCategorizedModel( true );
d->proxyModel->setSourceModel( model );
d->proxyModel->sort( 0 );
d->mainWidget = new QWidget();
d->mainLayout = new QHBoxLayout(d->mainWidget);
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::closeRequest, this, &SidebarMode::leaveModuleView );
d->categoryView = 0;
}
void SidebarMode::searchChanged( const QString& text )
{
d->proxyModel->setFilterRegExp( text );
if ( d->categoryView ) {
QAbstractItemModel *model = d->categoryView->model();
const int column = d->categoryView->modelColumn();
const QModelIndex root = d->categoryView->rootIndex();
for ( int i = 0; i < model->rowCount(); ++i ) {
const QModelIndex index = model->index( i, column, root );
if ( model->flags( index ) & Qt::ItemIsEnabled ) {
d->categoryView->scrollTo( index );
break;
}
}
}
}
void SidebarMode::changeModule( const QModelIndex& activeModule )
{
d->moduleView->closeModules();
d->moduleView->loadModule( activeModule );
}
void SidebarMode::moduleLoaded()
{
emit changeToolBarItems(BaseMode::NoItems);
}
void SidebarMode::initWidget()
{
// Create the widgets
QWidget *sidebar = new QWidget(d->mainWidget);
sidebar->setBackgroundRole(QPalette::Base);
sidebar->setFixedWidth(250);
sidebar->setAutoFillBackground(true);
QVBoxLayout *sidebarLayout = new QVBoxLayout(sidebar);
sidebarLayout->setSpacing(0);
sidebarLayout->setContentsMargins(0, 0, 0, 0);
// Initialise search
d->searchText = new KLineEdit( sidebar );
d->searchText->setClearButtonShown( true );
d->searchText->setPlaceholderText( i18nc( "Search through a list of control modules", "Search" ) );
d->searchText->setCompletionMode( KCompletion::CompletionPopup );
sidebarLayout->addWidget( d->searchText );
// Prepare the Base Data
MenuItem *rootModule = new MenuItem( true, 0 );
initMenuList(rootModule);
BaseData::instance()->setMenuItem( rootModule );
connect(d->searchText, &KLineEdit::textChanged, this, &SidebarMode::searchChanged);
d->searchText->completionObject()->setIgnoreCase( true );
d->searchText->completionObject()->setItems( BaseData::instance()->menuItem()->keywords() );
d->categoryView = new CategorizedView( sidebar );
sidebarLayout->addWidget( d->categoryView );
d->categoryDrawer = new CategoryDrawer(d->categoryView);
d->categoryView->setSelectionMode( QAbstractItemView::SingleSelection );
d->categoryView->setCategoryDrawer( d->categoryDrawer );
d->categoryView->setCategorySpacing(0);
d->categoryView->setIconSize(QSize(KIconLoader::SizeSmallMedium, KIconLoader::SizeSmallMedium));
d->categoryView->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
d->categoryView->setViewMode( QListView::ListMode );
d->categoryView->setMouseTracking( true );
d->categoryView->viewport()->setAttribute( Qt::WA_Hover );
//KFileItemDelegate *delegate = new KFileItemDelegate( d->categoryView );
//delegate->setWrapMode( QTextOption::WordWrap );
//d->categoryView->setItemDelegate( delegate );
d->categoryView->setFrameShape( QFrame::NoFrame );
d->categoryView->setModel( d->proxyModel );
connect( d->categoryView, &QAbstractItemView::activated,
this, &SidebarMode::changeModule );
d->mainLayout->addWidget( sidebar );
d->mainLayout->addWidget( d->moduleView );
emit changeToolBarItems(BaseMode::NoItems);
d->searchText->setFocus(Qt::OtherFocusReason);
}
void SidebarMode::initMenuList(MenuItem * parent)
{
KService::List categories = KServiceTypeTrader::self()->query("SystemSettingsCategory");
KService::List modules = KServiceTypeTrader::self()->query("KCModule", "[X-KDE-System-Settings-Parent-Category] != ''");
// look for any categories inside this level, and recurse into them
for (int i = 0; i < categories.size(); ++i) {
const KService::Ptr entry = categories.at(i);
const QString parentCategory = entry->property("X-KDE-System-Settings-Parent-Category").toString();
const QString parentCategory2 = entry->property("X-KDE-System-Settings-Parent-Category-V2").toString();
if ( parentCategory == parent->category() ||
// V2 entries must not be empty if they want to become a proper category.
( !parentCategory2.isEmpty() && parentCategory2 == parent->category() ) ) {
MenuItem * menuItem = new MenuItem(true, parent);
menuItem->setService( entry );
if( menuItem->category() == "lost-and-found" ) {
//lostFound = menuItem;
continue;
}
initMenuList( menuItem );
}
}
KService::List removeList;
// scan for any modules at this level and add them
for (int i = 0; i < modules.size(); ++i) {
const KService::Ptr entry = modules.at(i);
const QString category = entry->property("X-KDE-System-Settings-Parent-Category").toString();
const QString category2 = entry->property("X-KDE-System-Settings-Parent-Category-V2").toString();
if( !parent->category().isEmpty() && (category == parent->category() || category2 == parent->category()) ) {
// Add the module info to the menu
MenuItem * infoItem = new MenuItem(false, parent);
infoItem->setService( entry );
removeList.append( modules.at(i) );
}
}
for (int i = 0; i < removeList.size(); ++i) {
modules.removeOne( removeList.at(i) );
}
parent->sortChildrenByWeight();
}
void SidebarMode::leaveModuleView()
{
d->moduleView->closeModules(); // We have to force it here
}
void SidebarMode::giveFocus()
{
d->categoryView->setFocus();
}
#include "SidebarMode.moc"
/***************************************************************************
* Copyright (C) 2009 by Ben Cooksley <bcooksley@kde.org> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA *
***************************************************************************/
#ifndef SIDEBARMODE_H
#define SIDEBARMODE_H
#include "BaseMode.h"
class ModuleView;
class KAboutData;
class QModelIndex;
class QAbstractItemView;
class SidebarMode : public BaseMode
{
Q_OBJECT
public:
SidebarMode(QObject * parent, const QVariantList& );
~SidebarMode();
QWidget * mainWidget();
void initEvent();
void giveFocus();
void leaveModuleView();
KAboutData * aboutData();
ModuleView * moduleView() const;
protected:
QList<QAbstractItemView*> views() const;
public Q_SLOTS:
void searchChanged( const QString& text );
private Q_SLOTS:
void changeModule( const QModelIndex& activeModule );
void moduleLoaded();
void initWidget();
private:
void initMenuList(MenuItem * parent);
class Private;
Private *const d;
};
#endif
[Desktop Entry]
Icon=view-sidetree
Type=Service
X-KDE-ServiceTypes=SystemSettingsView
X-KDE-Library=systemsettings_sidebar_mode
X-KDE-Keywords=System Settings
X-KDE-Keywords[ar]=إعدادات النّظام
X-KDE-Keywords[bs]=Sistemske postavke
X-KDE-Keywords[ca]=Arranjament del sistema
X-KDE-Keywords[ca@valencia]=Arranjament del sistema
X-KDE-Keywords[cs]=Nastavení systému
X-KDE-Keywords[da]=Systemindstillinger
X-KDE-Keywords[de]=Systemeinstellungen
X-KDE-Keywords[el]=Ρυθμίσεις συστήματος
X-KDE-Keywords[en_GB]=System Settings
X-KDE-Keywords[eo]=Sistema agordo
X-KDE-Keywords[es]=Preferencias del sistema
X-KDE-Keywords[et]=Süsteemi seadistused
X-KDE-Keywords[eu]=Sistemaren ezarpenak
X-KDE-Keywords[fi]=järjestelmä, asetukset
X-KDE-Keywords[fr]=Configuration du système
X-KDE-Keywords[ga]=Socruithe an Chórais
X-KDE-Keywords[gl]=Configuración do sistema
X-KDE-Keywords[he]=הגדרות מערכת
X-KDE-Keywords[hu]=Rendszerbeállítások
X-KDE-Keywords[ia]=Preferentias de systema
X-KDE-Keywords[id]=Pengaturan Sistem
X-KDE-Keywords[is]=Kerfisstillingar
X-KDE-Keywords[it]=Impostazioni di sistema
X-KDE-Keywords[ja]=システム設定
X-KDE-Keywords[kk]=System Settings,Жүйе параметрлері
X-KDE-Keywords[km]=ការ​កំណត់​ប្រព័ន្ធ​
X-KDE-Keywords[ko]=시스템 설정
X-KDE-Keywords[lt]=Sistemos nuostatos
X-KDE-Keywords[lv]=Sistēmas iestatījumi
X-KDE-Keywords[mr]=प्रणाली संयोजना
X-KDE-Keywords[nb]=Systeminnstillinger
X-KDE-Keywords[nds]=Systeeminstellen
X-KDE-Keywords[nl]=Systeeminstellingen
X-KDE-Keywords[nn]=Systemoppsett
X-KDE-Keywords[pa]=ਸਿਸਟਮ ਸੈਟਿੰਗ
X-KDE-Keywords[pl]=Ustawienia systemowe
X-KDE-Keywords[pt]=Configuração do Sistema
X-KDE-Keywords[pt_BR]=Configurações do sistema
X-KDE-Keywords[ro]=Configurări de sistem
X-KDE-Keywords[ru]=Параметры системы
X-KDE-Keywords[sk]=Systémové nastavenia
X-KDE-Keywords[sl]=Sistemske nastavitve
X-KDE-Keywords[sr]=System Settings,Системске поставке
X-KDE-Keywords[sr@ijekavian]=System Settings,Системске поставке
X-KDE-Keywords[sr@ijekavianlatin]=System Settings,Sistemske postavke
X-KDE-Keywords[sr@latin]=System Settings,Sistemske postavke
X-KDE-Keywords[sv]=Systeminställningar
X-KDE-Keywords[tg]=Танзимотҳои система
X-KDE-Keywords[tr]=Sistem Ayarları
X-KDE-Keywords[ug]=سىستېما تەڭشەكلىرى
X-KDE-Keywords[uk]=система,параметри,System Settings,системні параметри
X-KDE-Keywords[vi]=Thiết lập hệ thống
X-KDE-Keywords[x-test]=xxSystem Settingsxx
X-KDE-Keywords[zh_CN]=System Settings,系统设置
X-KDE-Keywords[zh_TW]=System Settings
Name=Sidebar View
Comment=Categorized sidebar style
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