MythTV  master
miniplayer.cpp
Go to the documentation of this file.
1 
2 #include "miniplayer.h"
3 
4 // mythtv
5 #include <mythcontext.h>
6 #include <mythmainwindow.h>
7 #include <lcddevice.h>
8 
9 // mythmusic
10 #include "musicplayer.h"
11 #include "decoder.h"
12 
13 #include <QTimer>
14 
16  : MusicCommon(parent, nullptr, "music_miniplayer")
17 {
19  m_displayTimer = new QTimer(this);
20  m_displayTimer->setSingleShot(true);
21  connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(timerTimeout()));
22 }
23 
25 {
26  gPlayer->removeListener(this);
27 
28  // Timers are deleted by Qt
29  m_displayTimer->disconnect();
30  m_displayTimer = nullptr;
31 
32  if (LCD *lcd = LCD::Get())
33  lcd->switchToTime ();
34 }
35 
37 {
38  Close();
39 }
40 
42 {
43  // Load the theme for this screen
44  bool err = LoadWindowFromXML("music-ui.xml", "miniplayer", this);
45 
46  if (!err)
47  return false;
48 
49  // find common widgets available on any view
50  err = CreateCommon();
51 
52  if (err)
53  {
54  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'miniplayer'");
55  return false;
56  }
57 
58  m_displayTimer->start(10000);
59 
61 
62  return true;
63 }
64 
65 bool MiniPlayer::keyPressEvent(QKeyEvent *event)
66 {
67  // restart the display timer on any keypress if it is active
68  if (m_displayTimer && m_displayTimer->isActive())
69  m_displayTimer->start();
70 
71  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
72  return true;
73 
74  QStringList actions;
75  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
76 
77  for (int i = 0; i < actions.size() && !handled; i++)
78  {
79  QString action = actions[i];
80  handled = true;
81 
82  if (action == "SELECT")
83  {
84  if (m_displayTimer)
85  m_displayTimer->stop();
86  }
87  else if (action == "ESCAPE")
88  {
89  Close();
90  }
91  else if (action == "MENU")
92  {
94  //showAutoMode();
95  }
96  else
97  handled = false;
98  }
99 
100  if (!handled && MusicCommon::keyPressEvent(event))
101  handled = true;
102 
103  return handled;
104 }
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
void timerTimeout(void)
Definition: miniplayer.cpp:36
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
void removeListener(QObject *listener)
MusicView m_currentView
Definition: musiccommon.h:139
void BuildFocusList(void)
MiniPlayer(MythScreenStack *parent)
Definition: miniplayer.cpp:15
static LCD * Get(void)
Definition: lcddevice.cpp:65
virtual void Close()
bool getAutoShowPlayer(void)
Definition: musicplayer.h:109
bool keyPressEvent(QKeyEvent *) override
Key event handler.
Definition: miniplayer.cpp:65
bool Create(void) override
Definition: miniplayer.cpp:41
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
Definition: lcddevice.h:165
QTimer * m_displayTimer
Definition: miniplayer.h:25
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
bool CreateCommon(void)
Definition: musiccommon.cpp:84
void autoShowPlayer(bool autoShow)
This will allow/disallow the mini player showing on track changes.
Definition: musicplayer.h:108