KDEUI
kshortcuteditwidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "kshortcutsdialog_p.h"
00026
00027 #include <QPainter>
00028 #include <QPen>
00029 #include <QGridLayout>
00030 #include <QRadioButton>
00031 #include <QLabel>
00032
00033 #include "kkeysequencewidget.h"
00034 #include "klocale.h"
00035
00036 void TabConnectedWidget::paintEvent(QPaintEvent *e)
00037 {
00038 QWidget::paintEvent(e);
00039 QPainter p(this);
00040 QPen pen(QPalette().highlight().color());
00041 pen.setWidth(6);
00042 p.setPen(pen);
00043 p.drawLine(0, 0, width(), 0);
00044 p.drawLine(0, 0, 0, height());
00045 }
00046
00047 ShortcutEditWidget::ShortcutEditWidget(QWidget *viewport, const QKeySequence &defaultSeq,
00048 const QKeySequence &activeSeq, bool allowLetterShortcuts)
00049 : TabConnectedWidget(viewport),
00050 m_defaultKeySequence(defaultSeq),
00051 m_isUpdating(false)
00052 {
00053 QGridLayout *layout = new QGridLayout(this);
00054
00055 m_defaultRadio = new QRadioButton(i18n("Default:"), this);
00056 m_defaultLabel = new QLabel(i18nc("No shortcut defined", "None"), this);
00057 QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
00058 if (defaultText.isEmpty())
00059 defaultText = i18nc("No shortcut defined", "None");
00060 m_defaultLabel->setText(defaultText);
00061
00062 m_customRadio = new QRadioButton(i18n("Custom:"), this);
00063 m_customEditor = new KKeySequenceWidget(this);
00064 m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
00065
00066 layout->addWidget(m_defaultRadio, 0, 0);
00067 layout->addWidget(m_defaultLabel, 0, 1);
00068 layout->addWidget(m_customRadio, 1, 0);
00069 layout->addWidget(m_customEditor, 1, 1);
00070 layout->setColumnStretch(2, 1);
00071
00072 setKeySequence(activeSeq);
00073
00074 connect(m_defaultRadio, SIGNAL(toggled(bool)),
00075 this, SLOT(defaultToggled(bool)));
00076 connect(m_customEditor, SIGNAL(keySequenceChanged(const QKeySequence &)),
00077 this, SLOT(setCustom(const QKeySequence &)));
00078 connect(m_customEditor, SIGNAL(stealShortcut(const QKeySequence &, KAction *)),
00079 this, SIGNAL(stealShortcut(const QKeySequence &, KAction *)));
00080 }
00081
00082
00083 KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst() const
00084 {
00085 return m_customEditor->checkForConflictsAgainst();
00086 }
00087
00088
00089 void ShortcutEditWidget::defaultToggled(bool checked)
00090 {
00091 if (m_isUpdating)
00092 return;
00093
00094 m_isUpdating = true;
00095 if (checked) {
00096
00097
00098 if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
00099
00100 m_customEditor->clearKeySequence();
00101 emit keySequenceChanged(m_defaultKeySequence);
00102 } else {
00103
00104
00105 m_customRadio->setChecked(true);
00106 }
00107 } else {
00108
00109 emit keySequenceChanged(QKeySequence());
00110 }
00111 m_isUpdating = false;
00112 }
00113
00114
00115 void ShortcutEditWidget::setCheckActionCollections(
00116 const QList<KActionCollection*> checkActionCollections)
00117 {
00118
00119 m_customEditor->setCheckActionCollections(checkActionCollections);
00120 }
00121
00122
00123 void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes types)
00124 {
00125 m_customEditor->setCheckForConflictsAgainst(types);
00126 }
00127
00128
00129 void ShortcutEditWidget::setComponentName(const QString componentName)
00130 {
00131 m_customEditor->setComponentName(componentName);
00132 }
00133
00134
00135 void ShortcutEditWidget::setMultiKeyShortcutsAllowed(bool allowed)
00136 {
00137
00138 m_customEditor->setMultiKeyShortcutsAllowed(allowed);
00139 }
00140
00141
00142 bool ShortcutEditWidget::multiKeyShortcutsAllowed() const
00143 {
00144 return m_customEditor->multiKeyShortcutsAllowed();
00145 }
00146
00147
00148 void ShortcutEditWidget::setCustom(const QKeySequence &seq)
00149 {
00150 if (m_isUpdating)
00151 return;
00152
00153
00154
00155
00156 QKeySequence original = seq;
00157
00158 m_isUpdating = true;
00159
00160
00161
00162 setKeySequence(original);
00163
00164 emit keySequenceChanged(original);
00165 m_isUpdating = false;
00166 }
00167
00168
00169 void ShortcutEditWidget::setKeySequence(const QKeySequence &activeSeq)
00170 {
00171 if (activeSeq == m_defaultLabel->text()) {
00172 m_defaultRadio->setChecked(true);
00173 m_customEditor->clearKeySequence();
00174 } else {
00175 m_customRadio->setChecked(true);
00176
00177
00178 if (activeSeq!=m_customEditor->keySequence()) {
00179 m_customEditor->setKeySequence(activeSeq);
00180 }
00181 }
00182 }
00183