25 #include "kshortcutsdialog_p.h"
29 #include <QGridLayout>
30 #include <QRadioButton>
36 void TabConnectedWidget::paintEvent(QPaintEvent *e)
38 QWidget::paintEvent(e);
40 QPen pen(QPalette().highlight().color());
43 p.drawLine(0, 0, width(), 0);
44 if (qApp->isLeftToRight()) {
45 p.drawLine(0, 0, 0, height());
47 p.drawLine(width(), 0, width(), height());
51 ShortcutEditWidget::ShortcutEditWidget(
QWidget *viewport,
const QKeySequence &defaultSeq,
52 const QKeySequence &activeSeq,
bool allowLetterShortcuts)
53 : TabConnectedWidget(viewport),
54 m_defaultKeySequence(defaultSeq),
57 QGridLayout *layout =
new QGridLayout(
this);
59 m_defaultRadio =
new QRadioButton(
i18n(
"Default:"),
this);
60 m_defaultLabel =
new QLabel(
i18nc(
"No shortcut defined",
"None"),
this);
61 QString defaultText = defaultSeq.toString(QKeySequence::NativeText);
62 if (defaultText.isEmpty())
63 defaultText =
i18nc(
"No shortcut defined",
"None");
64 m_defaultLabel->setText(defaultText);
66 m_customRadio =
new QRadioButton(
i18n(
"Custom:"),
this);
68 m_customEditor->setModifierlessAllowed(allowLetterShortcuts);
70 layout->addWidget(m_defaultRadio, 0, 0);
71 layout->addWidget(m_defaultLabel, 0, 1);
72 layout->addWidget(m_customRadio, 1, 0);
73 layout->addWidget(m_customEditor, 1, 1);
74 layout->setColumnStretch(2, 1);
76 setKeySequence(activeSeq);
78 connect(m_defaultRadio, SIGNAL(toggled(
bool)),
79 this, SLOT(defaultToggled(
bool)));
80 connect(m_customEditor, SIGNAL(keySequenceChanged(QKeySequence)),
81 this, SLOT(setCustom(QKeySequence)));
82 connect(m_customEditor, SIGNAL(stealShortcut(QKeySequence,
KAction*)),
83 this, SIGNAL(stealShortcut(QKeySequence,
KAction*)));
87 KKeySequenceWidget::ShortcutTypes ShortcutEditWidget::checkForConflictsAgainst()
const
89 return m_customEditor->checkForConflictsAgainst();
93 void ShortcutEditWidget::defaultToggled(
bool checked)
102 if (m_customEditor->isKeySequenceAvailable(m_defaultKeySequence)) {
104 m_customEditor->clearKeySequence();
105 emit keySequenceChanged(m_defaultKeySequence);
109 m_customRadio->setChecked(
true);
113 emit keySequenceChanged(QKeySequence());
115 m_isUpdating =
false;
119 void ShortcutEditWidget::setCheckActionCollections(
123 m_customEditor->setCheckActionCollections(checkActionCollections);
127 void ShortcutEditWidget::setCheckForConflictsAgainst(KKeySequenceWidget::ShortcutTypes types)
129 m_customEditor->setCheckForConflictsAgainst(types);
133 void ShortcutEditWidget::setComponentName(
const QString componentName)
135 m_customEditor->setComponentName(componentName);
139 void ShortcutEditWidget::setMultiKeyShortcutsAllowed(
bool allowed)
142 m_customEditor->setMultiKeyShortcutsAllowed(allowed);
146 bool ShortcutEditWidget::multiKeyShortcutsAllowed()
const
148 return m_customEditor->multiKeyShortcutsAllowed();
152 void ShortcutEditWidget::setCustom(
const QKeySequence &seq)
160 QKeySequence original = seq;
166 setKeySequence(original);
168 emit keySequenceChanged(original);
169 m_isUpdating =
false;
173 void ShortcutEditWidget::setKeySequence(
const QKeySequence &activeSeq)
175 if (activeSeq == m_defaultLabel->text()) {
176 m_defaultRadio->setChecked(
true);
177 m_customEditor->clearKeySequence();
179 m_customRadio->setChecked(
true);
182 if (activeSeq!=m_customEditor->keySequence()) {
183 m_customEditor->setKeySequence(activeSeq);
QString i18n(const char *text)
QString i18nc(const char *ctxt, const char *text)
Class to encapsulate user-driven action or event.