summaryrefslogtreecommitdiff
path: root/inputmethods/multikey/keyboard.cpp
Side-by-side diff
Diffstat (limited to 'inputmethods/multikey/keyboard.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--inputmethods/multikey/keyboard.cpp42
1 files changed, 37 insertions, 5 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 2ce6dd3..aec0ad3 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -2,133 +2,136 @@
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "keyboard.h"
#include "configdlg.h"
#include <qpe/global.h>
#include <qpe/qcopenvelope_qws.h>
#include <qwindowsystem_qws.h>
#include <qpainter.h>
#include <qfontmetrics.h>
#include <qtimer.h>
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
#include <ctype.h>
-#include <qfile.h>
+#include <qdir.h>
#include <qtextstream.h>
#include <qstringlist.h>
#include <sys/utsname.h>
using namespace MultiKey;
static const char * const kb_config_xpm[] = {
"13 7 2 1",
" c None",
". c #000000",
" ",
" . ",
" ... ",
" ..... ",
" . ",
" . ",
" "};
/* Keyboard::Keyboard {{{1 */
Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
QFrame(parent, _name, f), shift(0), lock(0), ctrl(0), alt(0),
meta(0), circumflex(0), diaeresis(0), baccent(0), accent(0),
useLargeKeys(TRUE), usePicks(0), useRepeat(0),
pressedKeyRow(-1), pressedKeyCol(-1),
unicode(-1), qkeycode(0), modifiers(0), schar(0), mchar(0), echar(0),
configdlg(0)
{
// get the default font
Config *config = new Config( "qpe" );
config->setGroup( "Appearance" );
QString familyStr = config->readEntry( "FontFamily", "smallsmooth" );
delete config;
config = new Config("multikey");
config->setGroup ("general");
usePicks = config->readBoolEntry ("usePickboard", 0); // default closed
useRepeat = config->readBoolEntry ("useRepeat", 1);
delete config;
setFont( QFont( familyStr, 10 ) );
picks = new KeyboardPicks( this );
picks->setFont( QFont( familyStr, 10 ) );
picks->initialise();
if (usePicks) {
QObject::connect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
} else picks->hide();
loadKeyboardColors();
keys = new Keys();
repeatTimer = new QTimer( this );
connect( repeatTimer, SIGNAL(timeout()), this, SLOT(repeat()) );
+ QCopChannel* kbdChannel = new QCopChannel("MultiKey/Keyboard", this);
+ connect(kbdChannel, SIGNAL(received(const QCString &, const QByteArray &)),
+ this, SLOT(receive(const QCString &, const QByteArray &)));
}
Keyboard::~Keyboard() {
if ( configdlg ) {
- delete (ConfigDlg *) configdlg;
+ delete configdlg;
configdlg = 0;
}
}
/* Keyboard::resizeEvent {{{1 */
void Keyboard::resizeEvent(QResizeEvent*)
{
int ph = picks->sizeHint().height();
picks->setGeometry( 0, 0, width(), ph );
keyHeight = (height()-(usePicks ? ph : 0))/(keys->rows()?keys->rows():1);
int nk; // number of keys?
if ( useLargeKeys ) {
nk = 15;
} else {
nk = 19;
}
defaultKeyWidth = (width()/nk)/2;
xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
}
/* KeyboardPicks::initialize {{{1 */
void KeyboardPicks::initialise()
{
setSizePolicy(QSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed));
mode = 0;
dc = new KeyboardConfig(this);
configs.append(dc);
}
@@ -388,81 +391,83 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
}
else {
// back accent
qkeycode = 0x2002;
}
}
// Accent character support
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;
+ delete 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()));
+ connect(configdlg, SIGNAL(reloadSw()),
+ this, SLOT(reloadSw()));
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;
@@ -731,64 +736,75 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
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);
}
+void Keyboard::receive(const QCString &msg, const QByteArray &data)
+{
+ if (msg == "setmultikey(QString)") {
+ QDataStream stream(data, IO_ReadOnly);
+ QString map;
+ stream >> map;
+ setMapToFile(map);
+ } else if (msg == "getmultikey()") {
+ reloadSw();
+ }
+}
/* 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);
}
if (alt && alt != 0) {
*alt = 0;
alt = 0;
repaint(FALSE);
@@ -882,79 +898,95 @@ void Keyboard::togglePickboard(bool 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());
//adjustSize();
QObject::disconnect( picks, SIGNAL(key(ushort,ushort,ushort,bool,bool) ),
this, SIGNAL(key(ushort,ushort,ushort,bool,bool)) );
}
/*
* this closes && opens the input method
*/
QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
}
void Keyboard::toggleRepeat(bool on) {
useRepeat = on;
//cout << "setting useRepeat to: " << useRepeat << "\n";
}
void Keyboard::cleanupConfigDlg() {
if ( configdlg ) {
- delete (ConfigDlg *) configdlg;
+ delete configdlg;
configdlg = 0;
}
}
+void Keyboard::reloadSw() {
+ QCopEnvelope e("MultiKey/Switcher", "setsw(QString,QString)");
+
+ Config* config = new Config("multikey");
+ config->setGroup("keymaps");
+ QString current_map = config->readEntry("current", "en.keymap");
+ delete config;
+
+ e << ConfigDlg::loadSw().join("|") << current_map;
+}
+
/* Keyboard::setMapTo ... {{{1 */
void Keyboard::setMapToDefault() {
/* load current locale language map */
Config *config = new Config("locale");
config->setGroup( "Language" );
QString l = config->readEntry( "Language" , "en" );
delete config;
+ /* if Language represents as en_US, ru_RU, etc... */
+ int d = l.find('_');
+ if (d != -1) {
+ l.remove(d, l.length()-d);
+ }
QString key_map = QPEApplication::qpeDir() + "share/multikey/"
+ l + ".keymap";
/* save change to multikey config file */
config = new Config("multikey");
config->setGroup ("keymaps");
config->writeEntry ("current", key_map); // default closed
delete config;
int prevRows = keys->rows();
delete keys;
keys = new Keys(key_map);
// have to repaint the keyboard
if (prevRows != keys->rows()) {
QCopChannel::send ("QPE/TaskBar", "hideInputMethod()");
QCopChannel::send ("QPE/TaskBar", "showInputMethod()");
} else repaint(FALSE);
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
@@ -1477,65 +1509,65 @@ void Keys::setKeysFromFile(const char * filename) {
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);
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
+ // other variables like lang & title & sw
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();
} else {
// We couldnt find the selected keymap, give them a configure button
QImage * btn = new QImage((const char ** )kb_config_xpm);