Commit fb46a688 authored by Victor Yacovlev's avatar Victor Yacovlev

Qt non-latin shortcuts bug workaround (#kumir2-1769)

parent e4c98df2
...@@ -15,6 +15,7 @@ else() ...@@ -15,6 +15,7 @@ else()
set(QT_USE_QTMAIN 1) set(QT_USE_QTMAIN 1)
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml REQUIRED) find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml REQUIRED)
include(${QT_USE_FILE}) include(${QT_USE_FILE})
add_definitions(-DQT_NONLATIN_SHORTCUTS_BUG)
endif() endif()
include(../../kumir2_plugin.cmake) include(../../kumir2_plugin.cmake)
......
...@@ -407,6 +407,25 @@ void EditorInstance::updateInsertMenu() ...@@ -407,6 +407,25 @@ void EditorInstance::updateInsertMenu()
editMacros_->setEnabled(userMacros_.size() > 0); editMacros_->setEnabled(userMacros_.size() > 0);
} }
bool EditorInstance::tryEscKeyAction(const QString &text)
{
if (text.length()!=1 && text.at(0).toAscii()) {
return false; // workarund required only for non-latin keys
}
const QList<Macro> allMacros = systemMacros_ + userMacros_;
const QChar ch = text.at(0);
foreach (const Macro & m, allMacros) {
bool keyMatch = m.key == ch;
bool enabled = m.action && m.action->isEnabled();
if (keyMatch && enabled) {
m.action->trigger();
return true;
}
}
return false;
}
void EditorInstance::playMacro() void EditorInstance::playMacro()
{ {
QAction * a = qobject_cast<QAction*>(sender()); QAction * a = qobject_cast<QAction*>(sender());
......
...@@ -101,6 +101,7 @@ public slots: ...@@ -101,6 +101,7 @@ public slots:
void changeGlobalState(quint32 prevv, quint32 currentt); void changeGlobalState(quint32 prevv, quint32 currentt);
void updateSettings(const QStringList & keys); void updateSettings(const QStringList & keys);
void updateInsertMenu(); void updateInsertMenu();
bool tryEscKeyAction(const QString & text);
signals: signals:
void urlsDragAndDropped(const QList<QUrl> &); void urlsDragAndDropped(const QList<QUrl> &);
......
...@@ -44,6 +44,7 @@ EditorPlane::EditorPlane(EditorInstance * editor) ...@@ -44,6 +44,7 @@ EditorPlane::EditorPlane(EditorInstance * editor)
, pnt_dropPosCorner(QPoint(-1000, -1000)) , pnt_dropPosCorner(QPoint(-1000, -1000))
, selectionInProgressFlag_(false) , selectionInProgressFlag_(false)
, marginHintBox_(new QLabel(this, Qt::ToolTip)) , marginHintBox_(new QLabel(this, Qt::ToolTip))
, escPressFlag_(false)
{ {
if (editor->analizer()) { if (editor->analizer()) {
caseInsensitive_ = editor->analizer()->plugin()->caseInsensitiveGrammatic(); caseInsensitive_ = editor->analizer()->plugin()->caseInsensitiveGrammatic();
...@@ -124,6 +125,7 @@ void EditorPlane::contextMenuEvent(QContextMenuEvent *e) ...@@ -124,6 +125,7 @@ void EditorPlane::contextMenuEvent(QContextMenuEvent *e)
*/ */
void EditorPlane::mousePressEvent(QMouseEvent *e) void EditorPlane::mousePressEvent(QMouseEvent *e)
{ {
escPressFlag_ = false;
emit message(QString()); emit message(QString());
// Ensure auto scrolling by timer is stopped // Ensure auto scrolling by timer is stopped
emit requestAutoScroll(0); emit requestAutoScroll(0);
...@@ -1220,6 +1222,13 @@ void EditorPlane::keyReleaseEvent(QKeyEvent *e) ...@@ -1220,6 +1222,13 @@ void EditorPlane::keyReleaseEvent(QKeyEvent *e)
if (e->key()==Qt::Key_Shift || (e->key()==-1 && e->modifiers() & Qt::ShiftModifier)) { if (e->key()==Qt::Key_Shift || (e->key()==-1 && e->modifiers() & Qt::ShiftModifier)) {
Utils::shiftKeyPressed = false; Utils::shiftKeyPressed = false;
} }
if (Qt::Key_Escape == e->key() && e->modifiers() == 0)
{
escPressFlag_ = true;
}
else {
escPressFlag_ = false;
}
if (editor_->cursor()->isEnabled()) { if (editor_->cursor()->isEnabled()) {
e->accept(); e->accept();
} }
...@@ -1513,11 +1522,17 @@ void EditorPlane::keyPressEvent(QKeyEvent *e) ...@@ -1513,11 +1522,17 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
!e->modifiers().testFlag(Qt::ControlModifier) && !e->modifiers().testFlag(Qt::ControlModifier) &&
!ignoreTextEvent !ignoreTextEvent
) { ) {
editor_->cursor()->evaluateCommand(Utils::textByKey(Qt::Key(e->key()) bool escSequence = false;
, e->text() #ifdef QT_NONLATIN_SHORTCUTS_BUG
, e->modifiers().testFlag(Qt::ShiftModifier) escSequence = escPressFlag_ && editor_->tryEscKeyAction(e->text());
, editor_->isTeacherMode() && editor_->analizer() #endif
)); if (!escSequence) {
editor_->cursor()->evaluateCommand(Utils::textByKey(Qt::Key(e->key())
, e->text()
, e->modifiers().testFlag(Qt::ShiftModifier)
, editor_->isTeacherMode() && editor_->analizer()
));
}
} }
Qt::Key tempSwichLayoutKey = Qt::Key( Qt::Key tempSwichLayoutKey = Qt::Key(
...@@ -1534,6 +1549,7 @@ void EditorPlane::keyPressEvent(QKeyEvent *e) ...@@ -1534,6 +1549,7 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
} }
findCursor(); findCursor();
} }
escPressFlag_ = false;
if (e->key()>=Qt::Key_F1 && e->key()<=Qt::Key_F35) if (e->key()>=Qt::Key_F1 && e->key()<=Qt::Key_F35)
e->ignore(); e->ignore();
else else
......
...@@ -120,6 +120,7 @@ private: ...@@ -120,6 +120,7 @@ private:
QList<QAction*> contextMenuActions_; QList<QAction*> contextMenuActions_;
QLabel * marginHintBox_; QLabel * marginHintBox_;
bool escPressFlag_;
signals: signals:
void urlsDragAndDropped(const QList<QUrl> &); void urlsDragAndDropped(const QList<QUrl> &);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment