File indexing completed on 2024-11-24 03:56:28

0001 /*
0002  * SPDX-FileCopyrightText: 2019-2023 Mattia Basaglia <dev@dragon.best>
0003  *
0004  * SPDX-License-Identifier: GPL-3.0-or-later
0005  */
0006 
0007 #include "keyboard_settings_widget.hpp"
0008 #include "ui_keyboard_settings_widget.h"
0009 
0010 #include <QEvent>
0011 
0012 #include "app/settings/keyboard_shortcuts_model.hpp"
0013 
0014 class KeyboardSettingsWidget::Private
0015 {
0016 public:
0017     Private(app::settings::ShortcutSettings* settings)
0018         : inner_model(settings), settings(settings)
0019     {
0020         model.setSourceModel(&inner_model);
0021         model.setFilterCaseSensitivity(Qt::CaseInsensitive);
0022     }
0023 
0024     Ui::KeyboardSettingsWidget ui;
0025     app::settings::KeyboardShortcutsModel inner_model;
0026     app::settings::KeyboardShortcutsFilterModel model;
0027     app::settings::KeyboardShortcutsDelegate delegate;
0028     app::settings::ShortcutSettings* settings;
0029 
0030 };
0031 
0032 KeyboardSettingsWidget::KeyboardSettingsWidget(app::settings::ShortcutSettings* settings, QWidget* parent)
0033     : QWidget(parent), d(std::make_unique<Private>(settings))
0034 {
0035     d->ui.setupUi(this);
0036     d->ui.tree_view->setModel(&d->model);
0037     d->ui.tree_view->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
0038     d->ui.tree_view->header()->setSectionResizeMode(1, QHeaderView::Stretch);
0039     d->ui.tree_view->setItemDelegateForColumn(1, &d->delegate);
0040 
0041     connect(settings, &app::settings::ShortcutSettings::begin_actions_change, &d->inner_model, &app::settings::KeyboardShortcutsModel::begin_change_data);
0042     connect(settings, &app::settings::ShortcutSettings::end_actions_change, &d->inner_model, &app::settings::KeyboardShortcutsModel::end_change_data);
0043 }
0044 
0045 KeyboardSettingsWidget::~KeyboardSettingsWidget() = default;
0046 
0047 void KeyboardSettingsWidget::changeEvent ( QEvent* e )
0048 {
0049     QWidget::changeEvent(e);
0050 
0051     if ( e->type() == QEvent::LanguageChange)
0052     {
0053         d->ui.retranslateUi(this);
0054     }
0055 }
0056 
0057 void KeyboardSettingsWidget::clear_filter()
0058 {
0059     d->ui.filter->setText("");
0060 }
0061 
0062 void KeyboardSettingsWidget::filter(const QString& text)
0063 {
0064     d->model.setFilterFixedString(text);
0065 }