File indexing completed on 2024-04-28 16:44:49

0001 /*
0002    SPDX-FileCopyrightText: 2008 Michael Jansen <kde@michael-jansen.biz>
0003 
0004    SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #include "shortcut_trigger_widget.h"
0008 
0009 #include "action_data/action_data.h"
0010 #include "triggers/triggers.h"
0011 
0012 #include <QKeySequence>
0013 
0014 #include <KGlobalAccel>
0015 #include <QDebug>
0016 
0017 ShortcutTriggerWidget::ShortcutTriggerWidget(KHotKeys::ShortcutTrigger *trigger, QWidget *parent)
0018     : TriggerWidgetBase(trigger, parent)
0019 {
0020     shortcut_trigger_ui.setupUi(this);
0021 
0022     shortcut_trigger_ui.shortcut->setCheckForConflictsAgainst(
0023         // Don't know why that is necessary but it doesn't compile
0024         // without.
0025         KKeySequenceWidget::ShortcutTypes(KKeySequenceWidget::GlobalShortcuts | KKeySequenceWidget::StandardShortcuts));
0026 
0027     connect(shortcut_trigger_ui.shortcut, SIGNAL(keySequenceChanged(QKeySequence)), _changedSignals, SLOT(map()));
0028     _changedSignals->setMapping(shortcut_trigger_ui.shortcut, "shortcut");
0029 
0030     // If the global shortcuts is changed outside of the dialog just copy the
0031     // new key sequencence. It doesn't matter if the user changed the sequence
0032     // here.
0033     connect(KGlobalAccel::self(), &KGlobalAccel::globalShortcutChanged, this, &ShortcutTriggerWidget::_k_globalShortcutChanged);
0034 }
0035 
0036 ShortcutTriggerWidget::~ShortcutTriggerWidget()
0037 {
0038 }
0039 
0040 KHotKeys::ShortcutTrigger *ShortcutTriggerWidget::trigger()
0041 {
0042     return static_cast<KHotKeys::ShortcutTrigger *>(_trigger);
0043 }
0044 
0045 const KHotKeys::ShortcutTrigger *ShortcutTriggerWidget::trigger() const
0046 {
0047     return static_cast<const KHotKeys::ShortcutTrigger *>(_trigger);
0048 }
0049 
0050 void ShortcutTriggerWidget::doCopyFromObject()
0051 {
0052     Q_ASSERT(trigger());
0053     shortcut_trigger_ui.shortcut->setKeySequence(trigger()->primaryShortcut());
0054 }
0055 
0056 void ShortcutTriggerWidget::doCopyToObject()
0057 {
0058     Q_ASSERT(trigger());
0059     trigger()->set_key_sequence(shortcut_trigger_ui.shortcut->keySequence());
0060 }
0061 
0062 bool ShortcutTriggerWidget::isChanged() const
0063 {
0064     Q_ASSERT(trigger());
0065     return QKeySequence(trigger()->primaryShortcut(), QKeySequence::PortableText) != shortcut_trigger_ui.shortcut->keySequence();
0066 }
0067 
0068 void ShortcutTriggerWidget::_k_globalShortcutChanged(QAction *action, const QKeySequence &seq)
0069 {
0070     Q_UNUSED(action);
0071     shortcut_trigger_ui.shortcut->setKeySequence(seq);
0072 }
0073 
0074 #include "moc_shortcut_trigger_widget.cpp"