/* * Copyright (C) 2012 - 2016 by Ivan Cukic * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License or (at your option) version 3 or any later version * accepted by the membership of KDE e.V. (or its successor approved * by the membership of KDE e.V.), which shall act as a proxy * defined in Section 14 of version 3 of the license. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #include "SwitchingTab.h" #include "kactivitymanagerd_settings.h" #include #include #include #include #include "ui_SwitchingTabBase.h" #include #include class SwitchingTab::Private : public Ui::SwitchingTabBase { public: KActivityManagerdSettings mainConfig; KActionCollection *mainActionCollection; KActivities::Consumer activities; void createAction(const QString &actionName, const QString &actionText, const QList &defaultSequence) { auto action = mainActionCollection->addAction(actionName); action->setProperty("isConfigurationAction", true); action->setText(actionText); KGlobalAccel::self()->setShortcut(action, defaultSequence); KGlobalAccel::self()->setDefaultShortcut(action, defaultSequence); } Private() : mainActionCollection(nullptr) { } }; SwitchingTab::SwitchingTab(QWidget *parent) : QWidget(parent) , d() { d->setupUi(this); // Shortcut config. The shortcut belongs to the component "plasmashell"! d->mainActionCollection = new KActionCollection(this, QStringLiteral("plasmashell")); d->mainActionCollection->setComponentDisplayName(i18n("Activity switching")); d->mainActionCollection->setConfigGlobal(true); d->createAction(QStringLiteral("next activity"), i18nc("@action", "Walk through activities"), { Qt::META + Qt::Key_Tab }); d->createAction(QStringLiteral("previous activity"), i18nc("@action", "Walk through activities (Reverse)"), { Qt::META + Qt::SHIFT + Qt::Key_Tab } ); d->scActivities->setActionTypes(KShortcutsEditor::GlobalAction); d->scActivities->addCollection(d->mainActionCollection); connect(d->scActivities, &KShortcutsEditor::keyChange, this, [this] { changed(); }); connect(d->checkRememberVirtualDesktop, &QAbstractButton::toggled, this, &SwitchingTab::changed); defaults(); } SwitchingTab::~SwitchingTab() { } bool SwitchingTab::isDefault() { return !d->checkRememberVirtualDesktop->isChecked(); } void SwitchingTab::shortcutChanged(const QKeySequence &sequence) { QString actionName = sender() ? sender()->property("shortcutAction").toString() : QString(); if (actionName.isEmpty()) return; auto action = d->mainActionCollection->action(actionName); KGlobalAccel::self()->setShortcut(action, { sequence }, KGlobalAccel::NoAutoloading); d->mainActionCollection->writeSettings(); emit changed(); } void SwitchingTab::defaults() { d->checkRememberVirtualDesktop->setChecked(false); } void SwitchingTab::load() { d->checkRememberVirtualDesktop->setChecked(d->mainConfig.virtualDesktopSwitchEnabled()); } void SwitchingTab::save() { d->mainConfig.setVirtualDesktopSwitchEnabled(d->checkRememberVirtualDesktop->isChecked()); d->mainConfig.save(); }