File indexing completed on 2024-09-15 12:55:41
0001 /* SPDX-FileCopyrightText: 2009 Michael Jansen <kde@michael-jansen.biz> 0002 0003 SPDX-License-Identifier: LGPL-2.0-or-later 0004 */ 0005 0006 #include "keyboard_input_action_widget.h" 0007 0008 #include <QDebug> 0009 0010 KeyboardInputActionWidget::KeyboardInputActionWidget(KHotKeys::KeyboardInputAction *action, QWidget *parent) 0011 : Base(action, parent) 0012 { 0013 ui.setupUi(this); 0014 0015 connect(ui.input, SIGNAL(textChanged()), _changedSignals, SLOT(map())); 0016 _changedSignals->setMapping(ui.input, "input"); 0017 0018 connect(ui.windowdef_list, SIGNAL(changed(bool)), _changedSignals, SLOT(map())); 0019 _changedSignals->setMapping(ui.windowdef_list, "windowdef_list"); 0020 0021 connect(ui.active_radio, SIGNAL(clicked(bool)), _changedSignals, SLOT(map())); 0022 _changedSignals->setMapping(ui.active_radio, "active_radio"); 0023 0024 connect(ui.action_radio, SIGNAL(clicked(bool)), _changedSignals, SLOT(map())); 0025 _changedSignals->setMapping(ui.action_radio, "action_radio"); 0026 0027 connect(ui.specific_radio, SIGNAL(clicked(bool)), _changedSignals, SLOT(map())); 0028 _changedSignals->setMapping(ui.specific_radio, "specific_radio"); 0029 } 0030 0031 KeyboardInputActionWidget::~KeyboardInputActionWidget() 0032 { 0033 } 0034 0035 KHotKeys::KeyboardInputAction *KeyboardInputActionWidget::action() 0036 { 0037 Q_ASSERT(dynamic_cast<KHotKeys::KeyboardInputAction *>(_action)); 0038 return static_cast<KHotKeys::KeyboardInputAction *>(_action); 0039 } 0040 0041 const KHotKeys::KeyboardInputAction *KeyboardInputActionWidget::action() const 0042 { 0043 Q_ASSERT(dynamic_cast<KHotKeys::KeyboardInputAction *>(_action)); 0044 return static_cast<const KHotKeys::KeyboardInputAction *>(_action); 0045 } 0046 0047 void KeyboardInputActionWidget::doCopyFromObject() 0048 { 0049 Q_ASSERT(action()); 0050 ui.input->setText(action()->input()); 0051 ui.windowdef_list->setWindowDefinitions(action()->dest_window()); 0052 ui.windowdef_list->copyFromObject(); 0053 0054 switch (action()->destination()) { 0055 case KHotKeys::KeyboardInputAction::SpecificWindow: 0056 ui.specific_radio->setChecked(true); 0057 break; 0058 0059 case KHotKeys::KeyboardInputAction::ActiveWindow: 0060 ui.active_radio->setChecked(true); 0061 break; 0062 0063 case KHotKeys::KeyboardInputAction::ActionWindow: 0064 ui.action_radio->setChecked(true); 0065 break; 0066 0067 default: 0068 Q_ASSERT(false); 0069 ui.action_radio->setChecked(true); 0070 } 0071 } 0072 0073 void KeyboardInputActionWidget::doCopyToObject() 0074 { 0075 Q_ASSERT(action()); 0076 action()->setInput(ui.input->toPlainText()); 0077 if (ui.action_radio->isChecked()) { 0078 action()->setDestination(KHotKeys::KeyboardInputAction::ActionWindow); 0079 action()->dest_window()->clear(); 0080 } else if (ui.active_radio->isChecked()) { 0081 action()->setDestination(KHotKeys::KeyboardInputAction::ActiveWindow); 0082 action()->dest_window()->clear(); 0083 } else { 0084 action()->setDestination(KHotKeys::KeyboardInputAction::SpecificWindow); 0085 ui.windowdef_list->copyToObject(); 0086 } 0087 } 0088 0089 bool KeyboardInputActionWidget::isChanged() const 0090 { 0091 Q_ASSERT(action()); 0092 0093 if (ui.input->toPlainText() != action()->input()) 0094 return true; 0095 0096 switch (action()->destination()) { 0097 case KHotKeys::KeyboardInputAction::ActionWindow: 0098 return !ui.action_radio->isChecked(); 0099 0100 case KHotKeys::KeyboardInputAction::ActiveWindow: 0101 return !ui.active_radio->isChecked(); 0102 0103 case KHotKeys::KeyboardInputAction::SpecificWindow: 0104 return !ui.specific_radio->isChecked() || ui.windowdef_list->isChanged(); 0105 } 0106 0107 return false; 0108 } 0109 0110 #include "moc_keyboard_input_action_widget.cpp"