Skip to content
Permalink
Browse files

Add basic dead key support to mythuitextedit. Implemented from scratc…

…h because I couldn't see a way of getting QT to handle it. To start with the following characters are supported, but if patches are provided I will add more - áâàãäå éêèë ç íîìï ñ óôòõö úûùü ýÿ . Fixes #8304
  • Loading branch information
stuartm committed Mar 2, 2012
1 parent c3544ed commit d84d5c98d414ce889d47b5114240c28061f85c62
Showing with 96 additions and 4 deletions.
  1. +94 −4 mythtv/libs/libmythui/mythuitextedit.cpp
  2. +2 −0 mythtv/libs/libmythui/mythuitextedit.h
@@ -7,6 +7,7 @@
#include <QChar>
#include <QKeyEvent>
#include <QDomDocument>
#include <Qt>

// libmythbase headers
#include "mythlogging.h"
@@ -17,6 +18,7 @@
#include "mythmainwindow.h"
#include "mythfontproperties.h"
#include "mythuihelper.h"
#include <qnamespace.h>

#define LOC QString("MythUITextEdit: ")

@@ -49,6 +51,8 @@ MythUITextEdit::MythUITextEdit(MythUIType *parent, const QString &name)
m_initialized = false;

m_lastKeyPress.start();

m_composeKey = 0;
}

MythUITextEdit::~MythUITextEdit()
@@ -345,16 +349,102 @@ void MythUITextEdit::PasteTextFromClipboard(QClipboard::Mode mode)
InsertText(clipboard->text(mode));
}

bool MythUITextEdit::keyPressEvent(QKeyEvent *e)
typedef QPair<int, int> keyCombo;
static QMap<keyCombo, int> gDeadKeyMap;

static void LoadDeadKeys(QMap<QPair<int, int>, int> &map)
{
// Dead key // Key // Result
map[keyCombo(Qt::Key_Dead_Grave, Qt::Key_A)] = Qt::Key_Agrave;
map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_A)] = Qt::Key_Aacute;
map[keyCombo(Qt::Key_Dead_Circumflex, Qt::Key_A)] = Qt::Key_Acircumflex;
map[keyCombo(Qt::Key_Dead_Tilde, Qt::Key_A)] = Qt::Key_Atilde;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_A)] = Qt::Key_Adiaeresis;
map[keyCombo(Qt::Key_Dead_Abovering, Qt::Key_A)] = Qt::Key_Aring;

map[keyCombo(Qt::Key_Dead_Cedilla, Qt::Key_C)] = Qt::Key_Ccedilla;

map[keyCombo(Qt::Key_Dead_Grave, Qt::Key_E)] = Qt::Key_Egrave;
map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_E)] = Qt::Key_Eacute;
map[keyCombo(Qt::Key_Dead_Circumflex, Qt::Key_E)] = Qt::Key_Ecircumflex;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_E)] = Qt::Key_Ediaeresis;

map[keyCombo(Qt::Key_Dead_Grave, Qt::Key_I)] = Qt::Key_Igrave;
map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_I)] = Qt::Key_Iacute;
map[keyCombo(Qt::Key_Dead_Circumflex, Qt::Key_I)] = Qt::Key_Icircumflex;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_I)] = Qt::Key_Idiaeresis;

map[keyCombo(Qt::Key_Dead_Tilde, Qt::Key_N)] = Qt::Key_Ntilde;

map[keyCombo(Qt::Key_Dead_Grave, Qt::Key_O)] = Qt::Key_Ograve;
map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_O)] = Qt::Key_Oacute;
map[keyCombo(Qt::Key_Dead_Circumflex, Qt::Key_O)] = Qt::Key_Ocircumflex;
map[keyCombo(Qt::Key_Dead_Tilde, Qt::Key_O)] = Qt::Key_Otilde;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_O)] = Qt::Key_Odiaeresis;

map[keyCombo(Qt::Key_Dead_Grave, Qt::Key_U)] = Qt::Key_Ugrave;
map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_U)] = Qt::Key_Uacute;
map[keyCombo(Qt::Key_Dead_Circumflex, Qt::Key_U)] = Qt::Key_Ucircumflex;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_U)] = Qt::Key_Udiaeresis;

map[keyCombo(Qt::Key_Dead_Acute, Qt::Key_Y)] = Qt::Key_Yacute;
map[keyCombo(Qt::Key_Dead_Diaeresis, Qt::Key_Y)] = Qt::Key_ydiaeresis;

return;
}

bool MythUITextEdit::keyPressEvent(QKeyEvent *event)
{
m_lastKeyPress.restart();

QStringList actions;
bool handled = false;

handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions, false);
handled = GetMythMainWindow()->TranslateKeyPress("Global", event, actions,
false);

Qt::KeyboardModifiers modifiers = event->modifiers();
int keynum = event->key();

if (keynum >= Qt::Key_Shift && keynum <= Qt::Key_CapsLock)
return false;

QString character;
// Compose key handling
// Enter composition mode
if ((modifiers & Qt::GroupSwitchModifier) &&
(keynum >= Qt::Key_Dead_Grave) && (keynum <= Qt::Key_Dead_Horn))
{
m_composeKey = keynum;
handled = true;
}
else if (m_composeKey > 0) // 'Compose' the key
{
if (gDeadKeyMap.isEmpty())
LoadDeadKeys(gDeadKeyMap);

LOG(VB_GUI, LOG_DEBUG, QString("Compose key: %1 Key: %2").arg(QString::number(m_composeKey, 16)).arg(QString::number(keynum, 16)));

if (gDeadKeyMap.contains(keyCombo(m_composeKey, keynum)))
{
int keycode = gDeadKeyMap.value(keyCombo(m_composeKey, keynum));

//QKeyEvent key(QEvent::KeyPress, keycode, modifiers);
character = QChar(keycode);

if (modifiers & Qt::ShiftModifier)
character = character.toUpper();
else
character = character.toLower();
LOG(VB_GUI, LOG_DEBUG, QString("Founding match for dead-key combo - %1").arg(character));
}
m_composeKey = 0;
}

if (character.isEmpty())
character = event->text();

if (!handled && InsertCharacter(e->text()))
if (!handled && InsertCharacter(character))
handled = true;

for (int i = 0; i < actions.size() && !handled; i++)
@@ -379,7 +469,7 @@ bool MythUITextEdit::keyPressEvent(QKeyEvent *e)
{
RemoveCharacter(m_Position);
}
else if (action == "SELECT" && e->key() != Qt::Key_Space
else if (action == "SELECT" && keynum != Qt::Key_Space
&& GetMythDB()->GetNumSetting("UseVirtualKeyboard", 1) == 1)
{
MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
@@ -102,6 +102,8 @@ class MUI_PUBLIC MythUITextEdit : public MythUIType, public StorageUser
MythUIStateType *m_backgroundState;
MythUIImage *m_cursorImage;
MythUIText *m_Text;

int m_composeKey;
};

#endif

0 comments on commit d84d5c9

Please sign in to comment.
You can’t perform that action at this time.