File indexing completed on 2024-05-05 17:15:14
0001 /****************************************************************************** 0002 Copyright (C) 2011-2012 by Holger Danielsson (holger.danielsson@versanet.de) 0003 ******************************************************************************/ 0004 0005 #include "dialogs/scriptshortcutdialog.h" 0006 0007 #include <QKeySequence> 0008 0009 #include <KActionCollection> 0010 #include <KXMLGUIClient> 0011 #include <KXMLGUIFactory> 0012 #include <KConfigGroup> 0013 #include <QDialogButtonBox> 0014 #include <QPushButton> 0015 #include <QVBoxLayout> 0016 0017 #include "kiledebug.h" 0018 0019 namespace KileDialog { 0020 0021 0022 ScriptShortcutDialog::ScriptShortcutDialog(QWidget *parent, KileInfo *ki, int type, const QString &sequence) 0023 : QDialog(parent) 0024 { 0025 setWindowTitle(i18n("New Key Sequence")); 0026 setModal(true); 0027 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0028 QWidget *mainWidget = new QWidget(this); 0029 QVBoxLayout *mainLayout = new QVBoxLayout; 0030 setLayout(mainLayout); 0031 mainLayout->addWidget(mainWidget); 0032 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0033 okButton->setDefault(true); 0034 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0035 connect(buttonBox, SIGNAL(accepted()), this, SLOT(accept())); 0036 connect(buttonBox, SIGNAL(rejected()), this, SLOT(reject())); 0037 okButton->setDefault(true); 0038 0039 QWidget *page = new QWidget(this); 0040 mainLayout->addWidget(page); 0041 m_scriptShortcutDialog.setupUi(page); 0042 mainLayout->addWidget(buttonBox); 0043 0044 m_scriptShortcutDialog.m_rbKeySequence->setWhatsThis(i18n("Use a key sequence written in the editor to execute a script.")); 0045 m_scriptShortcutDialog.m_rbShortcut->setWhatsThis(i18n("Use a shortcut to execute a script.")); 0046 0047 if(type == KileScript::Script::KEY_SHORTCUT) { 0048 m_scriptShortcutDialog.m_rbShortcut->setChecked(true); 0049 if(sequence.isEmpty()) { 0050 m_scriptShortcutDialog.m_keyChooser->clearKeySequence(); 0051 } 0052 else { 0053 m_scriptShortcutDialog.m_keyChooser->setKeySequence( QKeySequence(sequence) ); 0054 } 0055 } 0056 else { 0057 m_scriptShortcutDialog.m_rbKeySequence->setChecked(true); 0058 m_scriptShortcutDialog.m_leKeySequence->setText(sequence); 0059 } 0060 slotUpdate(); 0061 0062 // search for all action collections (needed for shortcut conflicts) 0063 QList<KActionCollection *> allCollections; 0064 foreach ( KXMLGUIClient *client, ki->mainWindow()->guiFactory()->clients() ) { 0065 allCollections += client->actionCollection(); 0066 } 0067 m_scriptShortcutDialog.m_keyChooser->setCheckActionCollections(allCollections); 0068 0069 connect(m_scriptShortcutDialog.m_rbKeySequence, SIGNAL(clicked()), this, SLOT(slotUpdate())); 0070 connect(m_scriptShortcutDialog.m_rbShortcut, SIGNAL(clicked()), this, SLOT(slotUpdate())); 0071 0072 } 0073 0074 int ScriptShortcutDialog::sequenceType() 0075 { 0076 return (m_scriptShortcutDialog.m_rbShortcut->isChecked()) ? KileScript::Script::KEY_SHORTCUT : KileScript::Script::KEY_SEQUENCE; 0077 } 0078 0079 QString ScriptShortcutDialog::sequenceValue() 0080 { 0081 return m_scriptShortcutDialog.m_rbShortcut->isChecked() 0082 ? m_scriptShortcutDialog.m_keyChooser->keySequence().toString(QKeySequence::PortableText) 0083 : m_scriptShortcutDialog.m_leKeySequence->text(); 0084 } 0085 0086 void ScriptShortcutDialog::slotUpdate() 0087 { 0088 bool state = ( m_scriptShortcutDialog.m_rbKeySequence->isChecked() ) ? true : false; 0089 m_scriptShortcutDialog.m_lbKeySequence->setEnabled(state); 0090 m_scriptShortcutDialog.m_leKeySequence->setEnabled(state); 0091 m_scriptShortcutDialog.m_lbShortcut->setEnabled(!state); 0092 m_scriptShortcutDialog.m_keyChooser->setEnabled(!state); 0093 0094 if(state) { 0095 m_scriptShortcutDialog.m_leKeySequence->setFocus(); 0096 } 0097 else { 0098 m_scriptShortcutDialog.m_keyChooser->setFocus(); 0099 } 0100 } 0101 0102 0103 } 0104