Commit d188b4ee authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

improve plugins

parent f8cf4570
Pipeline #27926 failed with stage
in 60 minutes and 1 second
......@@ -2,6 +2,7 @@ set(messageviewer_folderconfiguresettingsplugin_SRCS
folderconfiguresettingsplugin.cpp
folderconfiguresettingsdialog.cpp
folderconfiguresettingswidget.cpp
foldersettingfilterproxymodel.cpp
)
kcoreaddons_add_plugin(messageviewer_folderconfiguresettingsplugin JSON messageviewer_folderconfiguresettingsplugin.json SOURCES
......
......@@ -18,12 +18,30 @@
*/
#include "folderconfiguresettingswidget.h"
#include <KCheckableProxyModel>
#include <QHBoxLayout>
#include <MailCommon/FolderTreeWidget>
#include <MailCommon/FolderTreeView>
FolderConfigureSettingsWidget::FolderConfigureSettingsWidget(QWidget *parent)
: QWidget(parent)
{
QHBoxLayout *mainLayout = new QHBoxLayout(this);
mainLayout->setContentsMargins(0, 0, 0, 0);
auto ftw = new MailCommon::FolderTreeWidget(this, nullptr,
MailCommon::FolderTreeWidget::TreeViewOptions(MailCommon::FolderTreeWidget::UseDistinctSelectionModel
|MailCommon::FolderTreeWidget::HideStatistics
|MailCommon::FolderTreeWidget::HideHeaderViewMenu));
ftw->folderTreeView()->setDragEnabled(false);
auto ftv = ftw->folderTreeView();
auto sourceModel = ftv->model();
auto selectionModel = ftw->selectionModel();
auto checkable = new KCheckableProxyModel(this);
checkable->setSourceModel(sourceModel);
checkable->setSelectionModel(selectionModel);
mainLayout->addWidget(ftw);
}
FolderConfigureSettingsWidget::~FolderConfigureSettingsWidget()
......
/*
Copyright (C) 2020 Laurent Montel <montel@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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "foldersettingfilterproxymodel.h"
#include <AkonadiCore/EntityTreeModel>
FolderSettingFilterProxyModel::FolderSettingFilterProxyModel(QObject *parent)
: QSortFilterProxyModel(parent)
{
}
FolderSettingFilterProxyModel::~FolderSettingFilterProxyModel()
{
}
QVariant FolderSettingFilterProxyModel::data(const QModelIndex &index, int role) const
{
if (role == Qt::CheckStateRole) {
// Make top-level collections uncheckable
const Akonadi::Collection col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (col.parentCollection() == Akonadi::Collection::root()) {
return {};
}
}
return QSortFilterProxyModel::data(index, role);
}
Qt::ItemFlags FolderSettingFilterProxyModel::flags(const QModelIndex &index) const
{
// Make top-level collections uncheckable
const Akonadi::Collection col = data(index, Akonadi::EntityTreeModel::CollectionRole).value<Akonadi::Collection>();
if (col.parentCollection() == Akonadi::Collection::root()) {
return QSortFilterProxyModel::flags(index) & ~Qt::ItemIsUserCheckable;
} else {
return QSortFilterProxyModel::flags(index);
}
}
/*
Copyright (C) 2020 Laurent Montel <montel@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; see the file COPYING. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef FOLDERSETTINGFILTERPROXYMODEL_H
#define FOLDERSETTINGFILTERPROXYMODEL_H
#include <QSortFilterProxyModel>
class FolderSettingFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit FolderSettingFilterProxyModel(QObject *parent = nullptr);
~FolderSettingFilterProxyModel();
QVariant data(const QModelIndex &index, int role) const override;
Qt::ItemFlags flags(const QModelIndex &index) const override;
};
#endif // FOLDERSETTINGFILTERPROXYMODEL_H
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