summaryrefslogtreecommitdiff
path: root/inputmethods
Side-by-side diff
Diffstat (limited to 'inputmethods') (more/less context) (show whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp57
1 files changed, 33 insertions, 24 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index de3aa52..08318bd 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -271,210 +271,212 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col)
else if (baccent && keys->baccent(keys->shift(c)))
c = keys->baccent(keys->shift(c));
else if (accent && keys->accent(keys->shift(c)))
c = keys->accent(keys->shift(c));
else if (meta && keys->meta(keys->shift(c)))
c = keys->meta(keys->shift(c));
else
c = keys->shift(c);
else if (meta && keys->meta(c))
c = keys->meta(c);
else if (circumflex && keys->circumflex(c))
c = keys->circumflex(c);
else if (baccent && keys->baccent(c))
c = keys->baccent(c);
else if (accent && keys->accent(c))
c = keys->accent(c);
else if (diaeresis && (keys->diaeresis(c) || c == 0x2c6)) {
if (c == 0x2c6)
c = 0xa8;
else
c = keys->diaeresis(c);
}
p.drawText(x, y,
keyWidthPix + 3, keyHeight,
AlignCenter, (QChar)c);
}
else {
// center the image in the middle of the key
pix->setColor(1, textcolor.rgb());
p.drawImage( x + (keyWidthPix - pix->width())/2 + 1,
y + (keyHeight - pix->height())/2 + 1,
QImage(*pix) );
}
p.setPen(keycolor_lines);
p.drawLine(x, y, x, y + keyHeight);
x += keyWidthPix;
}
}
p.setPen(keycolor_lines);
p.drawLine(0, height() - 1, width(), height() - 1);
p.drawLine(width() - 1, 0, width() - 1, height());
}
}
/* Keyboard::mousePressEvent {{{1 */
void Keyboard::mousePressEvent(QMouseEvent *e)
{
int row = (e->y() - (usePicks ? picks->height() : 0)) / keyHeight + 1;
if (row > 5) row = 5;
// figure out the column
int col = 0;
for (int w = 0; e->x() >= w; col++)
if (col < keys->numKeys(row)) // it segfaults if it trys to read past numKeys
w += keys->width(row,col) * defaultKeyWidth;
else break;
if (col <= 0) return;
col --; // rewind one...
qkeycode = keys->qcode(row, col);
unicode = keys->uni(row, col);
// might need to repaint if two or more of the same keys.
// should be faster if just paint one key even though multiple keys exist.
bool need_repaint = FALSE;
// circumflex and diaeresis support
// messy to have this here, but too hard to implement any other method
if (unicode == 0x2c6) {
unicode = 0;
if (shift || lock) {
// diaeresis
qkeycode = 0x2001;
}
else {
// circumflex
qkeycode = 0x2000;
}
}
// Back accent character support
- if (unicode == 0x60) {
+ //if (unicode == 0x60) { // the keys from 2c6 ~ 2cf should be used instead of the ascii one
+ if (unicode == 0x2cb) {
unicode = 0;
if (shift || lock) {
// circumblex
qkeycode = 0x2000;
}
else {
// back accent
qkeycode = 0x2002;
}
}
// Accent character support
- if (unicode == 0xb4) {
+ //if (unicode == 0xb4) {
+ if (unicode == 0x2ca) {
unicode = 0;
if (shift || lock) {
// diaeresis
qkeycode = 0x2001;
}
else {
// accent
qkeycode = 0x2003;
}
}
if (unicode == 0) { // either Qt char, or nothing
if (qkeycode == Qt::Key_F1) { // toggle the pickboard
if ( configdlg ) {
delete (ConfigDlg *) configdlg;
configdlg = 0;
}
else {
configdlg = new ConfigDlg ();
connect(configdlg, SIGNAL(setMapToDefault()),
this, SLOT(setMapToDefault()));
connect(configdlg, SIGNAL(setMapToFile(QString)),
this, SLOT(setMapToFile(QString)));
connect(configdlg, SIGNAL(pickboardToggled(bool)),
this, SLOT(togglePickboard(bool)));
connect(configdlg, SIGNAL(repeatToggled(bool)),
this, SLOT(toggleRepeat(bool)));
connect(configdlg, SIGNAL(reloadKeyboard()),
this, SLOT(reloadKeyboard()));
connect(configdlg, SIGNAL(configDlgClosed()),
this, SLOT(cleanupConfigDlg()));
configdlg->showMaximized();
configdlg->show();
configdlg->raise();
}
} else if (qkeycode == Qt::Key_Control) {
need_repaint = TRUE;
if (ctrl) {
*ctrl = 0;
ctrl = 0;
} else {
ctrl = keys->pressedPtr(row, col);
need_repaint = TRUE;
*ctrl = !keys->pressed(row, col);
}
} else if (qkeycode == Qt::Key_Alt) {
need_repaint = TRUE;
if (alt) {
*alt = 0;
alt = 0;
} else {
alt = keys->pressedPtr(row, col);
need_repaint = TRUE;
*alt = !keys->pressed(row, col);
}
} else if (qkeycode == Qt::Key_Shift) {
need_repaint = TRUE;
if (shift) {
*shift = 0;
shift = 0;
}
else {
shift = keys->pressedPtr(row, col);
*shift = 1;
if (lock) {
*lock = 0;
lock = 0;
}
}
/*
* want to be able to hit circumflex/diaeresis -> shift
* to type in shifted circumflex/diaeresis chars.
* same thing with meta
if (meta) { *meta = 0; meta = 0; }
@@ -673,192 +675,199 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
else if (meta && keys->meta(unicode)) {
unicode = keys->meta(unicode);
}
else if (circumflex && keys->circumflex(unicode)) {
unicode = keys->circumflex(unicode);
}
else if (diaeresis && keys->diaeresis(unicode)) {
unicode = keys->diaeresis(unicode);
}
else if (baccent && keys->baccent(unicode)) {
unicode = keys->baccent(unicode);
}
else if (accent && keys->accent(unicode)) {
unicode = keys->accent(unicode);
}
}
// korean parsing
if (keys->lang == "ko") {
unicode = parseKoreanInput(unicode);
}
modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
if ('A' <= unicode && unicode <= 'z' && modifiers) {
qkeycode = QChar(unicode).upper();
unicode = qkeycode - '@';
}
QWSServer::sendKeyEvent(unicode, qkeycode, modifiers, true, false);
// pickboard stuff
if (usePicks) {
KeyboardConfig *dc = picks->dc;
if (dc) {
if (qkeycode == Qt::Key_Backspace) {
dc->input.remove(dc->input.last()); // remove last input
dc->decBackspaces();
} else if ( qkeycode == Qt::Key_Return || QChar(unicode).isPunct() || QChar(unicode).isSpace() || unicode == 0) {
dc->input.clear();
dc->resetBackspaces();
} else {
dc->add(QString(QChar(unicode)));
dc->incBackspaces();
}
}
picks->repaint();
}
// painting
pressed = TRUE;
pressedKeyRow = row;
pressedKeyCol = col;
if (need_repaint) repaint(FALSE);
else { // just paint the one key pressed
QPainter p(this);
drawKeyboard(p, row, col);
}
if (useRepeat) repeatTimer->start( 800 );
//pressTid = startTimer(80);
}
/* Keyboard::mouseReleaseEvent {{{1 */
void Keyboard::mouseReleaseEvent(QMouseEvent*)
{
pressed = FALSE;
//if ( pressTid == 0 )
#if defined(Q_WS_QWS) || defined(_WS_QWS_)
if ( unicode != -1 ) {
emit key( unicode, qkeycode, modifiers, false, false );
repeatTimer->stop();
}
#endif
if (shift && unicode != 0) {
*shift = 0; // unpress shift key
shift = 0; // reset the shift pointer
repaint(FALSE);
}
+ if (ctrl && unicode != 0) {
+
+ *ctrl = 0;
+ ctrl = 0;
+ repaint(FALSE);
+
+ }
/*
* do not make the meta key release after being pressed
*
else if (meta && unicode != 0) {
*meta = 0;
meta = 0;
repaint(FALSE);
}
*/
else clearHighlight();
}
/* Keyboard::timerEvent {{{1 */
/* dont know what this does, but i think it is here so that if your screen
* sticks (like on an ipaq) then it will stop repeating if you click another
* key... but who knows what anything does in this thing anyway?
void Keyboard::timerEvent(QTimerEvent* e)
{
if ( e->timerId() == pressTid ) {
killTimer(pressTid);
pressTid = 0;
if ( !pressed )
cout << "calling clearHighlight from timerEvent\n";
//clearHighlight();
}
}
*/
void Keyboard::repeat()
{
repeatTimer->start( 200 );
emit key( unicode, qkeycode, modifiers, true, true );
}
void Keyboard::clearHighlight()
{
if ( pressedKeyRow >= 0 && pressedKeyCol >= 0) {
int tmpRow = pressedKeyRow;
int tmpCol = pressedKeyCol;
pressedKeyRow = -1;
pressedKeyCol = -1;
QPainter p(this);
drawKeyboard(p, tmpRow, tmpCol);
}
}
/* Keyboard::sizeHint {{{1 */
QSize Keyboard::sizeHint() const
{
QFontMetrics fm=fontMetrics();
int keyHeight = fm.lineSpacing() + 2;
return QSize( 240, keyHeight * keys->rows() + (usePicks ? picks->sizeHint().height() : 0) + 1);
}
void Keyboard::resetState()
{
if (shift) { *shift = 0; shift = 0; }
if (lock) {*lock = 0; lock = 0; }
if (meta) { *meta = 0; meta = 0; }
if (circumflex) { *circumflex = 0; circumflex = 0; }
if (diaeresis) { *diaeresis = 0; diaeresis = 0; }
if (baccent) { *baccent = 0; baccent = 0; }
if (accent) { *accent = 0; accent = 0; }
schar = mchar = echar = 0;
picks->resetState();
}
/* Keyboard::togglePickboard {{{1 */
void Keyboard::togglePickboard(bool on_off)
{
usePicks = on_off;
if (usePicks) {
picks->show();
//move(x(), y() - picks->height()); // not required anymore because QCopChannel::send
//adjustSize();
QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
} else {
picks->hide();
picks->resetState();
//move(x(), y() + picks->height());
@@ -922,277 +931,277 @@ void Keyboard::setMapToDefault() {
resetState();
}
void Keyboard::setMapToFile(QString map) {
/* save change to multikey config file */
Config *config = new Config("multikey");
config->setGroup ("keymaps");
config->writeEntry ("current", map); // default closed
delete config;
int prevRows = keys->rows();
delete keys;
if (QFile(map).exists())
keys = new Keys(map);
else
keys = new Keys();
if (keys->rows() != prevRows) {
QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
}
else repaint(FALSE);
resetState();
}
/* Keybaord::reloadKeyboard {{{1 */
void Keyboard::reloadKeyboard() {
// reload colors and redraw
loadKeyboardColors();
repaint();
}
void Keyboard::loadKeyboardColors() {
Config config ("multikey");
config.setGroup("colors");
QStringList color;
color = config.readListEntry("keycolor", QChar(','));
if (color.isEmpty()) {
color = QStringList::split(",", "240,240,240");
config.writeEntry("keycolor", color.join(","));
}
keycolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
color = config.readListEntry("keycolor_pressed", QChar(','));
if (color.isEmpty()) {
color = QStringList::split(",", "171,183,198");
config.writeEntry("keycolor_pressed", color.join(","));
}
keycolor_pressed = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
color = config.readListEntry("keycolor_lines", QChar(','));
if (color.isEmpty()) {
color = QStringList::split(",", "138,148,160");
config.writeEntry("keycolor_lines", color.join(","));
}
keycolor_lines = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
color = config.readListEntry("textcolor", QChar(','));
if (color.isEmpty()) {
color = QStringList::split(",", "43,54,68");
config.writeEntry("textcolor", color.join(","));
}
textcolor = QColor(color[0].toInt(), color[1].toInt(), color[2].toInt());
}
/* korean input functions {{{1
*
* TODO
* one major problem with this implementation is that you can't move the
* cursor after inputing korean chars, otherwise it will eat up and replace
* the char before the cursor you move to. fix that
*
* make backspace delete one single char, not the whole thing if still
* editing.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*
* how korean input works
*
* all following chars means unicode char value and are in hex
*
- * = schar (start char)
- * = mchar (middle char)
- * = echar (end char)
+ * 초음 = schar (start char)
+ * 중음 = mchar (middle char)
+ * 끝음 = echar (end char)
*
* there are 19 schars. unicode position is at 1100 - 1112
* there are 21 mchars. unicode position is at 1161 - 1175
* there are 27 echars. unicode position is at 11a8 - 11c2
*
* the map with everything combined is at ac00 - d7a3
*
*/
ushort Keyboard::parseKoreanInput (ushort c) {
if ((c != 0 && (c < 0x1100 || 0x11c2 < c) && (c < 0xac00 || 0xd7a3 < c))
||
(c == 0 && qkeycode != Qt::Key_Shift && Qt::Key_CapsLock != qkeycode
&& qkeycode != Qt::Key_Control && qkeycode != Qt::Key_Alt)) {
schar = 0, mchar = 0, echar = 0;
return c;
}
if ( 0x1100 <= c && c <= 0x1112 ) { // schar or echar was input
if (schar == 0 || (schar != 0 && mchar == 0)) {
schar = c; mchar = 0; echar = 0;
return c;
}
else if (mchar != 0) {
if (echar == 0) {
if (!(echar = constoe(c))) {
schar = c; mchar = 0; echar = 0;
return c;
}
}
else { // must figure out what the echar is
- if (echar == 0x11a8) { //
+ if (echar == 0x11a8) { // ㄱ
- if (c == 0x1100) echar = 0x11a9; // +
- else if (c == 0x1109) echar = 0x11aa; // +
+ if (c == 0x1100) echar = 0x11a9; // ㄱ + ㄱ
+ else if (c == 0x1109) echar = 0x11aa; // ㄱ + ㅅ
else {
schar = c; mchar = 0; echar = 0;
return c;
}
- } else if (echar == 0x11ab) { //
+ } else if (echar == 0x11ab) { // ㄴ
- if (c == 0x110c) echar = 0x11ac; // +
- else if (c == 0x1112) echar = 0x11ad; // +
+ if (c == 0x110c) echar = 0x11ac; // ㄴ + ㅈ
+ else if (c == 0x1112) echar = 0x11ad; // ㄴ + ㅎ
else {
schar = c; mchar = 0; echar = 0;
return c;
}
- } else if (echar == 0x11af) { //
+ } else if (echar == 0x11af) { // ㄹ
- if (c == 0x1100) echar = 0x11b0; // +
- else if (c == 0x1106) echar = 0x11b1; // +
- else if (c == 0x1107) echar = 0x11b2; // +
- else if (c == 0x1109) echar = 0x11b3; // +
- else if (c == 0x1110) echar = 0x11b4; // +
- else if (c == 0x1111) echar = 0x11b5; // +
- else if (c == 0x1112) echar = 0x11b6; // +
+ if (c == 0x1100) echar = 0x11b0; // ㄹ + ㄱ
+ else if (c == 0x1106) echar = 0x11b1; // ㄹ + ㅁ
+ else if (c == 0x1107) echar = 0x11b2; // ㄹ + ㅂ
+ else if (c == 0x1109) echar = 0x11b3; // ㄹ + ㅅ
+ else if (c == 0x1110) echar = 0x11b4; // ㄹ + ㅌ
+ else if (c == 0x1111) echar = 0x11b5; // ㄹ + ㅍ
+ else if (c == 0x1112) echar = 0x11b6; // ㄹ + ㅎ
else {
schar = c; mchar = 0; echar = 0;
return c;
}
- } else if (echar == 0x11b8) { //
+ } else if (echar == 0x11b8) { // ㅂ
- if (c == 0x1109) echar = 0x11b9; // +
+ if (c == 0x1109) echar = 0x11b9; // ㅂ + ㅅ
else {
schar = c; mchar = 0; echar = 0;
return c;
}
- } else if (echar == 0x11ba) { //
+ } else if (echar == 0x11ba) { // ㅅ
- if (c == 0x1109) echar = 0x11bb; // +
+ if (c == 0x1109) echar = 0x11bb; // ㅅ + ㅅ
else {
schar = c; mchar = 0; echar = 0;
return c;
}
} else { // if any other char, cannot combine chars
schar = c; mchar = 0; echar = 0;
return c;
}
unicode = echar;
}
}
}
else if (0x1161 <= c && c <= 0x1175) { // mchar was input
if (schar != 0 && mchar == 0) { mchar = c; }
else if (schar != 0 && mchar != 0 && echar == 0) {
switch (mchar) {
case 0x1169:
if (c == 0x1161) mchar = 0x116a;
else if (c == 0x1162) mchar = 0x116b;
else if (c == 0x1175) mchar = 0x116c;
else {
schar = 0; mchar = 0; echar = 0;
return c;
}
break;
case 0x116e:
if (c == 0x1165) mchar = 0x116f;
else if (c == 0x1166) mchar = 0x1170;
else if (c == 0x1175) mchar = 0x1171;
else {
schar = 0; mchar = 0; echar = 0;
return c;
}
break;
case 0x1173:
if (c == 0x1175) mchar = 0x1174;
else {
schar = 0; mchar = 0; echar = 0;
return c;
}
break;
default:
schar = 0; mchar = 0; echar = 0;
return c;
}
}
else if (schar != 0 && mchar != 0 && echar != 0) {
emit key( 8, Qt::Key_Backspace, 0, true, false );
ushort prev = 0;
switch (echar) {
/*
case 0x11a9:
prev = combineKoreanChars(schar, mchar, 0x11a8);
schar = 0x1100;
break;
*/
case 0x11aa:
prev = combineKoreanChars(schar, mchar, 0x11a8);
schar = 0x1109;
break;
case 0x11ac:
prev = combineKoreanChars(schar, mchar, 0x11ab);
schar = 0x110c;
break;
case 0x11ad:
prev = combineKoreanChars(schar, mchar, 0x11ab);
schar = 0x1112;
break;
case 0x11b0:
prev = combineKoreanChars(schar, mchar, 0x11af);
schar = 0x1100;
break;
case 0x11b1:
prev = combineKoreanChars(schar, mchar, 0x11af);
schar = 0x1106;
break;
case 0x11b2:
prev = combineKoreanChars(schar, mchar, 0x11af);
schar = 0x1107;
break;
case 0x11b3:
prev = combineKoreanChars(schar, mchar, 0x11af);
schar = 0x1109;
break;
case 0x11b4:
prev = combineKoreanChars(schar, mchar, 0x11af);
schar = 0x1110;
@@ -1369,193 +1378,193 @@ void Keys::setKeysFromFile(const char * filename) {
xpm2pix = 0;
// erase blank space
while (buf.contains(QRegExp("^\\s*$")) && buf) buf = t.readLine();
while (buf.contains(QRegExp("^\\s*\".*\""))) {
QString xpmBuf = buf.stripWhiteSpace();
xpm[xpmLineCount] = new char [xpmBuf.length()];
int j = 0;
for (ushort i = 0; i < xpmBuf.length(); i++) {
if (xpmBuf[i].latin1() != '"') {
((char *)xpm[xpmLineCount])[j] = xpmBuf.at(i).latin1();
j++;
}
}
// have to close that facker up
((char *)xpm[xpmLineCount])[j] = '\0';
xpmLineCount++;
buf = t.readLine();
}
if (xpmLineCount) {
xpm2pix = new QImage((const char **)xpm);
for (int i = 0; i < xpmLineCount; i++)
delete [] (xpm[i]);
}
setKey(row, qcode, unicode, width, xpm2pix);
}
// shift map
else if (buf.contains(QRegExp("^[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
tmp >> lower >> shift;
shiftMap.insert(lower, shift);
buf = t.readLine();
}
// meta key map
else if (buf.contains(QRegExp("^\\s*m\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
QChar m;
tmp >> m >> lower >> shift;
metaMap.insert(lower, shift);
buf = t.readLine();
}
// circumflex
else if (buf.contains(QRegExp("^\\s*c\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
QChar c;
tmp >> c >> lower >> shift;
circumflexMap.insert(lower, shift);
buf = t.readLine();
}
// diaeresis
else if (buf.contains(QRegExp("^\\s*d\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
QChar d;
tmp >> d >> lower >> shift;
diaeresisMap.insert(lower, shift);
buf = t.readLine();
}
// back accent
else if (buf.contains(QRegExp("^\\s*b\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
QChar d;
tmp >> d >> lower >> shift;
baccentMap.insert(lower, shift);
- qDebug ("Estoy aadiendo %i con %i", lower, shift);
+ qDebug ("Estoy aadiendo %i con %i", lower, shift);
buf = t.readLine();
}
// accent
else if (buf.contains(QRegExp("^\\s*a\\s+[0-9a-fx]+\\s+[0-9a-fx]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
ushort lower, shift;
QChar d;
tmp >> d >> lower >> shift;
accentMap.insert(lower, shift);
buf = t.readLine();
}
// other variables like lang & title
else if (buf.contains(QRegExp("^\\s*[a-zA-Z]+\\s*=\\s*[a-zA-Z0-9/]+\\s*$", FALSE, FALSE))) {
QTextStream tmp (buf, IO_ReadOnly);
QString name, equals, value;
tmp >> name >> equals >> value;
if (name == "lang") {
lang = value;
}
buf = t.readLine();
}
// comments
else if (buf.contains(QRegExp("^\\s*#"))) {
buf = t.readLine();
} else { // blank line, or garbage
buf = t.readLine();
}
}
f.close();
}
}
// Keys::setKey {{{2
void Keys::setKey(const int row, const int qcode, const ushort unicode,
const int width, QImage *pix) {
Key * key;
key = new Key;
key->qcode = qcode;
key->unicode = unicode;
key->width = width;
// share key->pressed between same keys
bool found = 0;
for (int i = 1; i <= 5; i++) {
for (unsigned int j = 0; j < keys[i].count(); j++)
if (keys[i].at(j)->qcode == qcode && keys[i].at(j)->unicode == unicode) {
key->pressed = keys[i].at(j)->pressed;
found = 1;
}
}
if (!found) {
key->pressed = new bool;
*(key->pressed) = 0;
}
key->pix = pix;
keys[row].append(key);
}
// Keys::~Keys {{{2
Keys::~Keys() {
for (int i = 1; i <= 5; i++)
for (unsigned int j = 0; j < keys[i].count(); j++)
delete keys[i].at(j);
}
// Keys:: other functions {{{2
int Keys::width(const int row, const int col) {
return keys[row].at(col)->width;
}