summaryrefslogtreecommitdiff
path: root/src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp')
-rw-r--r--src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp148
1 files changed, 0 insertions, 148 deletions
diff --git a/src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp b/src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp
index 16a67430a..2ceb0fef7 100644
--- a/src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp
+++ b/src/shared/qtpropertybrowser/qtpropertybrowserutils.cpp
@@ -301,152 +301,4 @@ void QtBoolEdit::mousePressEvent(QMouseEvent *event)
}
}
-
-QtKeySequenceEdit::QtKeySequenceEdit(QWidget *parent)
- : QWidget(parent), m_num(0), m_lineEdit(new QLineEdit(this))
-{
- QHBoxLayout *layout = new QHBoxLayout(this);
- layout->addWidget(m_lineEdit);
- layout->setMargin(0);
- m_lineEdit->installEventFilter(this);
- m_lineEdit->setReadOnly(true);
- m_lineEdit->setFocusProxy(this);
- setFocusPolicy(m_lineEdit->focusPolicy());
- setAttribute(Qt::WA_InputMethodEnabled);
-}
-
-bool QtKeySequenceEdit::eventFilter(QObject *o, QEvent *e)
-{
- if (o == m_lineEdit && e->type() == QEvent::ContextMenu) {
- QContextMenuEvent *c = static_cast<QContextMenuEvent *>(e);
- QMenu *menu = m_lineEdit->createStandardContextMenu();
- const QList<QAction *> actions = menu->actions();
- QListIterator<QAction *> itAction(actions);
- while (itAction.hasNext()) {
- QAction *action = itAction.next();
- action->setShortcut(QKeySequence());
- QString actionString = action->text();
- const int pos = actionString.lastIndexOf(QLatin1Char('\t'));
- if (pos > 0)
- actionString.remove(pos, actionString.length() - pos);
- action->setText(actionString);
- }
- QAction *actionBefore = 0;
- if (actions.count() > 0)
- actionBefore = actions[0];
- QAction *clearAction = new QAction(tr("Clear Shortcut"), menu);
- menu->insertAction(actionBefore, clearAction);
- menu->insertSeparator(actionBefore);
- clearAction->setEnabled(!m_keySequence.isEmpty());
- connect(clearAction, SIGNAL(triggered()), this, SLOT(slotClearShortcut()));
- menu->exec(c->globalPos());
- delete menu;
- e->accept();
- return true;
- }
-
- return QWidget::eventFilter(o, e);
-}
-
-void QtKeySequenceEdit::slotClearShortcut()
-{
- if (m_keySequence.isEmpty())
- return;
- setKeySequence(QKeySequence());
- emit keySequenceChanged(m_keySequence);
-}
-
-void QtKeySequenceEdit::handleKeyEvent(QKeyEvent *e)
-{
- int nextKey = e->key();
- if (nextKey == Qt::Key_Control || nextKey == Qt::Key_Shift ||
- nextKey == Qt::Key_Meta || nextKey == Qt::Key_Alt ||
- nextKey == Qt::Key_Super_L || nextKey == Qt::Key_AltGr)
- return;
-
- nextKey |= translateModifiers(e->modifiers(), e->text());
- int k0 = m_keySequence[0];
- int k1 = m_keySequence[1];
- int k2 = m_keySequence[2];
- int k3 = m_keySequence[3];
- switch (m_num) {
- case 0: k0 = nextKey; k1 = 0; k2 = 0; k3 = 0; break;
- case 1: k1 = nextKey; k2 = 0; k3 = 0; break;
- case 2: k2 = nextKey; k3 = 0; break;
- case 3: k3 = nextKey; break;
- default: break;
- }
- ++m_num;
- if (m_num > 3)
- m_num = 0;
- m_keySequence = QKeySequence(k0, k1, k2, k3);
- m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
- e->accept();
- emit keySequenceChanged(m_keySequence);
-}
-
-void QtKeySequenceEdit::setKeySequence(const QKeySequence &sequence)
-{
- if (sequence == m_keySequence)
- return;
- m_num = 0;
- m_keySequence = sequence;
- m_lineEdit->setText(m_keySequence.toString(QKeySequence::NativeText));
-}
-
-QKeySequence QtKeySequenceEdit::keySequence() const
-{
- return m_keySequence;
-}
-
-int QtKeySequenceEdit::translateModifiers(Qt::KeyboardModifiers state, const QString &text) const
-{
- int result = 0;
- if ((state & Qt::ShiftModifier) && (text.size() == 0 || !text.at(0).isPrint() || text.at(0).isLetter() || text.at(0).isSpace()))
- result |= Qt::SHIFT;
- if (state & Qt::ControlModifier)
- result |= Qt::CTRL;
- if (state & Qt::MetaModifier)
- result |= Qt::META;
- if (state & Qt::AltModifier)
- result |= Qt::ALT;
- return result;
-}
-
-void QtKeySequenceEdit::focusInEvent(QFocusEvent *e)
-{
- m_lineEdit->event(e);
- m_lineEdit->selectAll();
- QWidget::focusInEvent(e);
-}
-
-void QtKeySequenceEdit::focusOutEvent(QFocusEvent *e)
-{
- m_num = 0;
- m_lineEdit->event(e);
- QWidget::focusOutEvent(e);
-}
-
-void QtKeySequenceEdit::keyPressEvent(QKeyEvent *e)
-{
- handleKeyEvent(e);
- e->accept();
-}
-
-void QtKeySequenceEdit::keyReleaseEvent(QKeyEvent *e)
-{
- m_lineEdit->event(e);
-}
-
-bool QtKeySequenceEdit::event(QEvent *e)
-{
- if (e->type() == QEvent::Shortcut ||
- e->type() == QEvent::ShortcutOverride ||
- e->type() == QEvent::KeyRelease) {
- e->accept();
- return true;
- }
- return QWidget::event(e);
-}
-
QT_END_NAMESPACE