Changeset View
Changeset View
Standalone View
Standalone View
effects/trackmouse/trackmouse_config.cpp
Show All 38 Lines | |||||
39 | 39 | | |||
40 | K_PLUGIN_FACTORY_WITH_JSON(TrackMouseEffectConfigFactory, | 40 | K_PLUGIN_FACTORY_WITH_JSON(TrackMouseEffectConfigFactory, | ||
41 | "trackmouse_config.json", | 41 | "trackmouse_config.json", | ||
42 | registerPlugin<KWin::TrackMouseEffectConfig>();) | 42 | registerPlugin<KWin::TrackMouseEffectConfig>();) | ||
43 | 43 | | |||
44 | namespace KWin | 44 | namespace KWin | ||
45 | { | 45 | { | ||
46 | 46 | | |||
47 | static const QString s_toggleTrackMouseActionName = QStringLiteral("TrackMouse"); | ||||
48 | | ||||
47 | TrackMouseEffectConfigForm::TrackMouseEffectConfigForm(QWidget* parent) : QWidget(parent) | 49 | TrackMouseEffectConfigForm::TrackMouseEffectConfigForm(QWidget* parent) : QWidget(parent) | ||
48 | { | 50 | { | ||
49 | setupUi(this); | 51 | setupUi(this); | ||
50 | } | 52 | } | ||
51 | 53 | | |||
52 | TrackMouseEffectConfig::TrackMouseEffectConfig(QWidget* parent, const QVariantList& args) : | 54 | TrackMouseEffectConfig::TrackMouseEffectConfig(QWidget* parent, const QVariantList& args) : | ||
53 | KCModule(KAboutData::pluginData(QStringLiteral("trackmouse")), parent, args) | 55 | KCModule(KAboutData::pluginData(QStringLiteral("trackmouse")), parent, args) | ||
54 | { | 56 | { | ||
55 | TrackMouseConfig::instance(KWIN_CONFIG); | 57 | TrackMouseConfig::instance(KWIN_CONFIG); | ||
56 | m_ui = new TrackMouseEffectConfigForm(this); | 58 | m_ui = new TrackMouseEffectConfigForm(this); | ||
57 | QVBoxLayout* layout = new QVBoxLayout(this); | 59 | QVBoxLayout* layout = new QVBoxLayout(this); | ||
58 | layout->addWidget(m_ui); | 60 | layout->addWidget(m_ui); | ||
59 | 61 | | |||
60 | addConfig(TrackMouseConfig::self(), m_ui); | 62 | addConfig(TrackMouseConfig::self(), m_ui); | ||
61 | 63 | | |||
62 | m_actionCollection = new KActionCollection(this, QStringLiteral("kwin")); | 64 | m_actionCollection = new KActionCollection(this, QStringLiteral("kwin")); | ||
63 | m_actionCollection->setComponentDisplayName(i18n("KWin")); | 65 | m_actionCollection->setComponentDisplayName(i18n("KWin")); | ||
64 | m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse")); | 66 | m_actionCollection->setConfigGroup(QStringLiteral("TrackMouse")); | ||
65 | m_actionCollection->setConfigGlobal(true); | 67 | m_actionCollection->setConfigGlobal(true); | ||
66 | 68 | | |||
67 | QAction *a = m_actionCollection->addAction(QStringLiteral("TrackMouse")); | 69 | QAction *a = m_actionCollection->addAction(s_toggleTrackMouseActionName); | ||
68 | a->setText(i18n("Track mouse")); | 70 | a->setText(i18n("Track mouse")); | ||
69 | a->setProperty("isConfigurationAction", true); | 71 | a->setProperty("isConfigurationAction", true); | ||
70 | 72 | | |||
71 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>()); | 73 | KGlobalAccel::self()->setDefaultShortcut(a, QList<QKeySequence>()); | ||
72 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>()); | 74 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>()); | ||
73 | 75 | | |||
74 | connect(m_ui->shortcut, SIGNAL(keySequenceChanged(QKeySequence)), | 76 | connect(m_ui->shortcut, SIGNAL(keySequenceChanged(QKeySequence)), | ||
75 | SLOT(shortcutChanged(QKeySequence))); | 77 | SLOT(shortcutChanged(QKeySequence))); | ||
76 | 78 | | |||
77 | load(); | 79 | load(); | ||
78 | } | 80 | } | ||
79 | 81 | | |||
80 | TrackMouseEffectConfig::~TrackMouseEffectConfig() | 82 | TrackMouseEffectConfig::~TrackMouseEffectConfig() | ||
81 | { | 83 | { | ||
82 | } | 84 | } | ||
83 | 85 | | |||
84 | void TrackMouseEffectConfig::checkModifiers() | | |||
85 | { | | |||
86 | const bool modifiers = m_ui->kcfg_Shift->isChecked() || m_ui->kcfg_Alt->isChecked() || | | |||
87 | m_ui->kcfg_Control->isChecked() || m_ui->kcfg_Meta->isChecked(); | | |||
88 | m_ui->modifierRadio->setChecked(modifiers); | | |||
89 | m_ui->shortcutRadio->setChecked(!modifiers); | | |||
90 | } | | |||
91 | | ||||
92 | void TrackMouseEffectConfig::load() | 86 | void TrackMouseEffectConfig::load() | ||
93 | { | 87 | { | ||
94 | KCModule::load(); | 88 | KCModule::load(); | ||
95 | 89 | | |||
96 | checkModifiers(); | 90 | if (QAction *a = m_actionCollection->action(s_toggleTrackMouseActionName)) { | ||
97 | emit changed(false); | 91 | auto shortcuts = KGlobalAccel::self()->shortcut(a); | ||
92 | if (!shortcuts.isEmpty()) { | ||||
93 | m_ui->shortcut->setKeySequence(shortcuts.first()); | ||||
94 | } | ||||
95 | } | ||||
98 | } | 96 | } | ||
99 | 97 | | |||
100 | void TrackMouseEffectConfig::save() | 98 | void TrackMouseEffectConfig::save() | ||
101 | { | 99 | { | ||
102 | KCModule::save(); | 100 | KCModule::save(); | ||
103 | m_actionCollection->writeSettings(); | 101 | m_actionCollection->writeSettings(); | ||
104 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | 102 | OrgKdeKwinEffectsInterface interface(QStringLiteral("org.kde.KWin"), | ||
105 | QStringLiteral("/Effects"), | 103 | QStringLiteral("/Effects"), | ||
106 | QDBusConnection::sessionBus()); | 104 | QDBusConnection::sessionBus()); | ||
107 | interface.reconfigureEffect(QStringLiteral("trackmouse")); | 105 | interface.reconfigureEffect(QStringLiteral("trackmouse")); | ||
108 | } | 106 | } | ||
109 | 107 | | |||
110 | void TrackMouseEffectConfig::defaults() | 108 | void TrackMouseEffectConfig::defaults() | ||
111 | { | 109 | { | ||
112 | KCModule::defaults(); | 110 | KCModule::defaults(); | ||
113 | m_ui->shortcut->clearKeySequence(); | 111 | m_ui->shortcut->clearKeySequence(); | ||
114 | checkModifiers(); | | |||
115 | } | 112 | } | ||
116 | 113 | | |||
117 | void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq) | 114 | void TrackMouseEffectConfig::shortcutChanged(const QKeySequence &seq) | ||
118 | { | 115 | { | ||
119 | if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) { | 116 | if (QAction *a = m_actionCollection->action(QStringLiteral("TrackMouse"))) { | ||
120 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading); | 117 | KGlobalAccel::self()->setShortcut(a, QList<QKeySequence>() << seq, KGlobalAccel::NoAutoloading); | ||
121 | } | 118 | } | ||
122 | // m_actionCollection->writeSettings(); | | |||
123 | emit changed(true); | 119 | emit changed(true); | ||
124 | } | 120 | } | ||
125 | 121 | | |||
126 | } // namespace | 122 | } // namespace | ||
127 | 123 | | |||
128 | #include "trackmouse_config.moc" | 124 | #include "trackmouse_config.moc" |