author | hash <hash> | 2002-08-15 19:46:43 (UTC) |
---|---|---|
committer | hash <hash> | 2002-08-15 19:46:43 (UTC) |
commit | 3e328409c2829dff590d0087518938851aff8bcc (patch) (side-by-side diff) | |
tree | 0a0f9fe70fdd78ffd00702b73782f41ffbc56cd7 | |
parent | d9cc9bedf72e921f8f7d8edeb189db127c5651e3 (diff) | |
download | opie-3e328409c2829dff590d0087518938851aff8bcc.zip opie-3e328409c2829dff590d0087518938851aff8bcc.tar.gz opie-3e328409c2829dff590d0087518938851aff8bcc.tar.bz2 |
think i fixed a memory leak problem... please test it out and see if the size of qpe increases if you load/unload keymaps
-rw-r--r-- | inputmethods/multikey/keyboard.cpp | 10 | ||||
-rw-r--r-- | inputmethods/multikey/keyboard.h | 1 |
2 files changed, 11 insertions, 0 deletions
diff --git a/inputmethods/multikey/keyboard.cpp b/inputmethods/multikey/keyboard.cpp index b71f929..671868c 100644 --- a/inputmethods/multikey/keyboard.cpp +++ b/inputmethods/multikey/keyboard.cpp @@ -924,148 +924,158 @@ void Keys::setKeysFromFile(const char * filename) { } // have to close that facker up ((char *)xpm[xpmLineCount])[j] = '\0'; xpmLineCount++; buf = t.readLine(); } if (xpmLineCount) { xpm2pix = new QPixmap((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(); } // 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, QPixmap *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; } ushort Keys::uni(const int row, const int col) { return keys[row].at(col)->unicode; } int Keys::qcode(const int row, const int col) { return keys[row].at(col)->qcode; } QPixmap *Keys::pix(const int row, const int col) { return keys[row].at(col)->pix; } bool Keys::pressed(const int row, const int col) { return *(keys[row].at(col)->pressed); } int Keys::numKeys(const int row) { return keys[row].count(); } void Keys::setPressed(const int row, const int col, const bool pressed) { *(keys[row].at(col)->pressed) = pressed; } ushort Keys::shift(const ushort uni) { if (shiftMap[uni]) { return shiftMap[uni]; } else return 0; } bool *Keys::pressedPtr(const int row, const int col) { return keys[row].at(col)->pressed; } diff --git a/inputmethods/multikey/keyboard.h b/inputmethods/multikey/keyboard.h index 8ca50ea..400edc0 100644 --- a/inputmethods/multikey/keyboard.h +++ b/inputmethods/multikey/keyboard.h @@ -1,153 +1,154 @@ /********************************************************************** ** 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 <qframe.h> #include <qmap.h> #include "../pickboard/pickboardcfg.h" #include "../pickboard/pickboardpicks.h" #include "configdlg.h" class QTimer; class KeyboardConfig : public DictFilterConfig { public: KeyboardConfig(PickboardPicks* p) : DictFilterConfig(p), backspaces(0) { nrows = 1; } virtual void generateText(const QString &s); void decBackspaces() { if (backspaces) backspaces--; } void incBackspaces() { backspaces++; } void resetBackspaces() { backspaces = 0; } private: int backspaces; }; class KeyboardPicks : public PickboardPicks { Q_OBJECT public: KeyboardPicks(QWidget* parent=0, const char* name=0, WFlags f=0) : PickboardPicks(parent, name, f) { } void initialise(); virtual QSize sizeHint() const; KeyboardConfig *dc; }; class Keys { public: Keys(); Keys(const char * filename); + ~Keys(); ushort uni(const int row, const int col); int qcode(const int row, const int col); int width(const int row, const int col); bool pressed(const int row, const int col); bool *pressedPtr(const int row, const int col); ushort shift(const ushort); QPixmap *pix(const int row, const int col); int numKeys(const int row); 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 title; 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 setMapToDefault(); void setMapToFile(QString file); private: int getKey( int &w, int j = -1 ); void clearHighlight(); bool *shift; bool *lock; bool *ctrl; bool *alt; uint useLargeKeys:1; uint usePicks: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; |