File indexing completed on 2024-05-12 05:35:42

0001 /*
0002     SPDX-FileCopyrightText: 2010 Andriy Rysin <rysin@kde.org>
0003     SPDX-FileCopyrightText: 2021 Cyril Rossi <cyril.rossi@enioka.com>
0004 
0005     SPDX-License-Identifier: GPL-2.0-or-later
0006 */
0007 
0008 #pragma once
0009 
0010 #include "ui_kcm_keyboard.h"
0011 
0012 #include <QTabWidget>
0013 
0014 #include "keyboard_config.h"
0015 #include <config-keyboard.h>
0016 
0017 class QWidget;
0018 class KeyboardConfig;
0019 class WorkspaceOptions;
0020 struct Rules;
0021 class Flags;
0022 class QString;
0023 class QPushButton;
0024 class LayoutsTableModel;
0025 class KCMiscKeyboardWidget;
0026 class KeyboardLayoutActionCollection;
0027 class KeyboardMiscSettings;
0028 
0029 class KCMKeyboardWidget : public QTabWidget
0030 {
0031     Q_OBJECT
0032 
0033 public:
0034     KCMKeyboardWidget(Rules *rules, KeyboardConfig *keyboardConfig, WorkspaceOptions &workspaceOptions, KCMiscKeyboardWidget *kcmMiscWidget, const QVariantList &args, QWidget *parent = nullptr);
0035     ~KCMKeyboardWidget() override;
0036 
0037     void updateUI(); // load
0038     void save();
0039     void defaults();
0040 
0041     bool isSaveNeeded() const;
0042     bool isDefault() const;
0043 
0044 Q_SIGNALS:
0045     void changed(bool state);
0046 
0047 public Q_SLOTS:
0048     void setDefaultIndicator(bool visible);
0049 
0050 private Q_SLOTS:
0051     void updateUiDefaultIndicator();
0052     void addLayout();
0053     void removeLayout();
0054     void layoutSelectionChanged();
0055     // Set move UI values to config
0056     void uiChanged();
0057     void scrollToGroupShortcut();
0058     void scrollTo3rdLevelShortcut();
0059     void clearGroupShortcuts();
0060     void clear3rdLevelShortcuts();
0061     void updateXkbShortcutsButtons();
0062     void moveUp();
0063     void moveDown();
0064     void configureLayoutsChanged();
0065     void configureXkbOptionsChanged();
0066     void previewLayout();
0067     void alternativeShortcutChanged(const QKeySequence &seq);
0068     void lastUsedLayoutShortcutChanged(const QKeySequence &seq);
0069     void switchKeyboardShortcutChanged();
0070 
0071 private:
0072     Rules *rules;
0073     Flags *flags;
0074     Ui::TabWidget *uiWidget;
0075     KeyboardConfig *keyboardConfig;
0076     WorkspaceOptions &m_workspaceOptions;
0077     KeyboardLayoutActionCollection *actionCollection;
0078     LayoutsTableModel *layoutsTableModel;
0079     bool uiUpdating;
0080     bool m_highlightVisible = false;
0081 
0082     void initializeLayoutsUI();
0083     void initializeXkbOptionsUI();
0084     void initializeKeyboardModelUI();
0085     void updateHardwareUI(const QString &model);
0086     void updateLayoutsUI();
0087     void updateShortcutsUI();
0088     void updateSwitchingPolicyUI(KeyboardConfig::SwitchingPolicy policy);
0089     void updateXkbShortcutButton(const QString &groupName, QPushButton *button);
0090     void clearXkbGroup(const QString &groupName);
0091     void moveSelectedLayouts(int shift);
0092     void populateWithCurrentLayouts();
0093     void populateWithCurrentXkbOptions();
0094     void updateLoopCount();
0095     void handleParameters(const QVariantList &args);
0096     void saveXkbOptions();
0097     QStringList xkbOptionsFromUI() const;
0098 
0099     QString keyboardModelFromUI() const;
0100     KeyboardConfig::SwitchingPolicy switchingPolicyFromUI() const;
0101     void setDefaultIndicatorVisible(QWidget *widget, bool visible);
0102 };