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()
set(QT_USE_QTMAIN 1)
find_package(Qt4 4.7.0 COMPONENTS QtCore QtGui QtXml REQUIRED)
include(${QT_USE_FILE})
add_definitions(-DQT_NONLATIN_SHORTCUTS_BUG)
endif()
include(../../kumir2_plugin.cmake)
......
......@@ -407,6 +407,25 @@ void EditorInstance::updateInsertMenu()
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()
{
QAction * a = qobject_cast<QAction*>(sender());
......
......@@ -101,6 +101,7 @@ public slots:
void changeGlobalState(quint32 prevv, quint32 currentt);
void updateSettings(const QStringList & keys);
void updateInsertMenu();
bool tryEscKeyAction(const QString & text);
signals:
void urlsDragAndDropped(const QList<QUrl> &);
......
......@@ -44,6 +44,7 @@ EditorPlane::EditorPlane(EditorInstance * editor)
, pnt_dropPosCorner(QPoint(-1000, -1000))
, selectionInProgressFlag_(false)
, marginHintBox_(new QLabel(this, Qt::ToolTip))
, escPressFlag_(false)
{
if (editor->analizer()) {
caseInsensitive_ = editor->analizer()->plugin()->caseInsensitiveGrammatic();
......@@ -124,6 +125,7 @@ void EditorPlane::contextMenuEvent(QContextMenuEvent *e)
*/
void EditorPlane::mousePressEvent(QMouseEvent *e)
{
escPressFlag_ = false;
emit message(QString());
// Ensure auto scrolling by timer is stopped
emit requestAutoScroll(0);
......@@ -1220,6 +1222,13 @@ void EditorPlane::keyReleaseEvent(QKeyEvent *e)
if (e->key()==Qt::Key_Shift || (e->key()==-1 && e->modifiers() & Qt::ShiftModifier)) {
Utils::shiftKeyPressed = false;
}
if (Qt::Key_Escape == e->key() && e->modifiers() == 0)
{
escPressFlag_ = true;
}
else {
escPressFlag_ = false;
}
if (editor_->cursor()->isEnabled()) {
e->accept();
}
......@@ -1513,12 +1522,18 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
!e->modifiers().testFlag(Qt::ControlModifier) &&
!ignoreTextEvent
) {
bool escSequence = false;
#ifdef QT_NONLATIN_SHORTCUTS_BUG
escSequence = escPressFlag_ && editor_->tryEscKeyAction(e->text());
#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(
editor_->mySettings()->value(
......@@ -1534,6 +1549,7 @@ void EditorPlane::keyPressEvent(QKeyEvent *e)
}
findCursor();
}
escPressFlag_ = false;
if (e->key()>=Qt::Key_F1 && e->key()<=Qt::Key_F35)
e->ignore();
else
......
......@@ -120,6 +120,7 @@ private:
QList<QAction*> contextMenuActions_;
QLabel * marginHintBox_;
bool escPressFlag_;
signals:
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