summaryrefslogtreecommitdiff
path: root/meego/qt-translate.cpp
blob: c0917784aaf2df17ed4a37e03d2e42753336e440 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (C) 2010, Intel Corporation.
 *
 * Author: Raymond Liu <raymond.liu@intel.com>
 * 
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * version 2.1 as published by the Free Software Foundation.
 * 
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA
 */

#include "debug.h"

#include <QEvent>
#include <QKeyEvent>

#include "qt-keysym-map.h"

#include "qt-translate.h"

enum {
	ShiftModifier = 1 << 0,
	ControlModifier = 1 << 2,
	AltModifier = 1 << 3
};
#define SHIFT_MASK 1 << 0)

void meego_im_key_event_decode(MeegoImKeyEvent *e, int type, int key, int modifiers, char *text)
{
	g_warn_if_fail(type == QEvent::KeyPress || type == QEvent::KeyRelease);
	e->release = type == QEvent::KeyRelease;

	e->state = 0;
	if (modifiers & Qt::ShiftModifier)
		e->state |= ShiftModifier;
	if (modifiers & Qt::ControlModifier)
		e->state |= ControlModifier;
	if (modifiers & Qt::AltModifier)
		e->state |= AltModifier;

	e->keysym = QtKeyToXKeySym(key);

	if (text && strlen(text) > 0) {
		e->text = text;
	}
}

void meego_im_key_event_encode(const MeegoImKeyEvent *e, int *type, int *key, int *modifiers, char **text)
{
	*type = e->release ? QEvent::KeyRelease : QEvent::KeyPress;
	*key = XKeySymToQTKey(e->keysym);
	*modifiers = Qt::NoModifier;
	if (e->state & ShiftModifier)
		*modifiers |= Qt::ShiftModifier;
	if (e->state & ControlModifier)
		*modifiers |= Qt::ControlModifier;
	if (e->state & AltModifier)
		*modifiers |= Qt::AltModifier;
	*text = e->text && strlen(e->text) > 0 ? e->text : NULL;
}