KDEUI
kshortcutwidget.cpp
Go to the documentation of this file.00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2007 Andreas Hartmetz <ahartmetz@gmail.com> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #include "kshortcutwidget.h" 00021 #include "kiconloader.h" 00022 #include "ui_kshortcutwidget.h" 00023 00024 class KShortcutWidgetPrivate 00025 { 00026 public: 00027 KShortcutWidgetPrivate(KShortcutWidget *q) : q(q) {} 00028 00029 //private slots 00030 void priKeySequenceChanged(const QKeySequence &); 00031 void altKeySequenceChanged(const QKeySequence &); 00032 00033 //members 00034 KShortcutWidget *const q; 00035 Ui::KShortcutWidget ui; 00036 KShortcut cut; 00037 bool holdChangedSignal; 00038 }; 00039 00040 00041 KShortcutWidget::KShortcutWidget(QWidget *parent) 00042 : QWidget(parent), 00043 d(new KShortcutWidgetPrivate(this)) 00044 { 00045 d->holdChangedSignal = false; 00046 d->ui.setupUi(this); 00047 connect(d->ui.priEditor, SIGNAL(keySequenceChanged(const QKeySequence &)), 00048 this, SLOT(priKeySequenceChanged(const QKeySequence &))); 00049 connect(d->ui.altEditor, SIGNAL(keySequenceChanged(const QKeySequence &)), 00050 this, SLOT(altKeySequenceChanged(const QKeySequence &))); 00051 } 00052 00053 00054 KShortcutWidget::~KShortcutWidget() 00055 { 00056 delete d; 00057 } 00058 00059 00060 void KShortcutWidget::setModifierlessAllowed(bool allow) 00061 { 00062 d->ui.priEditor->setModifierlessAllowed(allow); 00063 d->ui.altEditor->setModifierlessAllowed(allow); 00064 } 00065 00066 00067 bool KShortcutWidget::isModifierlessAllowed() 00068 { 00069 return d->ui.priEditor->isModifierlessAllowed(); 00070 } 00071 00072 00073 void KShortcutWidget::setClearButtonsShown(bool show) 00074 { 00075 d->ui.priEditor->setClearButtonShown(show); 00076 d->ui.altEditor->setClearButtonShown(show); 00077 } 00078 00079 00080 KShortcut KShortcutWidget::shortcut() const 00081 { 00082 KShortcut ret; 00083 ret.setPrimary(d->ui.priEditor->keySequence()); 00084 ret.setAlternate(d->ui.altEditor->keySequence()); 00085 return ret; 00086 } 00087 00088 void KShortcutWidget::setCheckActionList(const QList<QAction*> &checkList) 00089 { 00090 d->ui.priEditor->setCheckActionList(checkList); 00091 d->ui.altEditor->setCheckActionList(checkList); 00092 } 00093 00094 void KShortcutWidget::setCheckActionCollections(const QList<KActionCollection *>& actionCollections) 00095 { 00096 d->ui.priEditor->setCheckActionCollections(actionCollections); 00097 d->ui.altEditor->setCheckActionCollections(actionCollections); 00098 } 00099 00100 //slot 00101 void KShortcutWidget::applyStealShortcut() 00102 { 00103 d->ui.priEditor->applyStealShortcut(); 00104 d->ui.altEditor->applyStealShortcut(); 00105 } 00106 00107 00108 //slot 00109 void KShortcutWidget::setShortcut(const KShortcut &newSc) 00110 { 00111 if (newSc == d->cut) 00112 return; 00113 00114 d->holdChangedSignal = true; 00115 d->ui.priEditor->setKeySequence(newSc.primary()); 00116 d->ui.altEditor->setKeySequence(newSc.alternate()); 00117 d->holdChangedSignal = false; 00118 00119 emit shortcutChanged(d->cut); 00120 } 00121 00122 00123 //slot 00124 void KShortcutWidget::clearShortcut() 00125 { 00126 setShortcut(KShortcut()); 00127 } 00128 00129 00130 //private slot 00131 void KShortcutWidgetPrivate::priKeySequenceChanged(const QKeySequence &seq) 00132 { 00133 cut.setPrimary(seq); 00134 if (!holdChangedSignal) 00135 emit q->shortcutChanged(cut); 00136 } 00137 00138 00139 //private slot 00140 void KShortcutWidgetPrivate::altKeySequenceChanged(const QKeySequence &seq) 00141 { 00142 cut.setAlternate(seq); 00143 if (!holdChangedSignal) 00144 emit q->shortcutChanged(cut); 00145 } 00146 00147 #include "kshortcutwidget.moc"