File indexing completed on 2025-01-05 05:23:47
0001 /* 0002 This file is part of the Okteta Kasten Framework, made within the KDE community. 0003 0004 SPDX-FileCopyrightText: 2022 Friedrich W. H. Kossebau <kossebau@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0007 */ 0008 0009 #include "structuresselector.hpp" 0010 0011 // tool 0012 #include "structureitemdelegate.hpp" 0013 #include "structuresselectionmodel.hpp" 0014 #include "structuresselectionsortfilterproxymodel.hpp" 0015 // KF 0016 #include <KCategorizedView> 0017 #include <KCategoryDrawer> 0018 #include <KLocalizedString> 0019 // Qt 0020 #include <QLineEdit> 0021 #include <QVBoxLayout> 0022 0023 StructuresSelector::StructuresSelector(QWidget* parent) 0024 : QWidget(parent) 0025 { 0026 auto* layout = new QVBoxLayout(this); 0027 layout->setContentsMargins(0, 0, 0, 0); 0028 0029 // data models 0030 m_structuresModel = new StructuresSelectionModel(this); 0031 connect(m_structuresModel, &StructuresSelectionModel::enabledStructuresChanged, 0032 this, &StructuresSelector::enabledStructuresChanged); 0033 m_soirtFilterProxyModel = new StructuresSelectionSortFilterProxyModel(this); 0034 m_soirtFilterProxyModel->setCategorizedModel(true); 0035 m_soirtFilterProxyModel->setSourceModel(m_structuresModel); 0036 0037 // search field 0038 m_lineEdit = new QLineEdit(this); 0039 m_lineEdit->setClearButtonEnabled(true); 0040 m_lineEdit->setPlaceholderText(i18nc("@info:placeholder", "Search...")); 0041 connect(m_lineEdit, &QLineEdit::textChanged, 0042 m_soirtFilterProxyModel, &StructuresSelectionSortFilterProxyModel::setFilterString); 0043 0044 layout->addWidget(m_lineEdit); 0045 0046 // list view 0047 m_listView = new KCategorizedView(this); 0048 m_categoryDrawer = new KCategoryDrawer(m_listView); 0049 m_listView->setVerticalScrollMode(QListView::ScrollPerPixel); 0050 m_listView->setAlternatingRowColors(true); 0051 m_listView->setCategoryDrawer(m_categoryDrawer); 0052 m_listView->setModel(m_soirtFilterProxyModel); 0053 m_listView->setAlternatingRowColors(true); 0054 0055 m_structureDelegate = new StructureItemDelegate(m_listView, this); 0056 m_listView->setItemDelegate(m_structureDelegate); 0057 0058 m_listView->setMouseTracking(true); 0059 m_listView->viewport()->setAttribute(Qt::WA_Hover); 0060 0061 layout->addWidget(m_listView); 0062 0063 setFocusProxy(m_lineEdit); 0064 } 0065 0066 StructuresSelector::~StructuresSelector() 0067 { 0068 // assist with clean destruction 0069 delete m_structureDelegate; 0070 delete m_listView; 0071 } 0072 0073 void StructuresSelector::setStructures(const QMap<QString, Kasten::StructureDefinitionFile*>& structureDefs) 0074 { 0075 m_structuresModel->setStructures(structureDefs); 0076 m_soirtFilterProxyModel->sort(0); 0077 } 0078 0079 void StructuresSelector::setEnabledStructures(const QStringList& enabledStructures) 0080 { 0081 m_structuresModel->setEnabledStructures(enabledStructures); 0082 } 0083 0084 QStringList StructuresSelector::enabledStructures() const 0085 { 0086 return m_structuresModel->enabledStructures(); 0087 } 0088 0089 const StructureEnabledList& StructuresSelector::enabledList() const 0090 { 0091 return m_structuresModel->enabledList(); 0092 } 0093 0094 #include "moc_structuresselector.cpp"