summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--inputmethods/multikey/configdlg.cpp31
-rw-r--r--inputmethods/multikey/configdlg.h3
-rw-r--r--inputmethods/multikey/keyboard.cpp37
-rw-r--r--inputmethods/multikey/keyboard.h2
4 files changed, 56 insertions, 17 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp
index 59a290b..566b2b9 100644
--- a/inputmethods/multikey/configdlg.cpp
+++ b/inputmethods/multikey/configdlg.cpp
@@ -66,160 +66,181 @@ ConfigDlg::ConfigDlg () : QTabWidget ()
keymaps->setSelected(i + 1, true);
}
}
custom_maps = config.readListEntry("maps", QChar('|'));
for (uint i = 0; i < custom_maps.count(); i++) {
if (map_dir.exists(QFileInfo(custom_maps[i]).fileName(), false)
|| !QFile::exists(custom_maps[i])) {
custom_maps.remove(custom_maps.at(i));
// remove it from the list too
config.writeEntry("maps", custom_maps.join("|"));
} else {
keymaps->insertItem(custom_maps[i]);
if (custom_maps[i] == current_map) {
keymaps->setSelected(map_dir.count() + i + 1, true);
}
}
}
// have to "+1" because the "current language" listItem... remember?
connect(keymaps, SIGNAL(highlighted(int)), SLOT(setMap(int)));
QGrid *add_remove_grid = new QGrid(2, map_group);
add_remove_grid->setMargin(3);
add_remove_grid->setSpacing(3);
add_button = new QPushButton(tr("Add"), add_remove_grid);
add_button->setFlat((bool)1);
connect(add_button, SIGNAL(clicked()), SLOT(addMap()));
remove_button = new QPushButton(tr("Remove"), add_remove_grid);
remove_button->setFlat((bool)1);
if ((int)map_dir.count() >= keymaps->currentItem())
remove_button->setDisabled(true);
connect(remove_button, SIGNAL(clicked()), SLOT(removeMap()));
- pick_button = new QCheckBox(tr("Pickboard"), gen_box);
+ // make a box that will contain the buttons on the bottom
+ QGrid *other_grid = new QGrid(2, gen_box);
+ pick_button = new QCheckBox(tr("Pickboard"), other_grid);
- config.setGroup ("pickboard");
- bool pick_open = config.readBoolEntry ("open", "0"); // default closed
+ config.setGroup ("general");
+ bool pick_open = config.readBoolEntry ("usePickboard", (bool)0); // default closed
if (pick_open) {
pick_button->setChecked(true);
}
// by connecting it after checking it, the signal isn't emmited
connect (pick_button, SIGNAL(clicked()), this, SLOT(pickTog()));
+ repeat_button = new QCheckBox(tr("Key Repeat"), other_grid);
+ bool repeat_on = config.readBoolEntry ("useRepeat", (bool)1);
+
+ if (repeat_on) {
+
+ repeat_button->setChecked(true);
+ }
+ connect (repeat_button, SIGNAL(clicked()), this, SLOT(repeatTog()));
+
+
/*
* 'color' tab
*/
QGrid *color_box = new QGrid(2, this);
color_box->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed));
color_box->setMargin(3);
color_box->setSpacing(3);
addTab(color_box, tr("Colors"));
QLabel *label;
QStringList color;
label = new QLabel(tr("Key Color"), color_box);
key_color_button = new QPushButton(color_box);
connect(key_color_button, SIGNAL(clicked()), SLOT(keyColorButtonClicked()));
key_color_button->setFlat((bool)1);
config.setGroup("colors");
color = config.readListEntry("keycolor", QChar(','));
if (color.isEmpty()) {
color = QStringList::split(",", "240,240,240");
config.writeEntry("keycolor", color.join(","));
}
key_color_button->setBackgroundColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt()));
label = new QLabel(tr("Key Pressed Color"), color_box);
QPushButton *button = new QPushButton(color_box);
button->setFlat((bool)1);
label = new QLabel(tr("Line Color"), color_box);
button = new QPushButton(color_box);
button->setFlat((bool)1);
label = new QLabel(tr("Text Color"), color_box);
button = new QPushButton(color_box);
button->setFlat((bool)1);
label = new QLabel("", color_box); // a spacer so the above buttons dont expand
label->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding));
}
void ConfigDlg::pickTog() {
Config config ("multikey");
- config.setGroup ("pickboard");
- config.writeEntry ("open", pick_button->isChecked()); // default closed
+ config.setGroup ("general");
+ config.writeEntry ("usePickboard", pick_button->isChecked()); // default closed
emit pickboardToggled(pick_button->isChecked());
}
+void ConfigDlg::repeatTog() {
+
+ Config config ("multikey");
+ config.setGroup ("general");
+ config.writeEntry ("useRepeat", repeat_button->isChecked()); // default closed
+
+ emit repeatToggled(repeat_button->isChecked());
+}
+
/*
* the index is kinda screwy, because in the config file, index 0 is just the
* first element in the QStringList, but here it's the "Current Language"
* listItem. therefor you have to minus one to the index before you access it.
*
*/
// ConfigDlg::setMap {{{1
void ConfigDlg::setMap(int index) {
if (index == 0) {
remove_button->setDisabled(true);
emit setMapToDefault();
}
else if ((uint)index <= default_maps.count()) {
remove_button->setDisabled(true);
emit setMapToFile(keymaps->text(index));
} else {
remove_button->setEnabled(true);
emit setMapToFile(keymaps->text(index));
}
}
// ConfigDlg::addMap() {{{1
void ConfigDlg::addMap() {
QString map = OFileDialog::getOpenFileName(1, QDir::home().absPath());
Config config ("multikey");
config.setGroup("keymaps");
QStringList maps = config.readListEntry("maps", QChar('|'));
maps.append(map);
keymaps->insertItem(map);
keymaps->setSelected(keymaps->count() - 1, true);
config.writeEntry("maps", maps, QChar('|'));
config.writeEntry("current", map);
}
// ConfigDlg::removeMap() {{{1
void ConfigDlg::removeMap() {
cout << "removing : " << custom_maps[keymaps->currentItem() - default_maps.count() - 1] << "\n";
diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h
index ae7afe2..a000e60 100644
--- a/inputmethods/multikey/configdlg.h
+++ b/inputmethods/multikey/configdlg.h
@@ -1,47 +1,50 @@
#include <qpe/qpeapplication.h>
#include <qtabwidget.h>
#include <qcheckbox.h>
#include <qlistbox.h>
#include <qpushbutton.h>
#ifndef CONFIGDLG_H
#define CONFIGDLG_H
class ConfigDlg : public QTabWidget
{
Q_OBJECT
public:
ConfigDlg ();
signals:
void pickboardToggled(bool on_off);
+ void repeatToggled(bool on_off);
void setMapToDefault();
void setMapToFile(QString map);
void reloadKeyboard();
private slots:
void pickTog();
+ void repeatTog();
void setMap(int index);
void addMap();
void removeMap();
// all those required slots for the color push buttons
void keyColorButtonClicked();
private:
QCheckBox *pick_button;
+ QCheckBox *repeat_button;
QListBox *keymaps;
QPushButton *add_button;
QPushButton *remove_button;
QStringList default_maps; // the maps in your share/multikey/ dir
QStringList custom_maps; // maps you added with the 'add' button
/* color buttons */
QPushButton *key_color_button;
};
#endif
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp
index 8280297..7334c1c 100644
--- a/inputmethods/multikey/keyboard.cpp
+++ b/inputmethods/multikey/keyboard.cpp
@@ -1,111 +1,111 @@
/**********************************************************************
** 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 <qtextstream.h>
#include <qstringlist.h>
#include <iostream.h>
#include <sys/utsname.h>
-#define USE_SMALL_BACKSPACE
-
/* Keyboard::Keyboard {{{1 */
Keyboard::Keyboard(QWidget* parent, const char* _name, WFlags f) :
QFrame(parent, _name, f), shift(0), lock(0), ctrl(0),
- alt(0), useLargeKeys(TRUE), usePicks(0), pressedKeyRow(-1), pressedKeyCol(-1),
+ alt(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", "fixed" );
delete config;
config = new Config("multikey");
- config->setGroup ("pickboard");
- usePicks = config->readBoolEntry ("open", "0"); // default closed
+ 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()) );
}
Keyboard::~Keyboard() {
if ( configdlg ) {
delete (ConfigDlg *) 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))/5;
int nk; // number of keys?
if ( useLargeKeys ) {
nk = 15;
} else {
nk = 19;
}
defaultKeyWidth = (width()/nk)/2;
xoffs = (width()-defaultKeyWidth*nk)/2; // empty key spaces?
}
@@ -239,102 +239,104 @@ void Keyboard::drawKeyboard(QPainter &p, int row, int col)
p.setPen(keycolor_lines);
p.drawLine(x, y, x, y + keyHeight);
x += keyWidthPix;
}
}
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;
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;
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(pickboardToggled(bool)),
- this, SLOT(togglePickboard(bool)));
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()));
configdlg->showMaximized();
configdlg->show();
configdlg->raise();
}
} else if (qkeycode == Qt::Key_Control) {
ctrl = keys->pressedPtr(row, col);
need_repaint = TRUE;
*ctrl = !keys->pressed(row, col);
} else if (qkeycode == Qt::Key_Alt) {
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;
}
}
} else if (qkeycode == Qt::Key_CapsLock) {
need_repaint = TRUE;
if (lock) {
*lock = 0;
lock = 0;
}
else {
lock = keys->pressedPtr(row, col);;
*lock = 1;
if (shift) {
*shift = 0;
shift = 0;
}
}
@@ -350,204 +352,215 @@ void Keyboard::mousePressEvent(QMouseEvent *e)
// korean parsing
if (keys->lang == "ko") {
unicode = parseKoreanInput(unicode);
}
modifiers = (ctrl ? Qt::ControlButton : 0) | (alt ? Qt::AltButton : 0);
emit key(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);
}
- pressTid = startTimer(80);
+ if (useRepeat) repeatTimer->start( 800 );
+ //pressTid = startTimer(80);
}
/* Keyboard::mouseReleaseEvent {{{1 */
void Keyboard::mouseReleaseEvent(QMouseEvent*)
{
pressed = FALSE;
- if ( pressTid == 0 )
+ //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);
}
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();
+ //clearHighlight();
}
}
*/
void Keyboard::repeat()
{
repeatTimer->start( 200 );
- emit key( unicode, 0, modifiers, true, true );
+ 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 * 5 + (usePicks ? picks->sizeHint().height() : 0) + 1);
}
void Keyboard::resetState()
{
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());
//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";
+}
+
/* 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;
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;
delete keys;
keys = new Keys(key_map);
// have to repaint the keyboard
repaint(FALSE);
}
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;
delete keys;
if (QFile(map).exists())
keys = new Keys(map);
else
keys = new Keys();
repaint(FALSE);
}
/* Keybaord::reloadKeyboard {{{1 */
void Keyboard::reloadKeyboard() {
diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h
index 6e577ab..dc50e55 100644
--- a/inputmethods/multikey/keyboard.h
+++ b/inputmethods/multikey/keyboard.h
@@ -67,102 +67,104 @@ public:
void setKeysFromFile(const char *filename);
void setKey(const int row, const int qcode, const ushort unicode,
const int width, QPixmap *pix);
void setPressed(const int row, const int col, const bool pressed);
QString lang;
QString label;
private:
typedef struct Key {
int qcode; // are qt key codes just unicode values?
ushort unicode;
int width; // not pixels but relative key width. normal key is 2
// only needed for keys like ctrl that can have multiple keys pressed at once
bool *pressed;
QPixmap *pix;
};
QList<Key> keys[6];
QMap<ushort,ushort> shiftMap;
};
class Keyboard : public QFrame
{
Q_OBJECT
public:
Keyboard( QWidget* parent=0, const char* name=0, WFlags f=0 );
~Keyboard();
void resetState();
void mousePressEvent(QMouseEvent*);
void mouseReleaseEvent(QMouseEvent*);
void resizeEvent(QResizeEvent*);
void paintEvent(QPaintEvent* e);
//void timerEvent(QTimerEvent* e);
void drawKeyboard( QPainter &p, int row = -1, int col = -1);
QSize sizeHint() const;
signals:
void key( ushort scancode, ushort unicode, ushort modifiers, bool, bool );
private slots:
void repeat();
void togglePickboard(bool on_off);
+ void toggleRepeat(bool on_off);
void setMapToDefault();
void setMapToFile(QString map);
// used to redraw keyboard after edited colors
void reloadKeyboard();
private:
int getKey( int &w, int j = -1 );
void clearHighlight();
bool *shift;
bool *lock;
bool *ctrl;
bool *alt;
uint useLargeKeys:1;
uint usePicks:1;
+ uint useRepeat:1;
int pressedKeyRow;
int pressedKeyCol;
KeyboardPicks *picks;
int keyHeight;
int defaultKeyWidth;
int xoffs;
int unicode;
int qkeycode;
int modifiers;
int pressTid;
bool pressed;
Keys *keys;
/* for korean input */
ushort schar, mchar, echar;
ushort parseKoreanInput(ushort c);
ushort combineKoreanChars(const ushort s, const ushort m, const ushort e);
ushort constoe(const ushort c);
QTimer *repeatTimer;
/* colors */
void loadKeyboardColors();
QColor keycolor;
QColor keycolor_pressed;
QColor keycolor_lines;
QColor textcolor;
ConfigDlg *configdlg;
};