]> git.lyx.org Git - features.git/commitdiff
Some stuff.
authorJohn Levon <levon@movementarian.org>
Sun, 25 Aug 2002 05:41:42 +0000 (05:41 +0000)
committerJohn Levon <levon@movementarian.org>
Sun, 25 Aug 2002 05:41:42 +0000 (05:41 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@5098 a592a061-630c-0410-9148-cb99ea01b6c8

src/frontends/qt2/ChangeLog
src/frontends/qt2/QContentPane.C
src/frontends/qt2/QGraphicsDialog.C
src/frontends/qt2/QLyXKeySym.C
src/frontends/qt2/QLyXKeySym.h
src/frontends/qt2/lyx_gui.C
src/frontends/qt2/qlkey.h

index 5aa9d9531db86bada5dd42eb14426c7fb675284b..f210ddf82eaa7659eac9328dd1bc7426f70d365f 100644 (file)
@@ -1,3 +1,10 @@
+2002-08-25  John Levon  <levon@movementarian.org>
+
+       * QLyXKeySym.h:
+       * QLyXKeySym.C:
+       * QContentPane.C: revert some wrong direction stuff and try
+         again. STILL BROKEN :(
 2002-08-25  John Levon  <levon@movementarian.org>
 
        * QGraphics.C:
index 770c6fe33544a57d3bd1ac316c317a259fc093e9..ff63407603e72e6d6281a11a4d82abe39ebc924b 100644 (file)
@@ -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()));
 }
 
index d067effe08bac9e70363e399a4f6bfe19121e47e..cf667ba912e2ead6c7b55981372c1514ff4f66fc 100644 (file)
@@ -37,6 +37,7 @@ QGraphicsDialog::QGraphicsDialog(QGraphics * form)
 
 void QGraphicsDialog::change_adaptor()
 {
+       lyxerr << "changed" << endl; 
        form_->changed();
 }
 
index eaf0293f83153ad535325fc8d38cffcb2997f619..5bb146f8a2726f4a90a2131187a2c2f14fb11a23 100644 (file)
 #include "qlkey.h"
 #include "debug.h"
  
+#include <qevent.h>
 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<QLyXKeySym const &>(k);
+       // ignore text_ ! 
        return o.key_ == key_;
 }
index 5c5438262c99ebc1781a48f09bd38d336d5e6498..538e81fad618082f8a3455cc32fd90d28b9bd94f 100644 (file)
 #include "LString.h"
 #include "frontends/LyXKeySym.h"
 
+#include <qstring.h>
+
+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
index ee6fb7ad01155b9b3887645a65c95c8fa179affc..f6438ed86d47a43fb1186111125fa4526bdc30b5 100644 (file)
@@ -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;
 }
 
 
index 7f20c7def94b39f0da4a3aac9a1da8a9bcbc4dcf..59365ea1831b097b219e7c0c620b5bf6d7c19738 100644 (file)
 
 #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