]> git.lyx.org Git - lyx.git/blob - src/frontends/qt2/QLyXKeySym.C
Some stuff.
[lyx.git] / src / frontends / qt2 / QLyXKeySym.C
1 /**
2  * \file QLyXKeySym.C
3  * Copyright 2002 the LyX Team
4  * Read the file COPYING
5  *
6  * \author Asger and Juergen
7  * \author John Levon <moz@compsoc.man.ac.uk>
8  */
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "QLyXKeySym.h"
17 #include "qlkey.h"
18 #include "debug.h"
19  
20 #include <qevent.h>
21  
22 QLyXKeySym::QLyXKeySym()
23         : LyXKeySym(), key_(0)
24 {
25 }
26  
27  
28 void QLyXKeySym::set(QKeyEvent * ev)
29 {
30         key_ = ev->key();
31         text_ = ev->text(); 
32         ascii_ = ev->ascii();
33 }
34  
35
36 void QLyXKeySym::init(string const & symbolname)
37 {
38         key_ = string_to_qkey(symbolname);
39         text_ = symbolname.c_str();
40         ascii_ = 0;
41         lyxerr[Debug::KEY] << "Init key to " << key_ << ", " << text_ << endl;
42 }
43
44  
45 bool QLyXKeySym::isOK() const
46 {
47         return ! key_ == 0;
48 }
49  
50
51 bool QLyXKeySym::isModifier() const
52 {
53         return q_is_modifier(key_);
54 }
55
56
57 // This is one ALMIGHTY hack. When you press C-S-z, you get
58 // "Press key 90 text "?", ascii "26"
59 // where text is meaningless. So we check specifically
60 // for this case ! (90 is 'Z')
61 // We also check against 0 for when we're comparing
62 // against a stored binding. 
63 bool QLyXKeySym::is_qt_bogon() const
64 {
65         if (ascii_ == 0)
66                 return false;
67         return (ascii_ < 27 && !text_.isEmpty());
68
69  
70  
71 char QLyXKeySym::debogonify() const
72 {
73         return 'a' + ascii_ - 1;
74 }
75
76
77 string QLyXKeySym::getSymbolName() const
78 {
79         string sym(qkey_to_string(key_));
80
81         // deal with "A", "a" properly
82         if (sym.empty()) {
83                 lyxerr[Debug::KEY] << "sym empty in getSymbolName()" << endl;
84  
85                 if (is_qt_bogon()) {
86                         sym = debogonify();
87                 } else {
88                         sym = text_.latin1();
89                 }
90         }
91         lyxerr[Debug::KEY] << "getSymbolName() -> " << sym << endl;
92         return sym;
93 }
94
95  
96 char QLyXKeySym::getISOEncoded() const
97 {
98         lyxerr[Debug::KEY] << "getISO returning " << text_.latin1()[0] << endl;
99
100         if (is_qt_bogon()) {
101                 return debogonify();
102         }
103  
104         return text_.latin1()[0]; 
105 }
106  
107
108 bool QLyXKeySym::operator==(LyXKeySym const & k) const
109 {
110         QLyXKeySym const & o = static_cast<QLyXKeySym const &>(k);
111         // ignore text_ ! 
112         return o.key_ == key_;
113 }