-rw-r--r-- | inputmethods/multikey/configdlg.cpp | 54 | ||||
-rw-r--r-- | inputmethods/multikey/configdlg.h | 7 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 65 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.h | 10 |
4 files changed, 120 insertions, 16 deletions
diff --git a/inputmethods/multikey/configdlg.cpp b/inputmethods/multikey/configdlg.cpp index ac132d3..1e104a6 100644 --- a/inputmethods/multikey/configdlg.cpp +++ b/inputmethods/multikey/configdlg.cpp @@ -1,43 +1,46 @@ /* * TODO * make a font selection thing (size too) + * make a cursor thing * * * */ #include <iostream.h> #include <qpe/qpeapplication.h> #include <qpe/config.h> #include <qwidget.h> #include <qdialog.h> #include <qtabwidget.h> #include <qvbox.h> #include <qgrid.h> #include <qgroupbox.h> #include <qlabel.h> #include <qcheckbox.h> #include <qsizepolicy.h> #include <qpushbutton.h> #include <qlistbox.h> #include <qstringlist.h> #include <opie/ofiledialog.h> +#include <opie/colordialog.h> #include <qdir.h> #include <qfileinfo.h> #include "configdlg.h" #include "keyboard.h" +// ConfigDlg::ConfigDlg() {{{1 ConfigDlg::ConfigDlg () : QTabWidget () { setCaption( tr("Multikey Configuration") ); Config config ("multikey"); config.setGroup("keymaps"); QString current_map = config.readEntry("current", 0); /* * 'general config' tab */ QVBox *gen_box = new QVBox (this); @@ -95,24 +98,26 @@ ConfigDlg::ConfigDlg () : QTabWidget () 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); config.setGroup ("pickboard"); bool pick_open = config.readBoolEntry ("open", "0"); // default closed if (pick_open) { pick_button->setChecked(true); } // by connecting it after checking it, the signal isn't emmited @@ -120,30 +125,43 @@ ConfigDlg::ConfigDlg () : QTabWidget () /* * '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); - QPushButton *button = new QPushButton(color_box); - button->setFlat((bool)1); + 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); - button = new QPushButton(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)); } @@ -155,67 +173,87 @@ void ConfigDlg::pickTog() { config.writeEntry ("open", pick_button->isChecked()); // default closed emit pickboardToggled(pick_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.join("|")); + 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"; cout << "currentItem : " << keymaps->currentItem() << "\n"; // move selection up one keymaps->setSelected(keymaps->currentItem() - 1, true); // delete the next selected item cus you just moved it up keymaps->removeItem(keymaps->currentItem() + 1); custom_maps.remove(custom_maps[keymaps->currentItem() - default_maps.count()]); // write the changes Config config ("multikey"); config.setGroup("keymaps"); - config.writeEntry("maps", custom_maps.join("|")); + config.writeEntry("maps", custom_maps, QChar('|')); +} + +// ConfigDlg::color {{{1 +void ConfigDlg::keyColorButtonClicked() { + + Config config ("multikey"); + config.setGroup ("colors"); + + QStringList color = config.readListEntry("keycolor", QChar(',')); + + QColor newcolor = OColorDialog::getColor(QColor(color[0].toInt(), color[1].toInt(), color[2].toInt())); + + color[0].setNum(newcolor.red()); + color[1].setNum(newcolor.green()); + color[2].setNum(newcolor.blue()); + + config.writeEntry("keycolor", color, QChar(',')); + + key_color_button->setBackgroundColor(newcolor); + emit reloadKeyboard(); } diff --git a/inputmethods/multikey/configdlg.h b/inputmethods/multikey/configdlg.h index 07d109c..ae7afe2 100644 --- a/inputmethods/multikey/configdlg.h +++ b/inputmethods/multikey/configdlg.h @@ -9,32 +9,39 @@ class ConfigDlg : public QTabWidget { Q_OBJECT public: ConfigDlg (); signals: void pickboardToggled(bool on_off); void setMapToDefault(); void setMapToFile(QString map); + void reloadKeyboard(); private slots: void pickTog(); void setMap(int index); void addMap(); void removeMap(); + // all those required slots for the color push buttons + void keyColorButtonClicked(); + private: QCheckBox *pick_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 ac3d9be..68918a6 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp @@ -40,53 +40,57 @@ #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), 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 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*) { @@ -147,56 +151,50 @@ void Keyboard::paintEvent(QPaintEvent* e) { QPainter painter(this); painter.setClipRect(e->rect()); drawKeyboard( painter ); picks->dc->draw( &painter ); } /* Keyboard::drawKeyboard {{{1 */ void Keyboard::drawKeyboard(QPainter &p, int row, int col) { - QColor keycolor = - QColor(240,240,240); - QColor keycolor_pressed = QColor(171,183,198); - QColor keycolor_lines = QColor(138,148,160); - QColor textcolor = QColor(43,54,68); if (row != -1 && col != -1) { //just redraw one key int x = 0; for (int i = 0; i < col; i++) { x += keys->width(row, i) * defaultKeyWidth; } int y = (row - 1) * keyHeight + (usePicks ? picks->height() : 0); int keyWidth = keys->width(row, col); p.fillRect(x + 1, y + 1, keyWidth * defaultKeyWidth - 1, keyHeight - 1, pressed || keys->pressed(row, col) ? keycolor_pressed : keycolor); QPixmap *pix = keys->pix(row,col); ushort c = keys->uni(row, col); - if (!pix) { - p.setPen(textcolor); + p.setPen(textcolor); + if (!pix) p.drawText(x, y, defaultKeyWidth * keyWidth, keyHeight, AlignCenter, ((shift || lock) && keys->shift(c)) ? (QChar)keys->shift(c) : (QChar)c); - } else // center the image in the middle of the key p.drawPixmap( x + (defaultKeyWidth * keyWidth - pix->width())/2, y + (keyHeight - pix->height())/2 + 1, *pix ); // this fixes the problem that the very right end of the board's vertical line // gets painted over, because it's one pixel shorter than all other keys p.setPen(keycolor_lines); p.drawLine(width() - 1, 0, width() - 1, height()); } else { @@ -283,24 +281,26 @@ void Keyboard::mousePressEvent(QMouseEvent *e) 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(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); @@ -539,24 +539,73 @@ void Keyboard::setMapToFile(QString map) { delete config; delete keys; if (QFile(map).exists()) keys = new Keys(map); else keys = new Keys(); repaint(FALSE); } +/* Keybaord::setColor {{{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. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h index 8c4e666..6e577ab 100644 --- a/inputmethods/multikey/keyboard.h +++ b/inputmethods/multikey/keyboard.h @@ -105,24 +105,27 @@ public: 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 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; @@ -143,16 +146,23 @@ private: 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; }; |