Permalink
Browse files

Adds the ability to remap action bindings in button lists with patch …

…from Ronald Frazier.

While perhaps universally useful the real reason for this enhancement is to address the loss of arrow acceleration when we allowed themes to use horizontal layouts. To this end I've attempted to add the mappings where needed in MythCenter-wide. Please open tickets for any places I missed so they can be fixed.
  • Loading branch information...
1 parent c5dc240 commit 4f5c3e64a8aac39e65f76c844f31f3390233e7e1 @daniel-kristjansson daniel-kristjansson committed Sep 27, 2011
@@ -1,10 +1,11 @@
-
#include "mythuibuttonlist.h"
#include <math.h>
// QT headers
+#include <QCoreApplication>
#include <QDomDocument>
+#include <QKeyEvent>
// libmyth headers
#include "mythlogging.h"
@@ -2245,6 +2246,46 @@ bool MythUIButtonList::keyPressEvent(QKeyEvent *e)
bool handled = false;
handled = GetMythMainWindow()->TranslateKeyPress("Global", e, actions);
+ // Handle action remappings
+ for (int i = 0; i < actions.size(); i++)
+ {
+ if (!m_actionRemap.contains(actions[i]))
+ continue;
+
+ QString key = m_actionRemap[actions[i]];
+ if (key.isEmpty())
+ return true;
+
+ QKeySequence a(key);
+ if (a.isEmpty())
+ continue;
+
+ int keyCode = a[0];
+ Qt::KeyboardModifiers modifiers = Qt::NoModifier;
+ QStringList parts = key.split('+');
+ for (int j = 0; j < parts.count(); j++)
+ {
+ if (parts[j].toUpper() == "CTRL")
+ modifiers |= Qt::ControlModifier;
+ if (parts[j].toUpper() == "SHIFT")
+ modifiers |= Qt::ShiftModifier;
+ if (parts[j].toUpper() == "ALT")
+ modifiers |= Qt::AltModifier;
+ if (parts[j].toUpper() == "META")
+ modifiers |= Qt::MetaModifier;
+ }
+
+ QCoreApplication::postEvent(
+ GetMythMainWindow(),
+ new QKeyEvent(QEvent::KeyPress, keyCode, modifiers, key));
+ QCoreApplication::postEvent(
+ GetMythMainWindow(),
+ new QKeyEvent(QEvent::KeyRelease, keyCode, modifiers, key));
+
+ return true;
+ }
+
+ // handle actions for this container
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
@@ -2538,6 +2579,26 @@ bool MythUIButtonList::ParseElement(
{
m_searchPosition = parsePoint(element);
}
+ else if (element.tagName() == "triggerevent")
+ {
+ QString trigger = getFirstText(element);
+ if (!trigger.isEmpty())
+ {
+ QString action = element.attribute("action", "");
+ if (action.isEmpty())
+ {
+ m_actionRemap[trigger] = "";
+ }
+ else
+ {
+ QString context = element.attribute("context", "");
+ QString keylist = GetMythMainWindow()->GetKey(context, action);
+ QStringList keys = keylist.split(',', QString::SkipEmptyParts);
+ if (!keys.empty())
+ m_actionRemap[trigger] = keys[0];
+ }
+ }
+ }
else
{
return MythUIType::ParseElement(filename, element, showWarnings);
@@ -2616,6 +2677,8 @@ void MythUIButtonList::CopyFrom(MythUIType *base)
m_ButtonList.clear();
+ m_actionRemap = lb->m_actionRemap;
+
m_initialized = false;
}
@@ -280,6 +280,7 @@ class MUI_PUBLIC MythUIButtonList : public MythUIType
QVector<MythUIStateType *> m_ButtonList;
QMap<int, MythUIButtonListItem *> m_ButtonToItem;
+ QHash<QString, QString> m_actionRemap;
bool m_initialized;
bool m_needsUpdate;
@@ -701,6 +701,8 @@
<drawfrombottom>yes</drawfrombottom>
<showarrow>no</showarrow>
<wrapstyle>selection</wrapstyle>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
+ <triggerevent context="Global" action="SELECT">RIGHT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<textarea name="buttontext">
@@ -750,6 +752,8 @@
<drawfrombottom>yes</drawfrombottom>
<showarrow>no</showarrow>
<wrapstyle>selection</wrapstyle>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
+ <triggerevent context="Global" action="SELECT">RIGHT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<textarea name="buttontext">
@@ -926,6 +930,7 @@
<area>4,70,500,440</area>
<layout>grid</layout>
<buttonarea>0,0,500,430</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<area>0,0,166,106</area>
<state name="active">
@@ -1080,6 +1085,7 @@
<spacing>5</spacing>
<wrapstyle>selection</wrapstyle>
<buttonarea>0,0,100%,97%</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,100%,85</area>
@@ -14,6 +14,7 @@
<buttonarea>0,0,1240,520</buttonarea>
<layout>grid</layout>
<spacing>5</spacing>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,300,60</area>
@@ -141,6 +141,8 @@
<spacing>6</spacing>
<wrapstyle>selection</wrapstyle>
<buttonarea>0,0,550,400</buttonarea>
+ <triggerevent context="Global" action="SELECT">RIGHT</triggerevent>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,550,60</area>
@@ -69,6 +69,7 @@
<scrollstyle>center</scrollstyle>
<wrapstyle>items</wrapstyle>
<searchposition>-1,390</searchposition>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<textarea name="name">
@@ -93,6 +94,7 @@
<wrapstyle>captive</wrapstyle>
<spacing>0</spacing>
<searchposition>-1,390</searchposition>
+ <triggerevent context="Global" action="MENU">RIGHT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,100%,30</area>
@@ -81,6 +81,7 @@
<area>226,250,1020,36</area>
<layout>horizontal</layout>
<buttonarea>0,0,1020,36</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<area>0,0,20%,36</area>
<state name="active">
@@ -102,6 +103,7 @@
<buttonlist name="channellist">
<area>24,294,194,396</area>
<buttonarea>0,0,194,396</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<area>0,0,194,74</area>
<state name="active">
@@ -254,6 +256,7 @@
<layout>horizontal</layout>
<spacing>0</spacing>
<buttonarea>0,0,1036,36</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<area>0,0,258,36</area>
<state name="active">
@@ -301,6 +304,7 @@
<layout>vertical</layout>
<spacing>0</spacing>
<buttonarea>0,0,190,396</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
<statetype name="buttonitem">
<area>0,0,196,74</area>
<state name="active">
@@ -121,6 +121,8 @@
<spacing>2</spacing>
<drawfrombottom>false</drawfrombottom>
<buttonarea>0,0,100%,620</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">LEFT</triggerevent>
+ <triggerevent context="Global" action="MENU">RIGHT</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,600,66</area>
@@ -19,6 +19,7 @@
<layout>horizontal</layout>
<spacing>6</spacing>
<buttonarea>24,0,1220,44</buttonarea>
+ <triggerevent context="Global" action="ESCAPE">UP</triggerevent>
<statetype name="buttonitem">
<state name="active">
<area>0,0,214,44</area>

0 comments on commit 4f5c3e6

Please sign in to comment.