From 5c7a1d34bbbe2abea58ee1e4bc84a951661f8d52 Mon Sep 17 00:00:00 2001 From: John Levon Date: Sun, 25 Aug 2002 05:41:42 +0000 Subject: [PATCH] Some stuff. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5098 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt2/ChangeLog | 7 ++ src/frontends/qt2/QContentPane.C | 5 +- src/frontends/qt2/QGraphicsDialog.C | 1 + src/frontends/qt2/QLyXKeySym.C | 66 +++++++++++++---- src/frontends/qt2/QLyXKeySym.h | 18 ++++- src/frontends/qt2/lyx_gui.C | 10 ++- src/frontends/qt2/qlkey.h | 109 +++------------------------- 7 files changed, 100 insertions(+), 116 deletions(-) diff --git a/src/frontends/qt2/ChangeLog b/src/frontends/qt2/ChangeLog index 5aa9d9531d..f210ddf82e 100644 --- a/src/frontends/qt2/ChangeLog +++ b/src/frontends/qt2/ChangeLog @@ -1,3 +1,10 @@ +2002-08-25 John Levon + + * QLyXKeySym.h: + * QLyXKeySym.C: + * QContentPane.C: revert some wrong direction stuff and try + again. STILL BROKEN :( + 2002-08-25 John Levon * QGraphics.C: diff --git a/src/frontends/qt2/QContentPane.C b/src/frontends/qt2/QContentPane.C index 770c6fe335..ff63407603 100644 --- a/src/frontends/qt2/QContentPane.C +++ b/src/frontends/qt2/QContentPane.C @@ -114,8 +114,11 @@ void QContentPane::mouseMoveEvent(QMouseEvent * e) void QContentPane::keyPressEvent(QKeyEvent * e) { + lyxerr[Debug::KEY] << "Press key " << e->key() + << " text \"" << (e->text().isEmpty() ? "none" : e->text().latin1()) + << "\", ascii \"" << e->ascii() << "\"" << endl; QLyXKeySym * sym = new QLyXKeySym(); - sym->set(e->key(), bool(e->state() & Qt::ShiftButton)); + sym->set(e); wa_->workAreaKeyPress(LyXKeySymPtr(sym), q_key_state(e->state())); } diff --git a/src/frontends/qt2/QGraphicsDialog.C b/src/frontends/qt2/QGraphicsDialog.C index d067effe08..cf667ba912 100644 --- a/src/frontends/qt2/QGraphicsDialog.C +++ b/src/frontends/qt2/QGraphicsDialog.C @@ -37,6 +37,7 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form) void QGraphicsDialog::change_adaptor() { + lyxerr << "changed" << endl; form_->changed(); } diff --git a/src/frontends/qt2/QLyXKeySym.C b/src/frontends/qt2/QLyXKeySym.C index eaf0293f83..5bb146f8a2 100644 --- a/src/frontends/qt2/QLyXKeySym.C +++ b/src/frontends/qt2/QLyXKeySym.C @@ -17,29 +17,34 @@ #include "qlkey.h" #include "debug.h" +#include + QLyXKeySym::QLyXKeySym() - : LyXKeySym(), key_(0), shift_(false) + : LyXKeySym(), key_(0) { } -void QLyXKeySym::set(int key, bool shift) +void QLyXKeySym::set(QKeyEvent * ev) { - key_ = key; - shift_ = shift; + key_ = ev->key(); + text_ = ev->text(); + ascii_ = ev->ascii(); } void QLyXKeySym::init(string const & symbolname) { key_ = string_to_qkey(symbolname); + text_ = symbolname.c_str(); + ascii_ = 0; + lyxerr[Debug::KEY] << "Init key to " << key_ << ", " << text_ << endl; } bool QLyXKeySym::isOK() const { - // FIXME - return key_ != 0; + return ! key_ == 0; } @@ -48,26 +53,61 @@ bool QLyXKeySym::isModifier() const return q_is_modifier(key_); } + +// This is one ALMIGHTY hack. When you press C-S-z, you get +// "Press key 90 text "?", ascii "26" +// where text is meaningless. So we check specifically +// for this case ! (90 is 'Z') +// We also check against 0 for when we're comparing +// against a stored binding. +bool QLyXKeySym::is_qt_bogon() const +{ + if (ascii_ == 0) + return false; + return (ascii_ < 27 && !text_.isEmpty()); +} + +char QLyXKeySym::debogonify() const +{ + return 'a' + ascii_ - 1; +} + + string QLyXKeySym::getSymbolName() const { - return qkey_to_string(key_, shift_); + string sym(qkey_to_string(key_)); + + // deal with "A", "a" properly + if (sym.empty()) { + lyxerr[Debug::KEY] << "sym empty in getSymbolName()" << endl; + + if (is_qt_bogon()) { + sym = debogonify(); + } else { + sym = text_.latin1(); + } + } + lyxerr[Debug::KEY] << "getSymbolName() -> " << sym << endl; + return sym; } char QLyXKeySym::getISOEncoded() const { - /* Even though we could try to use QKeyEvent->text(), - * it won't work, because it returns something other - * than 'Z' for things like C-S-z. Do not ask me why, - * just more Qt bullshit. - */ - return qkey_to_char(key_, shift_); + lyxerr[Debug::KEY] << "getISO returning " << text_.latin1()[0] << endl; + + if (is_qt_bogon()) { + return debogonify(); + } + + return text_.latin1()[0]; } bool QLyXKeySym::operator==(LyXKeySym const & k) const { QLyXKeySym const & o = static_cast(k); + // ignore text_ ! return o.key_ == key_; } diff --git a/src/frontends/qt2/QLyXKeySym.h b/src/frontends/qt2/QLyXKeySym.h index 5c5438262c..538e81fad6 100644 --- a/src/frontends/qt2/QLyXKeySym.h +++ b/src/frontends/qt2/QLyXKeySym.h @@ -18,6 +18,10 @@ #include "LString.h" #include "frontends/LyXKeySym.h" +#include + +class QKeyEvent; + /** * Qt-specific key press. * @@ -30,7 +34,7 @@ public: virtual ~QLyXKeySym() {} /// delayed constructor - void set(int key, bool shift); + void set(QKeyEvent * ev); /// set from a LyX symbolic name virtual void init(string const & symbolname); @@ -54,10 +58,18 @@ public: virtual bool operator==(LyXKeySym const & k) const; private: + /// return true if bogon (see source) + bool is_qt_bogon() const; + + /// return the fixed bogon (see source) + char debogonify() const; + /// the Qt sym value int key_; - /// shift held or not - bool shift_; + /// the event string value + QString text_; + /// hack-o-rama + int ascii_; }; #endif // QLYXKEYSYM_H diff --git a/src/frontends/qt2/lyx_gui.C b/src/frontends/qt2/lyx_gui.C index ee6fb7ad01..f6438ed86d 100644 --- a/src/frontends/qt2/lyx_gui.C +++ b/src/frontends/qt2/lyx_gui.C @@ -53,6 +53,11 @@ using std::endl; extern BufferList bufferlist; +namespace { + /// good ol' "easy to use" Qt again + float getDPI() { return 95; } +}; + // FIXME: wrong place ! LyXServer * lyxserver; @@ -64,13 +69,14 @@ void lyx_gui::parse_init(int & argc, char * argv[]) Image::newImage = boost::bind(&QLImage::newImage); Image::loadableFormats = boost::bind(&QLImage::loadableFormats); + + // needs to be done before reading lyxrc + lyxrc.dpi = getDPI(); } void lyx_gui::parse_lyxrc() { - // FIXME !!!! - lyxrc.dpi = 95; } diff --git a/src/frontends/qt2/qlkey.h b/src/frontends/qt2/qlkey.h index 7f20c7def9..59365ea183 100644 --- a/src/frontends/qt2/qlkey.h +++ b/src/frontends/qt2/qlkey.h @@ -14,7 +14,10 @@ #include "LString.h" -int q_is_modifier(int qkey) +/** + * Return true if the key event is a modifier. + */ +bool q_is_modifier(int qkey) { switch (qkey) { case Qt::Key_Hyper_L: @@ -31,7 +34,10 @@ int q_is_modifier(int qkey) } -// FIXME +/** + * Return the numeric Qt Key corresponding to the + * given symbol name. + */ int string_to_qkey(string const & str) { if (str == "Escape") return Qt::Key_Escape; @@ -274,19 +280,16 @@ int string_to_qkey(string const & str) /** - * qkey_t_string - convert Qt keypress into LyX + * qkey_to_string - convert Qt keypress into LyX * * Convert the Qt keypress into a string understandable - * by the LyX core (same as XKeysymToString) + * by the LyX core (same as XKeysymToString). */ -string const qkey_to_string(int lkey, bool shift) +string const qkey_to_string(int lkey) { switch (lkey) { case Qt::Key_Escape: return "Escape"; - case Qt::Key_Tab: return "Tab"; case Qt::Key_BackSpace: return "BackSpace"; - case Qt::Key_Return: return "Return"; - case Qt::Key_Enter: return "KP_Enter"; // correct ?? case Qt::Key_Insert: return "Insert"; case Qt::Key_Delete: return "Delete"; case Qt::Key_Pause: return "Pause"; @@ -342,16 +345,6 @@ string const qkey_to_string(int lkey, bool shift) case Qt::Key_F33: return "F33"; case Qt::Key_F34: return "F34"; case Qt::Key_F35: return "F35"; - case Qt::Key_0: return "0"; - case Qt::Key_1: return "1"; - case Qt::Key_2: return "2"; - case Qt::Key_3: return "3"; - case Qt::Key_4: return "4"; - case Qt::Key_5: return "5"; - case Qt::Key_6: return "6"; - case Qt::Key_7: return "7"; - case Qt::Key_8: return "8"; - case Qt::Key_9: return "9"; case Qt::Key_Colon: return "colon"; case Qt::Key_Semicolon: return "semicolon"; case Qt::Key_Less: return "less"; @@ -359,32 +352,6 @@ string const qkey_to_string(int lkey, bool shift) case Qt::Key_Greater: return "greater"; case Qt::Key_Question: return "question"; case Qt::Key_At: return "at"; - case Qt::Key_A: return shift ? "A" : "a"; - case Qt::Key_B: return shift ? "B" : "b"; - case Qt::Key_C: return shift ? "C" : "c"; - case Qt::Key_D: return shift ? "D" : "d"; - case Qt::Key_E: return shift ? "E" : "e"; - case Qt::Key_F: return shift ? "F" : "f"; - case Qt::Key_G: return shift ? "G" : "g"; - case Qt::Key_H: return shift ? "H" : "h"; - case Qt::Key_I: return shift ? "I" : "i"; - case Qt::Key_J: return shift ? "J" : "j"; - case Qt::Key_K: return shift ? "K" : "k"; - case Qt::Key_L: return shift ? "L" : "l"; - case Qt::Key_M: return shift ? "M" : "m"; - case Qt::Key_N: return shift ? "N" : "n"; - case Qt::Key_O: return shift ? "O" : "o"; - case Qt::Key_P: return shift ? "P" : "p"; - case Qt::Key_Q: return shift ? "Q" : "q"; - case Qt::Key_R: return shift ? "R" : "r"; - case Qt::Key_S: return shift ? "S" : "s"; - case Qt::Key_T: return shift ? "T" : "t"; - case Qt::Key_U: return shift ? "U" : "u"; - case Qt::Key_V: return shift ? "V" : "v"; - case Qt::Key_W: return shift ? "W" : "w"; - case Qt::Key_X: return shift ? "X" : "x"; - case Qt::Key_Y: return shift ? "Y" : "y"; - case Qt::Key_Z: return shift ? "Z" : "z"; case Qt::Key_BracketLeft: return "bracketleft"; case Qt::Key_Backslash: return "backslash"; case Qt::Key_BracketRight: return "bracketright"; @@ -519,60 +486,8 @@ string const qkey_to_string(int lkey, bool shift) case Qt::Key_Backtab: return "BackTab"; default: - case Qt::Key_unknown: return "unknown"; + case Qt::Key_unknown: return ""; } -} - -/** - * qkey_to_char - convert keypress into char - * - * Convert the Qt keypress into a iso8859-1 char that - * represents it. - * - * FIXME: this is where all the encoding stuff - * sits, I suppose. I have shit all idea what - * to do. Help ! - */ -char const qkey_to_char(int lkey, bool shift) -{ - // We are relying on Qt internals here, but it's - // not likely to change anyway. - if (lkey >= 0x1000) - return 0; - - switch (lkey) { - case Qt::Key_A: return shift ? 'A' : 'a'; - case Qt::Key_B: return shift ? 'B' : 'b'; - case Qt::Key_C: return shift ? 'C' : 'c'; - case Qt::Key_D: return shift ? 'D' : 'd'; - case Qt::Key_E: return shift ? 'E' : 'e'; - case Qt::Key_F: return shift ? 'F' : 'f'; - case Qt::Key_G: return shift ? 'G' : 'g'; - case Qt::Key_H: return shift ? 'H' : 'h'; - case Qt::Key_I: return shift ? 'I' : 'i'; - case Qt::Key_J: return shift ? 'J' : 'j'; - case Qt::Key_K: return shift ? 'K' : 'k'; - case Qt::Key_L: return shift ? 'L' : 'l'; - case Qt::Key_M: return shift ? 'M' : 'm'; - case Qt::Key_N: return shift ? 'N' : 'n'; - case Qt::Key_O: return shift ? 'O' : 'o'; - case Qt::Key_P: return shift ? 'P' : 'p'; - case Qt::Key_Q: return shift ? 'Q' : 'q'; - case Qt::Key_R: return shift ? 'R' : 'r'; - case Qt::Key_S: return shift ? 'S' : 's'; - case Qt::Key_T: return shift ? 'T' : 't'; - case Qt::Key_U: return shift ? 'U' : 'u'; - case Qt::Key_V: return shift ? 'V' : 'v'; - case Qt::Key_W: return shift ? 'W' : 'w'; - case Qt::Key_X: return shift ? 'X' : 'x'; - case Qt::Key_Y: return shift ? 'Y' : 'y'; - case Qt::Key_Z: return shift ? 'Z' : 'z'; - default: - return lkey; - } - - // FIXME: CapsLock ignored. - // FIXME: all things like é are screwed too. I LOVE Qt. I REALLY DO. } #endif // QLKEY_H -- 2.39.5