Skip to content

Commit

Permalink
Adds the ability to remap action bindings in button lists with patch …
Browse files Browse the repository at this point in the history
…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
daniel-kristjansson committed Sep 27, 2011
1 parent c5dc240 commit 4f5c3e6
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 1 deletion.
65 changes: 64 additions & 1 deletion mythtv/libs/libmythui/mythuibuttonlist.cpp
@@ -1,10 +1,11 @@

#include "mythuibuttonlist.h"

#include <math.h>

// QT headers
#include <QCoreApplication>
#include <QDomDocument>
#include <QKeyEvent>

// libmyth headers
#include "mythlogging.h"
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2616,6 +2677,8 @@ void MythUIButtonList::CopyFrom(MythUIType *base)

m_ButtonList.clear();

m_actionRemap = lb->m_actionRemap;

m_initialized = false;
}

Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythuibuttonlist.h
Expand Up @@ -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;
Expand Down
6 changes: 6 additions & 0 deletions mythtv/themes/MythCenter-wide/base.xml
Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions mythtv/themes/MythCenter-wide/config-ui.xml
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions mythtv/themes/MythCenter-wide/menu-ui.xml
Expand Up @@ -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>
Expand Down
2 changes: 2 additions & 0 deletions mythtv/themes/MythCenter-wide/recordings-ui.xml
Expand Up @@ -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">
Expand All @@ -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>
Expand Down
4 changes: 4 additions & 0 deletions mythtv/themes/MythCenter-wide/schedule-ui.xml
Expand Up @@ -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">
Expand All @@ -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">
Expand Down Expand Up @@ -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">
Expand Down Expand Up @@ -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">
Expand Down
2 changes: 2 additions & 0 deletions mythtv/themes/MythCenter-wide/settings-ui.xml
Expand Up @@ -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>
Expand Down
1 change: 1 addition & 0 deletions mythtv/themes/MythCenter-wide/status-ui.xml
Expand Up @@ -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>
Expand Down

0 comments on commit 4f5c3e6

Please sign in to comment.