00001
00002 #include <cmath>
00003
00004
00005 #include <algorithm>
00006 using namespace std;
00007
00008
00009 #include <QCoreApplication>
00010 #include <QPainter>
00011 #include <QLabel>
00012
00013 using namespace std;
00014
00015 #include "uitypes.h"
00016 #include "mythdialogs.h"
00017 #include "mythcontext.h"
00018 #include "lcddevice.h"
00019 #include "mythmiscutil.h"
00020
00021 #include "mythfontproperties.h"
00022 #include "mythuihelper.h"
00023 #include "x11colors.h"
00024
00025 #include "mythlogging.h"
00026
00027 #ifdef USING_MINGW
00028 #undef LoadImage
00029 #endif
00030
00031 LayerSet::LayerSet(const QString &name) :
00032 m_debug(false),
00033 m_context(-1),
00034 m_order(-1),
00035 m_name(name),
00036 numb_layers(-1),
00037 allTypes(new vector<UIType *>)
00038 {
00039 }
00040
00041 LayerSet::~LayerSet()
00042 {
00043 vector<UIType *>::iterator i = allTypes->begin();
00044 for (; i != allTypes->end(); ++i)
00045 {
00046 UIType *type = (*i);
00047 if (type)
00048 delete type;
00049 }
00050 delete allTypes;
00051 }
00052
00053 void LayerSet::AddType(UIType *type)
00054 {
00055 type->SetDebug(m_debug);
00056 typeList[type->Name()] = type;
00057 allTypes->push_back(type);
00058 type->SetParent(this);
00059 bumpUpLayers(type->getOrder());
00060 }
00061
00062 UIType *LayerSet::GetType(const QString &name)
00063 {
00064 UIType *ret = NULL;
00065 if (typeList.contains(name))
00066 ret = typeList[name];
00067
00068 return ret;
00069 }
00070
00071 void LayerSet::bumpUpLayers(int a_number)
00072 {
00073 if (a_number > numb_layers)
00074 {
00075 numb_layers = a_number;
00076 }
00077 }
00078
00079 void LayerSet::Draw(QPainter *dr, int drawlayer, int context)
00080 {
00081 if (m_context == context || m_context == -1)
00082 {
00083 vector<UIType *>::iterator i = allTypes->begin();
00084 for (; i != allTypes->end(); ++i)
00085 {
00086 if (m_debug)
00087 LOG(VB_GENERAL, LOG_DEBUG, "-LayerSet::Draw");
00088 UIType *type = (*i);
00089 type->Draw(dr, drawlayer, context);
00090 }
00091 }
00092 }
00093
00094 void LayerSet::DrawRegion(QPainter *dr, QRect &area, int drawlayer, int context)
00095 {
00096 if (m_context == context || m_context == -1)
00097 {
00098 vector<UIType *>::iterator i = allTypes->begin();
00099 for (; i != allTypes->end(); ++i)
00100 {
00101 if (m_debug)
00102 LOG(VB_GENERAL, LOG_DEBUG, "-LayerSet::DrawRegion");
00103 UIType *type = (*i);
00104 type->DrawRegion(dr, area, drawlayer, context);
00105 }
00106 }
00107 }
00108
00109 void LayerSet::SetDrawFontShadow(bool state)
00110 {
00111 vector<UIType *>::iterator i = allTypes->begin();
00112 for (; i != allTypes->end(); ++i)
00113 {
00114 UIType *type = (*i);
00115 type->SetDrawFontShadow(state);
00116 }
00117 }
00118
00119
00120
00121 UIType::UIType(const QString &name)
00122 : QObject(NULL)
00123 {
00124 setObjectName(name);
00125 m_parent = NULL;
00126 m_name = name;
00127 m_debug = false;
00128 m_context = -1;
00129 m_order = -1;
00130 has_focus = false;
00131 takes_focus = false;
00132 screen_area = QRect(0,0,0,0);
00133 drawFontShadow = true;
00134 hidden = false;
00135 }
00136
00137 void UIType::SetOrder(int order)
00138 {
00139 m_order = order;
00140 if (m_parent)
00141 {
00142 m_parent->bumpUpLayers(order);
00143 }
00144 }
00145
00146 UIType::~UIType()
00147 {
00148 }
00149
00150 void UIType::Draw(QPainter *dr, int drawlayer, int context)
00151 {
00152 dr->end();
00153 (void)drawlayer;
00154 (void)context;
00155 }
00156
00157 void UIType::DrawRegion(QPainter *dr, QRect &area, int drawlayer, int context)
00158 {
00159 (void)dr;
00160 (void)area;
00161 (void)drawlayer;
00162 (void)context;
00163 }
00164
00165 void UIType::SetParent(LayerSet *parent)
00166 {
00167 m_parent = parent;
00168 }
00169
00170 QString UIType::Name()
00171 {
00172 return m_name;
00173 }
00174
00175 bool UIType::takeFocus()
00176 {
00177 if (takes_focus)
00178 {
00179 has_focus = true;
00180 refresh();
00181 emit takingFocus();
00182 return true;
00183 }
00184 has_focus = false;
00185 return false;
00186 }
00187
00188 void UIType::looseFocus()
00189 {
00190 emit loosingFocus();
00191 has_focus = false;
00192 refresh();
00193 }
00194
00195 void UIType::calculateScreenArea()
00196 {
00197 screen_area = QRect(0,0,0,0);
00198 }
00199
00200 void UIType::refresh()
00201 {
00202 emit requestUpdate(screen_area);
00203 }
00204
00205 void UIType::show()
00206 {
00207
00208
00209
00210
00211
00212
00213 hidden = false;
00214 refresh();
00215 }
00216
00217 void UIType::hide()
00218 {
00219 hidden = true;
00220 refresh();
00221 }
00222
00223 bool UIType::toggleShow()
00224 {
00225 if (hidden)
00226 {
00227 show();
00228 }
00229 else
00230 {
00231 hide();
00232 }
00233
00234 return !hidden;
00235 }
00236
00237 QString UIType::cutDown(const QString &data, QFont *testFont, bool multiline,
00238 int overload_width, int overload_height)
00239 {
00240 int length = data.length();
00241 if (length == 0)
00242 return data;
00243
00244 int maxwidth = screen_area.width();
00245 if (overload_width != -1)
00246 maxwidth = overload_width;
00247 int maxheight = screen_area.height();
00248 if (overload_height != -1)
00249 maxheight = overload_height;
00250
00251 int justification = Qt::AlignLeft | Qt::TextWordWrap;
00252 QFontMetrics fm(*testFont);
00253
00254 int margin = length - 1;
00255 int index = 0;
00256 int diff = 0;
00257
00258 while (margin > 0)
00259 {
00260 if (multiline)
00261 diff = maxheight - fm.boundingRect(0, 0, maxwidth, maxheight,
00262 justification,
00263 data.left(index + margin)
00264 ).height();
00265 else
00266 diff = maxwidth - fm.width(data, index + margin);
00267 if (diff >= 0)
00268 index += margin;
00269
00270 margin /= 2;
00271
00272 if (index + margin >= length - 1)
00273 margin = (length - 1) - index;
00274 }
00275
00276 if (index < length - 1)
00277 {
00278 QString tmpStr(data);
00279 tmpStr.truncate(index);
00280 if (index >= 3)
00281 tmpStr.replace(index - 3, 3, "...");
00282 return tmpStr;
00283 }
00284
00285 return data;
00286 }
00287
00288
00289
00290
00291 UIKeyType::UIKeyType(const QString &name)
00292 : UIType(name)
00293 {
00294 m_normalImg = m_focusedImg = m_downImg = m_downFocusedImg = NULL;
00295 m_normalFont = m_focusedFont = m_downFont = m_downFocusedFont = NULL;
00296
00297 m_pos = QPoint(0, 0);
00298
00299 m_bDown = false;
00300 m_bShift = false;
00301 m_bAlt = false;
00302 m_bToggle = false;
00303
00304 takes_focus = true;
00305 connect(&m_pushTimer, SIGNAL(timeout()), this, SLOT(unPush()));
00306 }
00307
00308 UIKeyType::~UIKeyType()
00309 {
00310 }
00311
00312 void UIKeyType::Draw(QPainter *dr, int drawlayer, int context)
00313 {
00314 if (m_context == context || m_context == -1)
00315 {
00316 if (drawlayer == m_order)
00317 {
00318 fontProp *tempFont;
00319
00320
00321 if (!m_bDown)
00322 {
00323 if (!has_focus)
00324 {
00325 dr->drawPixmap(m_pos.x(), m_pos.y(), *m_normalImg);
00326 tempFont = m_normalFont;
00327 }
00328 else
00329 {
00330 dr->drawPixmap(m_pos.x(), m_pos.y(), *m_focusedImg);
00331 tempFont = m_focusedFont;
00332 }
00333 }
00334 else
00335 {
00336 if (!has_focus)
00337 {
00338 dr->drawPixmap(m_pos.x(), m_pos.y(), *m_downImg);
00339 tempFont = m_downFont;
00340 }
00341 else
00342 {
00343 dr->drawPixmap(m_pos.x(), m_pos.y(), *m_downFocusedImg);
00344 tempFont = m_downFocusedFont;
00345 }
00346 }
00347
00348 dr->setFont(tempFont->face);
00349
00350
00351 QString text;
00352
00353 if (!m_bShift)
00354 {
00355 if (!m_bAlt)
00356 text = m_normalChar;
00357 else
00358 text = m_altChar;
00359 }
00360 else
00361 {
00362 if (!m_bAlt)
00363 text = m_shiftChar;
00364 else
00365 text = m_shiftAltChar;
00366 }
00367
00368 if (drawFontShadow &&
00369 (tempFont->shadowOffset.x() != 0 ||
00370 tempFont->shadowOffset.y() != 0))
00371 {
00372 dr->setBrush(tempFont->dropColor);
00373 dr->setPen(QPen(tempFont->dropColor, (int)(2 * m_wmult)));
00374 dr->drawText(m_pos.x() + tempFont->shadowOffset.x(),
00375 m_pos.y() + tempFont->shadowOffset.y(),
00376 m_area.width(), m_area.height(),
00377 Qt::AlignCenter, text);
00378 }
00379
00380 dr->setBrush(tempFont->color);
00381 dr->setPen(QPen(tempFont->color, (int)(2 * m_wmult)));
00382 dr->drawText(m_pos.x(), m_pos.y(), m_area.width(), m_area.height(),
00383 Qt::AlignCenter, text);
00384 }
00385 }
00386 }
00387
00388 void UIKeyType::SetImages(QPixmap *normal, QPixmap *focused,
00389 QPixmap *down, QPixmap *downFocused)
00390 {
00391 m_normalImg = normal;
00392 m_focusedImg = focused;
00393 m_downImg = down;
00394 m_downFocusedImg = downFocused;
00395 }
00396
00397 void UIKeyType::SetDefaultImages(QPixmap *normal, QPixmap *focused,
00398 QPixmap *down, QPixmap *downFocused)
00399 {
00400 if (!m_normalImg) m_normalImg = normal;
00401 if (!m_focusedImg) m_focusedImg = focused;
00402 if (!m_downImg) m_downImg = down;
00403 if (!m_downFocusedImg) m_downFocusedImg = downFocused;
00404 }
00405
00406 void UIKeyType::SetFonts(fontProp *normal, fontProp *focused,
00407 fontProp *down, fontProp *downFocused)
00408 {
00409 m_normalFont = normal;
00410 m_focusedFont = focused;
00411 m_downFont = down;
00412 m_downFocusedFont = downFocused;
00413 }
00414
00415 void UIKeyType::SetDefaultFonts(fontProp *normal, fontProp *focused,
00416 fontProp *down, fontProp *downFocused)
00417 {
00418 if (!m_normalFont) m_normalFont = normal;
00419 if (!m_focusedFont) m_focusedFont = focused;
00420 if (!m_downFont) m_downFont = down;
00421 if (!m_downFocusedFont) m_downFocusedFont = downFocused;
00422 }
00423
00424 void UIKeyType::SetChars(QString normal, QString shift, QString alt,
00425 QString shiftAlt)
00426 {
00427 m_normalChar = decodeChar(normal);
00428 m_shiftChar = decodeChar(shift);
00429 m_altChar = decodeChar(alt);
00430 m_shiftAltChar = decodeChar(shiftAlt);
00431 }
00432
00433 QString UIKeyType::GetChar()
00434 {
00435 if (!m_bShift && !m_bAlt)
00436 return m_normalChar;
00437 else if (m_bShift && !m_bAlt)
00438 return m_shiftChar;
00439 else if (!m_bShift && m_bAlt)
00440 return m_altChar;
00441 else if (m_bShift && m_bAlt)
00442 return m_shiftAltChar;
00443
00444 return m_normalChar;
00445 }
00446
00447 QString UIKeyType::decodeChar(QString c)
00448 {
00449 QString res = "";
00450
00451 while (c.length() > 0)
00452 {
00453 if (c.startsWith("0x"))
00454 {
00455 QString sCode = c.left(6);
00456 bool bOK;
00457 short nCode = sCode.toShort(&bOK, 16);
00458
00459 c = c.mid(6);
00460
00461 if (bOK)
00462 {
00463 QChar uc(nCode);
00464 res += QString(uc);
00465 }
00466 else
00467 LOG(VB_GENERAL, LOG_ERR,
00468 QString("UIKeyType::decodeChar - bad char code (%1)")
00469 .arg(sCode));
00470 }
00471 else
00472 {
00473 res += c.left(1);
00474 c = c.mid(1);
00475 }
00476 }
00477
00478 return res;
00479 }
00480
00481 void UIKeyType::SetMoves(QString moveLeft, QString moveRight, QString moveUp,
00482 QString moveDown)
00483 {
00484 m_moveLeft = moveLeft;
00485 m_moveRight = moveRight;
00486 m_moveUp = moveUp;
00487 m_moveDown = moveDown;
00488 }
00489
00490 QString UIKeyType::GetMove(QString direction)
00491 {
00492 QString res = m_moveLeft;
00493
00494 if (direction == "Up")
00495 res = m_moveUp;
00496 else if (direction == "Down")
00497 res = m_moveDown;
00498 else if (direction == "Right")
00499 res = m_moveRight;
00500
00501 return res;
00502 }
00503
00504 void UIKeyType::calculateScreenArea()
00505 {
00506 if (!m_normalImg)
00507 return;
00508
00509 int width = m_normalImg->width();
00510 int height = m_normalImg->height();
00511
00512 QRect r = QRect(m_pos.x(), m_pos.y(), width, height);
00513 r.translate(m_parent->GetAreaRect().left(), m_parent->GetAreaRect().top());
00514 screen_area = r;
00515 m_area = r;
00516 }
00517
00518 void UIKeyType::SetShiftState(bool sh, bool ag)
00519 {
00520 m_bShift = sh;
00521 m_bAlt = ag;
00522 refresh();
00523 }
00524
00525 void UIKeyType::push()
00526 {
00527 if (m_bToggle)
00528 {
00529 m_bDown = !m_bDown;
00530 refresh();
00531 emit pushed();
00532
00533 return;
00534 }
00535
00536 if (m_bDown)
00537 return;
00538
00539 m_bDown = true;
00540 m_pushTimer.setSingleShot(true);
00541 m_pushTimer.start(300);
00542 refresh();
00543 emit pushed();
00544 }
00545
00546 void UIKeyType::unPush()
00547 {
00548 if (!m_bToggle)
00549 {
00550 m_bDown = false;
00551 refresh();
00552 }
00553 }
00554
00555
00556
00557 const int numcomps = 95;
00558
00559 const QString comps[numcomps][3] = {
00560 {"!", "!", (QChar)0xa1}, {"c", "/", (QChar)0xa2},
00561 {"l", "-", (QChar)0xa3}, {"o", "x", (QChar)0xa4},
00562 {"y", "-", (QChar)0xa5}, {"|", "|", (QChar)0xa6},
00563 {"s", "o", (QChar)0xa7}, {"\"", "\"", (QChar)0xa8},
00564 {"c", "o", (QChar)0xa9}, {"-", "a", (QChar)0xaa},
00565 {"<", "<", (QChar)0xab}, {"-", "|", (QChar)0xac},
00566 {"-", "-", (QChar)0xad}, {"r", "o", (QChar)0xae},
00567 {"^", "-", (QChar)0xaf}, {"^", "0", (QChar)0xb0},
00568 {"+", "-", (QChar)0xb1}, {"^", "2", (QChar)0xb2},
00569 {"^", "3", (QChar)0xb3}, {"/", "/", (QChar)0xb4},
00570 {"/", "u", (QChar)0xb5}, {"P", "!", (QChar)0xb6},
00571 {"^", ".", (QChar)0xb7}, {",", ",", (QChar)0xb8},
00572 {"^", "1", (QChar)0xb9}, {"_", "o", (QChar)0xba},
00573 {">", ">", (QChar)0xbb}, {"1", "4", (QChar)0xbc},
00574 {"1", "2", (QChar)0xbd}, {"3", "4", (QChar)0xbe},
00575 {"?", "?", (QChar)0xbf}, {"A", "`", (QChar)0xc0},
00576 {"A", "'", (QChar)0xc1}, {"A", "^", (QChar)0xc2},
00577 {"A", "~", (QChar)0xc3}, {"A", "\"", (QChar)0xc4},
00578 {"A", "*", (QChar)0xc5}, {"A", "E", (QChar)0xc6},
00579 {"C", ",", (QChar)0xc7}, {"E", "`", (QChar)0xc8},
00580 {"E", "'", (QChar)0xc9}, {"E", "^", (QChar)0xca},
00581 {"E", "\"", (QChar)0xcb}, {"I", "`", (QChar)0xcc},
00582 {"I", "'", (QChar)0xcd}, {"I", "^", (QChar)0xce},
00583 {"I", "\"", (QChar)0xcf}, {"D", "-", (QChar)0xd0},
00584 {"N", "~", (QChar)0xd1}, {"O", "`", (QChar)0xd2},
00585 {"O", "'", (QChar)0xd3}, {"O", "^", (QChar)0xd4},
00586 {"O", "~", (QChar)0xd5}, {"O", "\"", (QChar)0xd6},
00587 {"x", "x", (QChar)0xd7}, {"O", "/", (QChar)0xd8},
00588 {"U", "`", (QChar)0xd9}, {"U", "'", (QChar)0xda},
00589 {"U", "^", (QChar)0xdb}, {"U", "\"", (QChar)0xdc},
00590 {"Y", "'", (QChar)0xdd}, {"T", "H", (QChar)0xde},
00591 {"s", "s", (QChar)0xdf}, {"a", "`", (QChar)0xe0},
00592 {"a", "'", (QChar)0xe1}, {"a", "^", (QChar)0xe2},
00593 {"a", "~", (QChar)0xe3}, {"a", "\"", (QChar)0xe4},
00594 {"a", "*", (QChar)0xe5}, {"a", "e", (QChar)0xe6},
00595 {"c", ",", (QChar)0xe7}, {"e", "`", (QChar)0xe8},
00596 {"e", "'", (QChar)0xe9}, {"e", "^", (QChar)0xea},
00597 {"e", "\"", (QChar)0xeb}, {"i", "`", (QChar)0xec},
00598 {"i", "'", (QChar)0xed}, {"i", "^", (QChar)0xee},
00599 {"i", "\"", (QChar)0xef}, {"d", "-", (QChar)0xf0},
00600 {"n", "~", (QChar)0xf1}, {"o", "`", (QChar)0xf2},
00601 {"o", "'", (QChar)0xf3}, {"o", "^", (QChar)0xf4},
00602 {"o", "~", (QChar)0xf5}, {"o", "\"", (QChar)0xf6},
00603 {"-", ":", (QChar)0xf7}, {"o", "/", (QChar)0xf8},
00604 {"u", "`", (QChar)0xf9}, {"u", "'", (QChar)0xfa},
00605 {"u", "^", (QChar)0xfb}, {"u", "\"", (QChar)0xfc},
00606 {"y", "'", (QChar)0xfd}, {"t", "h", (QChar)0xfe},
00607 {"y", "\"", (QChar)0xff}
00608 };
00609
00610 UIKeyboardType::UIKeyboardType(const QString &name, int order)
00611 : UIType(name)
00612 {
00613 m_order = order;
00614 m_container = NULL;
00615 m_parentEdit = NULL;
00616 m_parentDialog = NULL;
00617 m_bInitalized = false;
00618 m_focusedKey = m_doneKey = m_altKey = m_lockKey = NULL;
00619 m_shiftRKey = m_shiftLKey = NULL;
00620
00621 m_bCompTrap = false;
00622 m_comp1 = "";
00623 }
00624
00625
00626 UIKeyboardType::~UIKeyboardType()
00627 {
00628 if (m_container)
00629 delete m_container;
00630 }
00631
00632 void UIKeyboardType::init()
00633 {
00634 m_bInitalized = true;
00635
00636 KeyList::iterator it = m_keyList.begin();
00637 for (; it != m_keyList.end(); ++it)
00638 {
00639 UIKeyType *key = *it;
00640 if (key->GetType() == "char")
00641 {
00642 connect(key, SIGNAL( pushed() ), this, SLOT( charKey() ) );
00643 }
00644 else if (key->GetType() == "shift")
00645 {
00646 if (!m_shiftLKey)
00647 {
00648 connect(key, SIGNAL( pushed() ), this, SLOT( shiftLOnOff() ) );
00649 m_shiftLKey = key;
00650 m_shiftLKey->SetToggleKey(true);
00651 }
00652 else
00653 {
00654 connect(key, SIGNAL( pushed() ), this, SLOT( shiftROnOff() ) );
00655 m_shiftRKey = key;
00656 m_shiftRKey->SetToggleKey(true);
00657 }
00658 }
00659 else if (key->GetType() == "del")
00660 {
00661 connect(key, SIGNAL( pushed() ), this, SLOT( delKey() ) );
00662 }
00663 else if (key->GetType() == "back")
00664 {
00665 connect(key, SIGNAL( pushed() ), this, SLOT( backspaceKey() ) );
00666 }
00667 else if (key->GetType() == "lock")
00668 {
00669 connect(key, SIGNAL( pushed() ), this, SLOT( lockOnOff() ) );
00670 m_lockKey = key;
00671 m_lockKey->SetToggleKey(true);
00672 }
00673 else if (key->GetType() == "done")
00674 {
00675 connect(key, SIGNAL( pushed() ), this, SLOT( close() ) );
00676 m_doneKey = key;
00677 }
00678 else if (key->GetType() == "moveleft")
00679 {
00680 connect(key, SIGNAL( pushed() ), this, SLOT( leftCursor() ) );
00681 }
00682 else if (key->GetType() == "moveright")
00683 {
00684 connect(key, SIGNAL( pushed() ), this, SLOT( rightCursor() ) );
00685 }
00686 else if (key->GetType() == "comp")
00687 {
00688 connect(key, SIGNAL( pushed() ), this, SLOT( compOnOff() ) );
00689 }
00690 else if (key->GetType() == "alt")
00691 {
00692 connect(key, SIGNAL( pushed() ), this, SLOT( altGrOnOff() ) );
00693 m_altKey = key;
00694 m_altKey->SetToggleKey(true);
00695 }
00696 }
00697 }
00698
00699 void UIKeyboardType::Draw(QPainter *dr, int drawlayer, int context)
00700 {
00701 if (!m_bInitalized)
00702 init();
00703
00704 if (hidden)
00705 return;
00706
00707 if (m_context == context || m_context == -1)
00708 {
00709 if (drawlayer == m_order)
00710 {
00711 dr = dr;
00712 }
00713 }
00714 }
00715
00716 void UIKeyboardType::calculateScreenArea()
00717 {
00718 QRect r = m_area;
00719 r.translate(m_parent->GetAreaRect().left(),
00720 m_parent->GetAreaRect().top());
00721 screen_area = r;
00722 }
00723
00724 void UIKeyboardType::leftCursor()
00725 {
00726 if (!m_parentEdit)
00727 return;
00728
00729 if (m_parentEdit->inherits("QLineEdit"))
00730 {
00731 QLineEdit *par = (QLineEdit *)m_parentEdit;
00732 par->cursorBackward(m_shiftLKey->IsOn());
00733 }
00734 else if (m_parentEdit->inherits("QTextEdit"))
00735 {
00736 QTextEdit *par = (QTextEdit *)m_parentEdit;
00737 par->textCursor().movePosition(
00738 QTextCursor::PreviousCharacter, QTextCursor::MoveAnchor);
00739 }
00740 else
00741 {
00742 QKeyEvent *key = new QKeyEvent(
00743 QEvent::KeyPress, Qt::Key_Left, Qt::NoModifier, "", false, 1);
00744 QCoreApplication::postEvent(m_parentEdit, key);
00745 }
00746 }
00747
00748 void UIKeyboardType::rightCursor()
00749 {
00750 if (!m_parentEdit)
00751 return;
00752
00753 if (m_parentEdit->inherits("QLineEdit"))
00754 {
00755 QLineEdit *par = (QLineEdit *)m_parentEdit;
00756 par->cursorForward(m_shiftLKey->IsOn());
00757 }
00758 else if (m_parentEdit->inherits("QTextEdit"))
00759 {
00760 QTextEdit *par = (QTextEdit *)m_parentEdit;
00761 par->textCursor().movePosition(
00762 QTextCursor::NextCharacter, QTextCursor::MoveAnchor);
00763 }
00764 else
00765 {
00766 QKeyEvent *key = new QKeyEvent(
00767 QEvent::KeyPress, Qt::Key_Right, Qt::NoModifier, "", false, 1);
00768 QCoreApplication::postEvent(m_parentEdit, key);
00769 }
00770 }
00771
00772 void UIKeyboardType::backspaceKey()
00773 {
00774 if (!m_parentEdit)
00775 return;
00776
00777 if (m_parentEdit->inherits("QLineEdit"))
00778 {
00779 QLineEdit *par = (QLineEdit *)m_parentEdit;
00780 par->backspace();
00781 }
00782 else if (m_parentEdit->inherits("MythRemoteLineEdit"))
00783 {
00784 MythRemoteLineEdit *par = (MythRemoteLineEdit *)m_parentEdit;
00785 par->backspace();
00786 }
00787 else
00788 {
00789 QKeyEvent *key = new QKeyEvent(
00790 QEvent::KeyPress, Qt::Key_Backspace, Qt::NoModifier, "", false, 1);
00791 QCoreApplication::postEvent(m_parentEdit, key);
00792 }
00793 }
00794
00795 void UIKeyboardType::delKey()
00796 {
00797 if (!m_parentEdit)
00798 return;
00799
00800 if (m_parentEdit->inherits("QLineEdit"))
00801 {
00802 QLineEdit *par = (QLineEdit *)m_parentEdit;
00803 par->del();
00804 }
00805 else if (m_parentEdit->inherits("MythRemoteLineEdit"))
00806 {
00807 MythRemoteLineEdit *par = (MythRemoteLineEdit *)m_parentEdit;
00808 par->del();
00809 }
00810 else
00811 {
00812 QKeyEvent *key = new QKeyEvent(
00813 QEvent::KeyPress, Qt::Key_Delete, Qt::NoModifier, "", false, 1);
00814 QCoreApplication::postEvent(m_parentEdit, key);
00815 }
00816 }
00817
00818 void UIKeyboardType::altGrOnOff()
00819 {
00820 if (m_lockKey->IsOn())
00821 {
00822 m_shiftLKey->SetOn(false);
00823 if (m_shiftRKey) m_shiftRKey->SetOn(false);
00824 if (m_altKey) m_altKey->SetOn(false);
00825 m_lockKey->SetOn(false);
00826 }
00827 updateButtons();
00828 }
00829
00830 void UIKeyboardType::compOnOff()
00831 {
00832 m_bCompTrap = !m_bCompTrap;
00833 m_comp1 = "";
00834 }
00835
00836 void UIKeyboardType::charKey()
00837 {
00838 if (m_focusedKey && m_focusedKey->GetType() == "char")
00839 {
00840 insertChar(m_focusedKey->GetChar());
00841 shiftOff();
00842 }
00843 }
00844
00845 void UIKeyboardType::insertChar(QString c)
00846 {
00847 if (!m_bCompTrap)
00848 {
00849 if (m_parentEdit->inherits("QLineEdit"))
00850 {
00851 QLineEdit *par = (QLineEdit *)m_parentEdit;
00852 par->insert(c);
00853 }
00854 else if (m_parentEdit->inherits("MythRemoteLineEdit"))
00855 {
00856 MythRemoteLineEdit *par = (MythRemoteLineEdit *)m_parentEdit;
00857 par->insert(c);
00858 }
00859 else
00860 {
00861 QKeyEvent *key = new QKeyEvent(QEvent::KeyPress, 0, Qt::NoModifier,
00862 c, false, c.length());
00863 QCoreApplication::postEvent(m_parentEdit, key);
00864 }
00865 }
00866 else
00867 {
00868 if (m_comp1.isEmpty()) m_comp1 = c;
00869 else
00870 {
00871
00872 for (int i=0; i<numcomps; i++)
00873 {
00874 if ((m_comp1 == comps[i][0]) && (c == comps[i][1]))
00875 {
00876 if (m_parentEdit->inherits("QLineEdit"))
00877 {
00878 QLineEdit *par = (QLineEdit *)m_parentEdit;
00879 par->insert(comps[i][2]);
00880 }
00881 else if (m_parentEdit->inherits("MythRemoteLineEdit"))
00882 {
00883 MythRemoteLineEdit *par =
00884 (MythRemoteLineEdit *)m_parentEdit;
00885 par->insert(comps[i][2]);
00886 }
00887 else
00888 {
00889 QKeyEvent *key = new QKeyEvent(QEvent::KeyPress, 0,
00890 Qt::NoModifier,
00891 comps[i][2], false,
00892 comps[i][2].length());
00893 QCoreApplication::postEvent(m_parentEdit, key);
00894 }
00895
00896 break;
00897 }
00898 }
00899
00900 m_comp1 = "";
00901 m_bCompTrap = false;
00902 }
00903 }
00904 }
00905
00906 void UIKeyboardType::lockOnOff()
00907 {
00908 if (m_lockKey->IsOn())
00909 {
00910 if (!(m_altKey && m_altKey->IsOn()))
00911 {
00912 m_shiftLKey->SetOn(true);
00913 if (m_shiftRKey) m_shiftRKey->SetOn(true);
00914 }
00915 }
00916 else
00917 {
00918 m_shiftLKey->SetOn(false);
00919 if (m_shiftRKey) m_shiftRKey->SetOn(false);
00920 if (m_altKey) m_altKey->SetOn(false);
00921 }
00922 updateButtons();
00923 }
00924
00925 void UIKeyboardType::shiftOff()
00926 {
00927 if (!m_lockKey->IsOn())
00928 {
00929 m_shiftLKey->SetOn(false);
00930 if (m_shiftRKey) m_shiftRKey->SetOn(false);
00931 if (m_altKey) m_altKey->SetOn(false);
00932 }
00933 updateButtons();
00934 }
00935
00936 void UIKeyboardType::close(void)
00937 {
00938 if (!m_parentDialog)
00939 return;
00940
00941 m_parentDialog->done(kDialogCodeAccepted);
00942 }
00943
00944 void UIKeyboardType::updateButtons()
00945 {
00946 bool bShift = m_shiftLKey->IsOn();
00947 bool bAlt = (m_altKey ? m_altKey->IsOn() : false);
00948
00949 KeyList::iterator it = m_keyList.begin();
00950 for (; it != m_keyList.end(); ++it)
00951 (*it)->SetShiftState(bShift, bAlt);
00952 }
00953
00954 void UIKeyboardType::shiftLOnOff()
00955 {
00956 if (m_lockKey->IsOn())
00957 {
00958 m_shiftLKey->SetOn(false);
00959 if (m_shiftRKey) m_shiftRKey->SetOn(false);
00960 if (m_altKey) m_altKey->SetOn(false);
00961 m_lockKey->SetOn(false);
00962 }
00963 else if (m_shiftRKey) m_shiftRKey->SetOn(m_shiftLKey->IsOn());
00964
00965 updateButtons();
00966 }
00967
00968 void UIKeyboardType::shiftROnOff()
00969 {
00970 if (!m_shiftRKey) return;
00971
00972 if (m_lockKey->IsOn())
00973 {
00974 m_shiftLKey->SetOn(false);
00975 m_shiftRKey->SetOn(false);
00976 if (m_altKey) m_altKey->SetOn(false);
00977 m_lockKey->SetOn(false);
00978 }
00979 else m_shiftLKey->SetOn(m_shiftRKey->IsOn());
00980
00981 updateButtons();
00982 }
00983
00984 void UIKeyboardType::keyPressEvent(QKeyEvent *e)
00985 {
00986 bool handled = false;
00987 QStringList actions;
00988 handled = GetMythMainWindow()->TranslateKeyPress("qt", e, actions, false);
00989
00990 for (int i = 0; i < actions.size() && !handled; i++)
00991 {
00992 QString action = actions[i];
00993 handled = true;
00994
00995 if (action == "UP")
00996 {
00997 moveUp();
00998 }
00999 else if (action == "DOWN")
01000 {
01001 moveDown();
01002 }
01003 else if (action == "LEFT")
01004 {
01005 moveLeft();
01006 }
01007 else if (action == "RIGHT")
01008 {
01009 moveRight();
01010 }
01011 else if (action == "SELECT")
01012 m_focusedKey->activate();
01013 else
01014 handled = false;
01015 }
01016
01017 if (!handled)
01018 {
01019 QKeyEvent *key = new QKeyEvent(e->type(), e->key(), e->modifiers(),
01020 e->text(), e->isAutoRepeat(),
01021 e->count());
01022 QCoreApplication::postEvent(m_parentEdit, key);
01023 m_parentEdit->setFocus();
01024 }
01025 }
01026
01027 void UIKeyboardType::moveUp()
01028 {
01029 if (!m_focusedKey)
01030 {
01031 m_focusedKey = m_doneKey;
01032 return;
01033 }
01034
01035 UIKeyType *newKey = findKey(m_focusedKey->GetMove("Up"));
01036
01037 if (newKey)
01038 {
01039 m_focusedKey->looseFocus();
01040 m_focusedKey = newKey;
01041 m_focusedKey->takeFocus();
01042 }
01043 }
01044
01045 void UIKeyboardType::moveDown()
01046 {
01047 if (!m_focusedKey)
01048 {
01049 m_focusedKey = m_doneKey;
01050 return;
01051 }
01052
01053 UIKeyType *newKey = findKey(m_focusedKey->GetMove("Down"));
01054
01055 if (newKey)
01056 {
01057 m_focusedKey->looseFocus();
01058 m_focusedKey = newKey;
01059 m_focusedKey->takeFocus();
01060 }
01061 }
01062
01063 void UIKeyboardType::moveLeft()
01064 {
01065 if (!m_focusedKey)
01066 {
01067 m_focusedKey = m_doneKey;
01068 return;
01069 }
01070
01071 UIKeyType *newKey = findKey(m_focusedKey->GetMove("Left"));
01072
01073 if (newKey)
01074 {
01075 m_focusedKey->looseFocus();
01076 m_focusedKey = newKey;
01077 m_focusedKey->takeFocus();
01078 }
01079 }
01080
01081 void UIKeyboardType::moveRight()
01082 {
01083 if (!m_focusedKey)
01084 {
01085 m_focusedKey = m_doneKey;
01086 return;
01087 }
01088
01089 UIKeyType *newKey = findKey(m_focusedKey->GetMove("Right"));
01090
01091 if (newKey)
01092 {
01093 m_focusedKey->looseFocus();
01094 m_focusedKey = newKey;
01095 m_focusedKey->takeFocus();
01096 }
01097 }
01098
01099 UIKeyType *UIKeyboardType::findKey(QString keyName)
01100 {
01101 KeyList::const_iterator it = m_keyList.begin();
01102 for (; it != m_keyList.end(); ++it)
01103 {
01104 if ((*it)->getName() == keyName)
01105 return (*it);
01106 }
01107 return NULL;
01108 }
01109
01110 void UIKeyboardType::AddKey(UIKeyType *key)
01111 {
01112 m_keyList.append(key);
01113
01114 if (key->GetType().toLower() == "done")
01115 {
01116 key->takeFocus();
01117 m_focusedKey = key;
01118 }
01119 }
01120
01121