Commit 7e379f2f authored by Michel Ludwig's avatar Michel Ludwig
Browse files

Correctly convert special characters into LaTeX that were typed with caps lock enabled

This fix works from KDE 4.3 and upwards as the class 'KModifierKeyInfo' is used.

BUG: 296123
parent 6d16356f
......@@ -25,12 +25,19 @@
#include <KTextEditor/Document>
#include <KTextEditor/View>
#if KDE_IS_VERSION(4,3,0)
#include <KModifierKeyInfo>
#endif
#include "kiledebug.h"
#include "editorextension.h"
#include "kileconfig.h"
LaTeXEventFilter::LaTeXEventFilter(KTextEditor::View *view, KileDocument::EditorExtension *edit) : QObject(view), m_view(view), m_edit(edit)
{
#if KDE_IS_VERSION(4,3,0)
m_modifierKeyInfo = new KModifierKeyInfo(this);
#endif
readConfig();
}
......@@ -39,6 +46,17 @@ void LaTeXEventFilter::readConfig()
m_bCompleteEnvironment = KileConfig::completeEnvironment();
}
// querying the caps lock state directly is currrently not supported by Qt
bool LaTeXEventFilter::isCapsLockEnabled()
{
#if KDE_IS_VERSION(4,3,0)
return m_modifierKeyInfo->isKeyLatched(Qt::Key_CapsLock)
|| m_modifierKeyInfo->isKeyLocked(Qt::Key_CapsLock);
#else
return false;
#endif
}
//FIXME: there should be one central place to convert unicode chars to LaTeX;
// also see 'EditorExtension::insertLatexFromUnicode'.
// KateViewInternal as a child of KTextEditor::View has the focus
......@@ -58,7 +76,7 @@ bool LaTeXEventFilter::eventFilter(QObject* /* o */, QEvent *e)
}
if (e->type() == QEvent::KeyPress) {
QKeyEvent *ke = (QKeyEvent*) e;
QKeyEvent *ke = static_cast<QKeyEvent*>(e);
switch(ke->key())
{
case Qt::Key_QuoteDbl: return m_edit->insertDoubleQuotes(m_view);
......@@ -84,142 +102,142 @@ bool LaTeXEventFilter::eventFilter(QObject* /* o */, QEvent *e)
case Qt::Key_multiply: return m_edit->insertSpecialCharacter("\\times", m_view);
case Qt::Key_ssharp: return m_edit->insertSpecialCharacter("\\ss{}", m_view);
case Qt::Key_Agrave:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\`A", m_view);
}
else return m_edit->insertSpecialCharacter("\\`a", m_view);
case Qt::Key_Aacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'A", m_view);
}
else return m_edit->insertSpecialCharacter("\\'a", m_view);
case Qt::Key_Acircumflex:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\^A", m_view);
}
else return m_edit->insertSpecialCharacter("\\^a", m_view);
case Qt::Key_Atilde:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\~A", m_view);
}
else return m_edit->insertSpecialCharacter("\\~a", m_view);
case Qt::Key_Adiaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"A", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"a", m_view);
case Qt::Key_Aring:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\AA", m_view);
}
else return m_edit->insertSpecialCharacter("\\aa", m_view);
case Qt::Key_AE:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\AE", m_view);
}
else return m_edit->insertSpecialCharacter("\\ae", m_view);
case Qt::Key_Ccedilla:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\c{C}", m_view);
}
else return m_edit->insertSpecialCharacter("\\c{c}", m_view);
case Qt::Key_Egrave:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\`E", m_view);
}
else return m_edit->insertSpecialCharacter("\\`e", m_view);
case Qt::Key_Eacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'E", m_view);
}
else return m_edit->insertSpecialCharacter("\\'e", m_view);
case Qt::Key_Ecircumflex:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\^E", m_view);
}
else return m_edit->insertSpecialCharacter("\\^e", m_view);
case Qt::Key_Ediaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"E", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"e", m_view);
case Qt::Key_Igrave:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\`I", m_view);
}
else return m_edit->insertSpecialCharacter("\\`i", m_view);
case Qt::Key_Iacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'I", m_view);
}
else return m_edit->insertSpecialCharacter("\\'i", m_view);
case Qt::Key_Icircumflex:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\^I", m_view);
}
else return m_edit->insertSpecialCharacter("\\^i", m_view);
case Qt::Key_Idiaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"I", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"i", m_view);
case Qt::Key_Ntilde:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\~N", m_view);
}
else return m_edit->insertSpecialCharacter("\\~n", m_view);
case Qt::Key_Ograve:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\`O", m_view);
}
else return m_edit->insertSpecialCharacter("\\`o", m_view);
case Qt::Key_Oacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'O", m_view);
}
else return m_edit->insertSpecialCharacter("\\'o", m_view);
case Qt::Key_Ocircumflex:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\^O", m_view);
}
else return m_edit->insertSpecialCharacter("\\^o", m_view);
case Qt::Key_Otilde:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\~O", m_view);
}
else return m_edit->insertSpecialCharacter("\\~o", m_view);
case Qt::Key_Odiaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"O", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"o", m_view);
case Qt::Key_Ugrave:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\`U", m_view);
}
else return m_edit->insertSpecialCharacter("\\`u", m_view);
case Qt::Key_Uacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'U", m_view);
}
else return m_edit->insertSpecialCharacter("\\'u", m_view);
case Qt::Key_Ucircumflex:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\^U", m_view);
}
else return m_edit->insertSpecialCharacter("\\^u", m_view);
case Qt::Key_Udiaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"U", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"u", m_view);
case Qt::Key_Yacute:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\'Y", m_view);
}
else return m_edit->insertSpecialCharacter("\\'y", m_view);
case Qt::Key_ydiaeresis:
if (ke->modifiers() == Qt::ShiftModifier) {
if (ke->modifiers() == Qt::ShiftModifier || isCapsLockEnabled()) {
return m_edit->insertSpecialCharacter("\\\"Y", m_view);
}
else return m_edit->insertSpecialCharacter("\\\"y", m_view);
......
/***********************************************************************************************
Copyright (C) 2004 by Jeroen Wijnhout <Jeroen.Wijnhout@kdemail.net>
2008 by Michel Ludwig (michel.ludwig@kdemail.net)
2008-2012 by Michel Ludwig (michel.ludwig@kdemail.net)
***********************************************************************************************/
/***************************************************************************
......@@ -19,6 +19,10 @@
#include <QObject>
#include <QRegExp>
#include <kdeversion.h>
class KModifierKeyInfo;
namespace KTextEditor {class View; }
namespace KileDocument { class EditorExtension; }
......@@ -38,11 +42,16 @@ public Q_SLOTS:
protected:
bool eventFilter(QObject *o, QEvent *e);
bool isCapsLockEnabled();
private:
bool m_bCompleteEnvironment;
KTextEditor::View *m_view;
KileDocument::EditorExtension *m_edit;
#if KDE_IS_VERSION(4,3,0)
KModifierKeyInfo *m_modifierKeyInfo;
#endif
};
#endif
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