Ticket #2078: view_menu.diff

File view_menu.diff, 13.0 KB (added by mfgalizia, 18 years ago)

Uses a menu to change the views instead of "magic keys." This does not change the way that alternate views display information. This patch replaces the previous (fix_remove.diff) patch.

  • mythcontrols/keygrabber.h

     
    2525// MythTV headers
    2626#include <mythtv/mythdialogs.h>
    2727
    28 
    2928/** \class KeyGrabPopupBox
    3029 *  \brief Captures a key.
    3130 *
     
    9493    Q_OBJECT
    9594
    9695  public:
    97     enum actions { kSave, kCancel, };
     96    enum actions { kSave, kChangeView, kCancel, };
    9897
    9998    /// \brief Create a new action window. Does not pop-up menu.
    10099    OptionsMenu(MythMainWindow *window);
     
    103102    int GetOption(void) { return ExecPopup(this,SLOT(Cancel())); }
    104103
    105104  public slots:
    106     void Save(void)     { done(OptionsMenu::kSave);   }
    107     void Cancel(void)   { done(OptionsMenu::kCancel); }
     105    void Save(void)                     { done(OptionsMenu::kSave);   }
     106    void ChangeView(void)       { done(OptionsMenu::kChangeView); }
     107    void Cancel(void)           { done(OptionsMenu::kCancel); }
    108108};
    109109
    110110
  • mythcontrols/mythcontrols.cpp

     
    3737#include <mythtv/mythdialogs.h>
    3838
    3939// MythControls headers
     40#include "keygrabber.h"
    4041#include "mythcontrols.h"
    41 #include "keygrabber.h"
    4242
    4343static QString key_to_display(const QString &key);
    4444static QString display_to_key(const QString &key);
     
    5353 */
    5454MythControls::MythControls(MythMainWindow *parent, bool &ok)
    5555    : MythThemedDialog(parent, "controls", "controls-", "controls"),
    56       m_focusedUIElement(NULL),
     56      m_currentView(kActionsByContext), m_focusedUIElement(NULL),
    5757      m_leftList(NULL),        m_rightList(NULL),
    5858      m_description(NULL),
    5959      m_leftDescription(NULL), m_rightDescription(NULL),
    60       m_bindings(NULL),     m_container(NULL)
     60      m_bindings(NULL),     m_container(NULL)     
    6161{
    6262    bzero(m_actionButtons, sizeof(void*) * Action::kMaximumNumberOfBindings);
    6363    m_contexts.setAutoDelete(true);
     
    221221    RefreshKeyInformation();
    222222}
    223223
     224/// \brief Chagne the view.
     225void MythControls::ChangeView(void)
     226{
     227    ViewMenu popup(gContext->GetMainWindow(), m_currentView);
     228
     229    switch(popup.GetOption())
     230    {
     231    case ViewMenu::kContextAction:
     232        m_currentView = kActionsByContext;
     233
     234        if ((m_leftListType  != kContextList) ||
     235            (m_rightListType != kActionList))
     236        {
     237            m_leftListType  = kContextList;
     238            m_rightListType = kActionList;
     239            UpdateLists();
     240           
     241            if (m_focusedUIElement != m_leftList)
     242            {
     243                ChangeListFocus(m_leftList,
     244                                (m_focusedUIElement == m_rightList) ?
     245                                m_rightList : NULL);
     246            }
     247        }
     248        break;
     249    case ViewMenu::kContextKey:
     250
     251        m_currentView = kKeysByContext;
     252
     253        if ((m_leftListType  != kContextList) ||
     254            (m_rightListType != kKeyList))
     255        {
     256            m_leftListType  = kContextList;
     257            m_rightListType = kKeyList;
     258            UpdateLists();
     259
     260            if (m_focusedUIElement != m_leftList)
     261            {
     262                ChangeListFocus(m_leftList,
     263                                (m_focusedUIElement == m_rightList) ?
     264                                m_rightList : NULL);
     265            }
     266        }
     267        break;
     268    case ViewMenu::kKeyContext:
     269
     270        m_currentView = kContextsByKey;
     271
     272        if ((m_leftListType  != kKeyList) ||
     273            (m_rightListType != kContextList))
     274        {
     275            m_leftListType  = kKeyList;
     276            m_rightListType = kContextList;
     277            UpdateLists();
     278
     279            if (m_focusedUIElement != m_leftList)
     280            {
     281                ChangeListFocus(m_leftList,
     282                                (m_focusedUIElement == m_rightList) ?
     283                                m_rightList : NULL);
     284            }
     285        }
     286        break;
     287    default:
     288        break;
     289    }
     290}
     291
     292
    224293void MythControls::keyPressEvent(QKeyEvent *e)
    225294{
    226295    bool handled = false;
     
    238307            m_focusedUIElement->looseFocus();
    239308
    240309            OptionsMenu popup(gContext->GetMainWindow());
    241             if (OptionsMenu::kSave == popup.GetOption())
    242                 Save();
    243310
     311            switch (popup.GetOption())
     312            {
     313            case OptionsMenu::kSave: Save();
     314                break;
     315            case OptionsMenu::kChangeView:
     316                ChangeView();
     317                break;
     318            default:
     319                break;
     320            }
     321
    244322            m_focusedUIElement->takeFocus();
    245323        }
    246324        else if (action == "SELECT")
     
    327405            else if (m_focusedUIElement == m_rightList)
    328406                m_rightList->MoveDown(UIListBtnType::MovePage);
    329407        }
    330         else if (action == "1")
    331         {
    332             if ((m_leftListType  != kContextList) ||
    333                 (m_rightListType != kActionList))
    334             {
    335                 m_leftListType  = kContextList;
    336                 m_rightListType = kActionList;
    337                 UpdateLists();
    338 
    339                 if (m_focusedUIElement != m_leftList)
    340                 {
    341                     ChangeListFocus(m_leftList,
    342                                     (m_focusedUIElement == m_rightList) ?
    343                                     m_rightList : NULL);
    344                 }
    345             }
    346             else
    347             {
    348                 handled = false;
    349             }
    350         }
    351         else if (action == "2")
    352         {
    353             if ((m_leftListType  != kContextList) ||
    354                 (m_rightListType != kKeyList))
    355             {
    356                 m_leftListType  = kContextList;
    357                 m_rightListType = kKeyList;
    358                 UpdateLists();
    359 
    360                 if (m_focusedUIElement != m_leftList)
    361                 {
    362                     ChangeListFocus(m_leftList,
    363                                     (m_focusedUIElement == m_rightList) ?
    364                                     m_rightList : NULL);
    365                 }
    366             }
    367             else
    368             {
    369                 handled = false;
    370             }
    371         }
    372         else if (action == "3")
    373         {
    374             if ((m_leftListType  != kKeyList) ||
    375                 (m_rightListType != kContextList))
    376             {
    377                 m_leftListType  = kKeyList;
    378                 m_rightListType = kContextList;
    379                 UpdateLists();
    380 
    381                 if (m_focusedUIElement != m_leftList)
    382                 {
    383                     ChangeListFocus(m_leftList,
    384                                     (m_focusedUIElement == m_rightList) ?
    385                                     m_rightList : NULL);
    386                 }
    387             }
    388             else
    389             {
    390                 handled = false;
    391             }
    392         }
    393408        else
    394409        {
    395410            handled = false;
     
    846861        return;
    847862    }
    848863
    849     BindingList *list = m_keyToBindingsMap[key];
    850     Binding *binding = NULL;
     864    ConfirmMenu popup(gContext->GetMainWindow(), tr("Delete this binding?"));
    851865
    852     for (BindingList::iterator it = list->begin(); it != list->end(); ++it)
    853     {
    854         Binding *b = *it;
    855         if (b->context == context)
    856             binding = b;
    857     }
    858 
    859     if (!binding)
    860     {
    861         InvalidBindingPopup popup(gContext->GetMainWindow());
    862         popup.GetOption();
     866    if (popup.GetOption() != ConfirmMenu::kConfirm)
    863867        return;
    864     }
    865868
    866     if (binding->contextFrom != context)
     869    if (!m_bindings->RemoveActionKey(context, action, key))
    867870    {
    868         ConfirmMenu popup(gContext->GetMainWindow(),
    869                           tr("Delete this key binding from context %1?")
    870                           .arg(binding->contextFrom));
    871 
    872         if (popup.GetOption() != ConfirmMenu::kConfirm)
    873             return;
    874     }
    875     else
    876     {
    877         ConfirmMenu popup(gContext->GetMainWindow(),
    878                           tr("Delete this binding?"));
    879 
    880         if (popup.GetOption() != ConfirmMenu::kConfirm)
    881             return;
    882     }
    883 
    884     if (!m_bindings->RemoveActionKey(binding->contextFrom, action, key))
    885     {
    886871        InvalidBindingPopup popup(gContext->GetMainWindow());
    887872        popup.GetOption();
    888873        return;
     
    12041189    return key;
    12051190}
    12061191
     1192/** \brief Create the view menu.
     1193 *  \param window The main window.
     1194 *  \param current The current view type.
     1195 */
     1196ViewMenu::ViewMenu(MythMainWindow *window, ViewType current)
     1197    : MythPopupBox(window, "mcviewmenu")
     1198{
     1199    addLabel(tr("Change View"), Large, false);
     1200
     1201    switch(current)
     1202    {
     1203    case kKeysByContext:
     1204        addButton(tr("Actions By Context"),     this,   SLOT(ActionsByContext()));
     1205        addButton(tr("Contexts By Key"),        this,   SLOT(ContextsByKey()));
     1206        break;
     1207    case kContextsByKey:
     1208        addButton(tr("Actions By Context"),     this,   SLOT(ActionsByContext()));
     1209        addButton(tr("Keys By Context"),        this,   SLOT(KeysByContext()));
     1210        break;
     1211    default:
     1212        addButton(tr("Keys By Context"),        this,   SLOT(KeysByContext()));
     1213        addButton(tr("Contexts By Key"),        this,   SLOT(ContextsByKey()));
     1214        break; 
     1215    }
     1216
     1217    addButton(tr("Cancel"), this, SLOT(Cancel()))->setFocus();
     1218}
     1219
    12071220/* vim: set expandtab tabstop=4 shiftwidth=4: */
  • mythcontrols/mythcontrols.h

     
    2929
    3030#include "keybindings.h"
    3131
     32
     33typedef enum { kActionsByContext, kKeysByContext, kContextsByKey} ViewType;
     34
     35/** \class ViewMenu
     36 *  \brief Prompts the user to change the view.
     37 */
     38class ViewMenu : public MythPopupBox
     39{
     40    Q_OBJECT
     41
     42public:
     43
     44    /// \brief The available views
     45    enum actions { kContextAction, kContextKey, kKeyContext, kCancel};
     46
     47    /** \brief Creates a new view dialog box.
     48     *  \param window The main MythTV window.
     49     *  \param first The first button's caption
     50     *  \param second The second button's caption
     51     */
     52    ViewMenu(MythMainWindow *window, ViewType current);
     53
     54    /// \brief Execute the option popup.
     55    int GetOption(void) { return ExecPopup(this,SLOT(Cancel())); }
     56
     57public slots:
     58
     59    void ActionsByContext(void) { done(ViewMenu::kContextAction); }
     60    void KeysByContext(void)    { done(ViewMenu::kContextKey); }
     61    void ContextsByKey(void)    { done(ViewMenu::kKeyContext); }
     62    void Cancel(void)                   { done(ViewMenu::kCancel); }
     63};
     64
     65
    3266class Binding
    3367{
    3468  public:
     
    83117    void    LoadData(const QString &hostname);
    84118    void    ChangeButtonFocus(int direction);
    85119    void    ChangeListFocus(UIListBtnType *focus, UIListBtnType *unfocus);
     120    void        ChangeView(void);
    86121    void    AddBindings(QDict<Binding> &bindings, const QString &context,
    87122                        const QString &contextParent, int bindlevel);
    88123
     
    106141    void Save(void) { m_bindings->CommitChanges(); }
    107142
    108143  private:
     144    ViewType           m_currentView;
    109145    UIType            *m_focusedUIElement;
    110146    UIListBtnType     *m_leftList;
    111147    UIListBtnType     *m_rightList;
  • mythcontrols/controls-ui.xml

     
    4646  <container name="controls">
    4747   <area>20,20,780,450</area>
    4848
    49    <textarea name="options" draworder="1" align="center">
    50     <font>options</font>
    51     <area>0,0,780,30</area>
    52     <value>(1) Contexts / Actions  (2) Contexts / Keys  (3) Keys / Contexts</value>
    53    </textarea>
    54 
    5549   <textarea name="leftdesc" draworder="1" align="center">
    5650    <font>info</font>
    57     <area>0,40,370,20</area>
     51    <area>0,0,370,20</area>
    5852    <value>Contexts</value>
    5953   </textarea>
    6054
    6155   <listbtnarea name="leftlist" draworder="0">
    62     <area>0,60,370,380</area>
     56    <area>0,30,370,420</area>
    6357    <gradient type="unselected" start="#505050" end="#000000" alpha="100"/>
    6458    <gradient type="selected" start="#52CA38" end="#349838" alpha="255"/>
    6559    <fcnfont name="active" function="active"/>
     
    6963
    7064   <textarea name="rightdesc" draworder="1" align="center">
    7165    <font>info</font>
    72     <area>390,40,370,20</area>
     66    <area>390,0,370,20</area>
    7367    <value>Actions</value>
    7468   </textarea>
    7569
    7670   <listbtnarea name="rightlist" draworder="0">
    77     <area>390,60,370,380</area>
     71    <area>390,30,370,420</area>
    7872    <gradient type="unselected" start="#505050" end="#000000" alpha="100"/>
    7973    <gradient type="selected" start="#52CA38" end="#349838" alpha="255"/>
    8074    <fcnfont name="active" function="active"/>
  • mythcontrols/keygrabber.cpp

     
    126126{
    127127    addLabel(tr("Options"), Large, false);
    128128    addButton(QObject::tr("Save"),   this, SLOT(Save()));
     129    addButton(QObject::tr("Change View"), this, SLOT(ChangeView()));
    129130    addButton(QObject::tr("Cancel"), this, SLOT(Cancel()))->setFocus();
    130131}
    131132