Commit b41df9ad authored by Marco Martin's avatar Marco Martin

tart port to QML

parent 8285db38
......@@ -17,7 +17,7 @@ include(GenerateExportHeader)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS
Widgets
Widgets Quick Qml QuickWidgets
)
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
......@@ -33,6 +33,7 @@ find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS
DBusAddons
Config
DocTools
Package
OPTIONAL_COMPONENTS
KHtml
QUIET
......
......@@ -32,6 +32,13 @@ MenuProxyModel::MenuProxyModel( QObject * parent )
setFilterCaseSensitivity( Qt::CaseInsensitive );
}
QHash<int, QByteArray> MenuProxyModel::roleNames() const
{
QHash<int, QByteArray> names = KCategorizedSortFilterProxyModel::roleNames();
names[KCategorizedSortFilterProxyModel::CategoryDisplayRole] = "categoryDisplayRole";
return names;
}
bool MenuProxyModel::lessThan( const QModelIndex &left, const QModelIndex &right ) const
{
if( isCategorizedModel() ) {
......@@ -110,9 +117,18 @@ Qt::ItemFlags MenuProxyModel::flags( const QModelIndex &index ) const
void MenuProxyModel::setFilterRegExp ( const QString & pattern )
{
if (pattern == filterRegExp()) {
return;
}
emit layoutAboutToBeChanged ();
KCategorizedSortFilterProxyModel::setFilterRegExp( pattern );
emit layoutChanged ();
emit filterRegExpChanged ();
}
QString MenuProxyModel::filterRegExp() const
{
return KCategorizedSortFilterProxyModel::filterRegExp().pattern();
}
void MenuProxyModel::setFilterRegExp ( const QRegExp & regExp )
......
......@@ -40,6 +40,8 @@ class SYSTEMSETTINGSVIEW_EXPORT MenuProxyModel : public KCategorizedSortFilterPr
{
Q_OBJECT
Q_PROPERTY(QString filterRegExp READ filterRegExp WRITE setFilterRegExp NOTIFY filterRegExpChanged)
public:
/**
* Constructs a MenuProxyModel with the specified parent.
......@@ -48,6 +50,8 @@ public:
*/
MenuProxyModel( QObject *parent = 0 );
QHash<int, QByteArray> roleNames() const;
/**
* Please see the Qt QSortFilterProxyModel documentation for further information.\n
* Provides information on whether or not the QModelIndex specified by left is below right.
......@@ -99,6 +103,8 @@ public:
*/
void setFilterRegExp ( const QString & pattern );
QString filterRegExp() const;
/**
* makes the filter highlight matching entries instead of hiding them
*/
......@@ -109,6 +115,9 @@ public:
*/
bool filterHighlightsEntries() const;
Q_SIGNALS:
void filterRegExpChanged();
private:
bool m_filterHighlightsEntries : 1;
};
......
......@@ -14,8 +14,13 @@ target_link_libraries(systemsettings_sidebar_mode systemsettingsview
KF5::KIOWidgets
KF5::Service
KF5::XmlGui
KF5::Package
Qt5::Qml
Qt5::Quick
Qt5::QuickWidgets
)
install( TARGETS systemsettings_sidebar_mode DESTINATION ${PLUGIN_INSTALL_DIR} )
install( FILES settings-sidebar-view.desktop DESTINATION ${SERVICES_INSTALL_DIR} )
install(DIRECTORY package/ DESTINATION ${KDE_INSTALL_DATAROOTDIR}/kpackage/genericqml/org.kde.systemsettings.sidebar)
This diff is collapsed.
......@@ -26,11 +26,18 @@ class ModuleView;
class KAboutData;
class QModelIndex;
class QAbstractItemView;
class QAbstractItemModel;
class SidebarMode : public BaseMode
{
Q_OBJECT
Q_PROPERTY(QAbstractItemModel *categoryModel READ categoryModel CONSTANT)
Q_PROPERTY(QAbstractItemModel *subCategoryModel READ subCategoryModel CONSTANT)
Q_PROPERTY(QList<QObject *> globalActions READ globalActions CONSTANT)
Q_PROPERTY(int activeCategory READ activeCategory WRITE setActiveCategory NOTIFY activeCategoryChanged)
Q_PROPERTY(int activeSubCategory READ activeSubCategory WRITE setActiveSubCategory NOTIFY activeSubCategoryChanged)
public:
SidebarMode(QObject * parent, const QVariantList& );
~SidebarMode();
......@@ -40,18 +47,28 @@ public:
void leaveModuleView();
KAboutData * aboutData();
ModuleView * moduleView() const;
QAbstractItemModel *categoryModel() const;
QAbstractItemModel *subCategoryModel() const;
QList<QObject *> globalActions() const;
int activeCategory() const;
void setActiveCategory(int cat);
int activeSubCategory() const;
void setActiveSubCategory(int cat);
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();
Q_SIGNALS:
void activeCategoryChanged();
void activeSubCategoryChanged();
private:
void initMenuList(MenuItem * parent);
class Private;
......
/*
Copyright (c) 2017 Marco Martin <mart@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
import QtQuick 2.1
import QtQuick.Layouts 1.1
import QtQuick.Controls 1.0 as QtControls
import QtQuick.Controls 2.0 as QtControls2
import org.kde.kirigami 2.0 as Kirigami
Kirigami.PageRow {
id: root
initialPage: mainColumn
Kirigami.ScrollablePage {
id: mainColumn
header: RowLayout {
QtControls.ToolButton {
iconName: "application-menu"
menu: QtControls.Menu {
id: globalMenu
Instantiator {
model: systemsettings.globalActions
QtControls.MenuItem {
text: modelData.text
property QtObject action: modelData
onTriggered: action.trigger();
}
onObjectAdded: globalMenu.insertItem(index, object)
onObjectRemoved: globalMenu.removeItem(object)
}
}
}
QtControls.TextField {
Layout.fillWidth: true
placeholderText: i18n("Search...")
onTextChanged: systemsettings.categoryModel.filterRegExp = text
}
}
background: Rectangle {
color: Kirigami.Theme.viewBackgroundColor
}
ListView {
id: categoryView
anchors.fill: parent
model: systemsettings.categoryModel
currentIndex: systemsettings.activeCategory
section {
property: "categoryDisplayRole"
delegate: Item {
width: categoryView.width
height: sectionLabel.height * 1.6
Kirigami.Separator {
anchors {
left: parent.left
right: parent.right
bottom: sectionLabel.top
}
}
Kirigami.Label {
anchors {
bottom: parent.bottom
left: parent.left
leftMargin: Kirigami.Units.smallSpacing
}
id: sectionLabel
text: section
opacity: 0.3
//FIXME: kirigami bug, why?
Component.onCompleted: font.bold = true
}
}
}
delegate: Kirigami.BasicListItem {
icon: model.decoration
label: model.display
separatorVisible: false
onClicked: systemsettings.activeCategory = index
checked: systemsettings.activeCategory == index
}
}
}
Kirigami.ScrollablePage {
id: subCategoryColumn
header: RowLayout {
QtControls.ToolButton {
iconName: "go-previous"
onClicked: root.currentIndex = 0;
}
Kirigami.Heading {
text: "Subcategory"
}
}
background: Rectangle {
color: Kirigami.Theme.viewBackgroundColor
}
ListView {
id: subCategoryView
anchors.fill: parent
model: systemsettings.subCategoryModel
currentIndex: systemsettings.activeSubCategory
onCountChanged: {
if (count > 1) {
root.push(subCategoryColumn);
root.currentIndex = 1;
} else {
root.pop(mainColumn)
}
}
delegate: Kirigami.BasicListItem {
icon: model.decoration
label: model.display
separatorVisible: false
onClicked: systemsettings.activeSubCategory = index
checked: systemsettings.activeSubCategory == index
}
}
}
}
[Desktop Entry]
Name=Sidebar View
Comment=Categorized sidebar style
Icon=view-sidetree
Encoding=UTF-8
Keywords=
Type=Service
X-KDE-ParentApp=
X-KDE-PluginInfo-Author=Marco Martin
X-KDE-PluginInfo-Email=mart@kde.org
X-KDE-PluginInfo-License=GPL
X-KDE-PluginInfo-Name=org.kde.systemsettings.sidebar
X-KDE-PluginInfo-Version=
X-KDE-PluginInfo-Website=
X-KDE-ServiceTypes=KPackage/GenericQML
X-Plasma-MainScript=ui/main.qml
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