File indexing completed on 2025-01-26 03:28:30
0001 /* 0002 SPDX-FileCopyrightText: 2023 Montel Laurent <montel@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL 0005 */ 0006 0007 #include "accessibletreewidget.h" 0008 #include "accessibletreeview.h" 0009 #include <KLocalizedString> 0010 #include <QHeaderView> 0011 #include <QLineEdit> 0012 #include <QSettings> 0013 #include <QTreeView> 0014 #include <QVBoxLayout> 0015 0016 AccessibleTreeWidget::AccessibleTreeWidget(QAccessibleClient::Registry *registry, QWidget *parent) 0017 : QWidget{parent} 0018 , mSearchLineEdit(new QLineEdit(this)) 0019 , mAccessibleTreeView(new AccessibleTreeView(registry, this)) 0020 { 0021 auto mainLayout = new QVBoxLayout(this); 0022 mainLayout->setObjectName(QLatin1StringView("mainLayout")); 0023 mainLayout->setContentsMargins({}); 0024 mainLayout->setSpacing(0); 0025 0026 mSearchLineEdit->setPlaceholderText(i18nc("@info:placeholder", "Filter...")); 0027 0028 auto searchLineEditWrapper = new QVBoxLayout; 0029 searchLineEditWrapper->setContentsMargins(style()->pixelMetric(QStyle::PM_LayoutLeftMargin), 0030 style()->pixelMetric(QStyle::PM_LayoutTopMargin), 0031 style()->pixelMetric(QStyle::PM_LayoutRightMargin), 0032 style()->pixelMetric(QStyle::PM_LayoutBottomMargin)); 0033 searchLineEditWrapper->addWidget(mSearchLineEdit); 0034 mSearchLineEdit->setObjectName(QLatin1StringView("mSearchLineEdit")); 0035 mSearchLineEdit->setClearButtonEnabled(true); 0036 mainLayout->addLayout(searchLineEditWrapper); 0037 0038 mAccessibleTreeView->setObjectName(QLatin1StringView("mAccessibleTreeView")); 0039 mAccessibleTreeView->setProperty("_breeze_borders_sides", QVariant::fromValue(QFlags{Qt::TopEdge})); 0040 mainLayout->addWidget(mAccessibleTreeView); 0041 connect(mAccessibleTreeView, &AccessibleTreeView::accessibleTreeviewSelectionChanged, this, &AccessibleTreeWidget::accessibleTreeviewSelectionChanged); 0042 connect(mSearchLineEdit, &QLineEdit::textChanged, mAccessibleTreeView, &AccessibleTreeView::setSearchTextChanged); 0043 } 0044 0045 AccessibleTreeWidget::~AccessibleTreeWidget() = default; 0046 0047 AccessibleObjectTreeModel *AccessibleTreeWidget::accessibleObjectTreeModel() const 0048 { 0049 return mAccessibleTreeView->accessibleObjectTreeModel(); 0050 } 0051 0052 void AccessibleTreeWidget::setCurrentObject(const QAccessibleClient::AccessibleObject &object) 0053 { 0054 mAccessibleTreeView->setCurrentObject(object); 0055 } 0056 0057 void AccessibleTreeWidget::saveSettings(QSettings &settings) 0058 { 0059 const QByteArray state = mAccessibleTreeView->header()->saveState(); 0060 settings.beginGroup(QStringLiteral("accessibleytreeview")); 0061 settings.setValue(QStringLiteral("header"), state); 0062 settings.endGroup(); 0063 } 0064 0065 void AccessibleTreeWidget::loadSettings(QSettings &settings) 0066 { 0067 settings.beginGroup(QStringLiteral("accessibleytreeview")); 0068 mAccessibleTreeView->header()->restoreState(settings.value("header").toByteArray()); 0069 settings.endGroup(); 0070 } 0071 0072 #include "moc_accessibletreewidget.cpp"