2002-06-19 05:20:29 +00:00
|
|
|
/**
|
|
|
|
* \file QLyXKeySym.C
|
|
|
|
* Copyright 2002 the LyX Team
|
|
|
|
* Read the file COPYING
|
|
|
|
*
|
|
|
|
* \author Asger and Juergen
|
|
|
|
* \author John Levon <moz@compsoc.man.ac.uk>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
|
#ifdef __GNUG__
|
|
|
|
#pragma implementation
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "QLyXKeySym.h"
|
|
|
|
#include "qlkey.h"
|
2002-07-30 00:53:57 +00:00
|
|
|
#include "debug.h"
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2002-08-25 05:41:42 +00:00
|
|
|
#include <qevent.h>
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
QLyXKeySym::QLyXKeySym()
|
2002-08-25 05:41:42 +00:00
|
|
|
: LyXKeySym(), key_(0)
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-25 05:41:42 +00:00
|
|
|
void QLyXKeySym::set(QKeyEvent * ev)
|
2002-06-19 05:20:29 +00:00
|
|
|
{
|
2002-08-25 05:41:42 +00:00
|
|
|
key_ = ev->key();
|
|
|
|
text_ = ev->text();
|
|
|
|
ascii_ = ev->ascii();
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void QLyXKeySym::init(string const & symbolname)
|
|
|
|
{
|
|
|
|
key_ = string_to_qkey(symbolname);
|
2002-08-25 05:41:42 +00:00
|
|
|
text_ = symbolname.c_str();
|
|
|
|
ascii_ = 0;
|
|
|
|
lyxerr[Debug::KEY] << "Init key to " << key_ << ", " << text_ << endl;
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QLyXKeySym::isOK() const
|
|
|
|
{
|
2002-08-25 05:41:42 +00:00
|
|
|
return ! key_ == 0;
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QLyXKeySym::isModifier() const
|
|
|
|
{
|
|
|
|
return q_is_modifier(key_);
|
|
|
|
}
|
|
|
|
|
2002-08-25 05:41:42 +00:00
|
|
|
|
|
|
|
// 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());
|
|
|
|
}
|
2002-06-19 05:20:29 +00:00
|
|
|
|
2002-08-25 05:41:42 +00:00
|
|
|
|
|
|
|
char QLyXKeySym::debogonify() const
|
|
|
|
{
|
2002-08-25 05:52:38 +00:00
|
|
|
return 'A' + ascii_ - 1;
|
2002-08-25 05:41:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-06-19 05:20:29 +00:00
|
|
|
string QLyXKeySym::getSymbolName() const
|
|
|
|
{
|
2002-08-25 05:41:42 +00:00
|
|
|
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;
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
char QLyXKeySym::getISOEncoded() const
|
|
|
|
{
|
2002-08-25 05:41:42 +00:00
|
|
|
lyxerr[Debug::KEY] << "getISO returning " << text_.latin1()[0] << endl;
|
|
|
|
|
|
|
|
if (is_qt_bogon()) {
|
|
|
|
return debogonify();
|
|
|
|
}
|
|
|
|
|
|
|
|
return text_.latin1()[0];
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool QLyXKeySym::operator==(LyXKeySym const & k) const
|
|
|
|
{
|
|
|
|
QLyXKeySym const & o = static_cast<QLyXKeySym const &>(k);
|
2002-08-25 05:41:42 +00:00
|
|
|
// ignore text_ !
|
2002-07-22 18:22:35 +00:00
|
|
|
return o.key_ == key_;
|
2002-06-19 05:20:29 +00:00
|
|
|
}
|