File indexing completed on 2024-09-15 10:32:55
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 "simple_action_data_widget.h" 0008 0009 #include "actions/command_url_action_widget.h" 0010 #include "actions/dbus_action_widget.h" 0011 #include "actions/keyboard_input_action_widget.h" 0012 #include "actions/menuentry_action_widget.h" 0013 #include "triggers/gesture_trigger_widget.h" 0014 #include "triggers/shortcut_trigger_widget.h" 0015 #include "triggers/window_trigger_widget.h" 0016 0017 #include <QDebug> 0018 0019 SimpleActionDataWidget::SimpleActionDataWidget(QWidget *parent) 0020 : HotkeysWidgetBase(parent) 0021 , currentTrigger(nullptr) 0022 , currentAction(nullptr) 0023 { 0024 } 0025 0026 SimpleActionDataWidget::~SimpleActionDataWidget() 0027 { 0028 delete currentTrigger; 0029 delete currentAction; 0030 } 0031 0032 bool SimpleActionDataWidget::isChanged() const 0033 { 0034 return (currentTrigger && currentTrigger->isChanged()) || (currentAction && currentAction->isChanged()) || Base::isChanged(); 0035 } 0036 0037 void SimpleActionDataWidget::doCopyFromObject() 0038 { 0039 Base::doCopyFromObject(); 0040 0041 if (currentTrigger) { 0042 currentTrigger->copyFromObject(); 0043 } 0044 0045 if (currentAction) { 0046 currentAction->copyFromObject(); 0047 } 0048 } 0049 0050 void SimpleActionDataWidget::doCopyToObject() 0051 { 0052 Base::doCopyToObject(); 0053 0054 if (currentTrigger) { 0055 currentTrigger->copyToObject(); 0056 } 0057 0058 if (currentAction) { 0059 currentAction->copyToObject(); 0060 } 0061 } 0062 0063 void SimpleActionDataWidget::unsetActionData() 0064 { 0065 _data = nullptr; 0066 0067 delete currentTrigger; 0068 currentTrigger = nullptr; 0069 0070 delete currentAction; 0071 currentAction = nullptr; 0072 } 0073 0074 void SimpleActionDataWidget::setActionData(KHotKeys::SimpleActionData *pData) 0075 { 0076 unsetActionData(); 0077 _data = pData; 0078 0079 if (KHotKeys::Trigger *trg = data()->trigger()) { 0080 switch (trg->type()) { 0081 case KHotKeys::Trigger::ShortcutTriggerType: 0082 qDebug() << "1"; 0083 currentTrigger = new ShortcutTriggerWidget(static_cast<KHotKeys::ShortcutTrigger *>(trg)); 0084 break; 0085 0086 case KHotKeys::Trigger::WindowTriggerType: 0087 qDebug() << "2"; 0088 currentTrigger = new WindowTriggerWidget(static_cast<KHotKeys::WindowTrigger *>(trg)); 0089 break; 0090 0091 case KHotKeys::Trigger::GestureTriggerType: 0092 qDebug() << "3"; 0093 currentTrigger = new GestureTriggerWidget(static_cast<KHotKeys::GestureTrigger *>(trg)); 0094 break; 0095 0096 default: 0097 qDebug() << "Unknown trigger type"; 0098 }; 0099 } 0100 0101 if (currentTrigger) { 0102 connect(currentTrigger, SIGNAL(changed(bool)), this, SLOT(slotChanged())); 0103 extend(currentTrigger, i18n("Trigger")); 0104 } 0105 0106 if (KHotKeys::Action *act = data()->action()) { 0107 switch (act->type()) { 0108 case KHotKeys::Action::MenuEntryActionType: 0109 currentAction = new MenuentryActionWidget(static_cast<KHotKeys::MenuEntryAction *>(act)); 0110 break; 0111 0112 case KHotKeys::Action::DBusActionType: 0113 currentAction = new DbusActionWidget(static_cast<KHotKeys::DBusAction *>(act)); 0114 break; 0115 0116 case KHotKeys::Action::CommandUrlActionType: 0117 currentAction = new CommandUrlActionWidget(static_cast<KHotKeys::CommandUrlAction *>(act)); 0118 break; 0119 0120 case KHotKeys::Action::KeyboardInputActionType: 0121 currentAction = new KeyboardInputActionWidget(static_cast<KHotKeys::KeyboardInputAction *>(act)); 0122 break; 0123 0124 default: 0125 qDebug() << "Unknown action type"; 0126 }; 0127 } 0128 0129 if (currentAction) { 0130 connect(currentAction, SIGNAL(changed(bool)), this, SLOT(slotChanged())); 0131 extend(currentAction, i18n("Action")); 0132 } 0133 0134 Base::copyFromObject(); 0135 } 0136 0137 #include "moc_simple_action_data_widget.cpp"