MythTV  master
visualizerview.cpp
Go to the documentation of this file.
1 #include <iostream>
2 #include <cstdlib>
3 
4 // qt
5 #include <QKeyEvent>
6 #include <QTimer>
7 
8 // myth
9 #include <mythcontext.h>
10 #include <mythdbcon.h>
11 #include <mythmainwindow.h>
12 #include <mythuibuttonlist.h>
13 #include <mythuiwebbrowser.h>
14 #include <mythuitext.h>
15 #include <mythuiimage.h>
16 #include <mythuistatetype.h>
17 #include <mythuiutils.h>
18 #include <mythdialogbox.h>
19 
20 // mythmusic
21 #include "musiccommon.h"
22 #include "visualizerview.h"
23 
25  :MusicCommon(parent, parentScreen, "visualizerview")
26 {
28 }
29 
31 {
32  // Load the theme for this screen
33  bool err = LoadWindowFromXML("music-ui.xml", "visualizerview", this);
34 
35  if (!err)
36  return false;
37 
38  // find common widgets available on any view
39  err = CreateCommon();
40 
41  // find widgets specific to this view
42 
43  if (err)
44  {
45  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'lyricsview'");
46  return false;
47  }
48 
50 
51  return true;
52 }
53 
54 void VisualizerView::customEvent(QEvent *event)
55 {
56  if (event->type() == MusicPlayerEvent::TrackChangeEvent ||
59 
61 }
62 
63 bool VisualizerView::keyPressEvent(QKeyEvent *event)
64 {
65  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
66  return true;
67 
68  QStringList actions;
69  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
70 
71  for (int i = 0; i < actions.size() && !handled; i++)
72  {
73  QString action = actions[i];
74  handled = true;
75 
76  if (action == "INFO")
77  {
79  }
80  else
81  handled = false;
82  }
83 
84  if (!handled && MusicCommon::keyPressEvent(event))
85  handled = true;
86 
87  return handled;
88 }
89 
91 {
92  QString label = tr("Actions");
93 
94  auto *menu = new MythMenu(label, this, "menu");
95 
96  menu->AddItem(tr("Change Visualizer"), nullptr, createVisualizerMenu());
97  menu->AddItem(tr("Show Track Info"), SLOT(showTrackInfoPopup()));
98  menu->AddItem(tr("Other Options"), nullptr, createMainMenu());
99 
100  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
101 
102  auto *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
103 
104  if (menuPopup->Create())
105  popupStack->AddScreen(menuPopup);
106  else
107  delete menuPopup;
108 }
109 
111 {
112  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
113 
114  auto *popup = new TrackInfoPopup(popupStack, gPlayer->getCurrentMetadata());
115 
116  if (!popup->Create())
117  {
118  delete popup;
119  return;
120  }
121 
122  popupStack->AddScreen(popup);
123 }
124 
125 //---------------------------------------------------------
126 // TrackInfoPopup
127 //---------------------------------------------------------
128 #define MUSICINFOPOPUPTIME (8 * 1000)
129 
131 {
132  if (m_displayTimer)
133  {
134  m_displayTimer->stop();
135  delete m_displayTimer;
136  m_displayTimer = nullptr;
137  }
138 }
139 
141 {
142  bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
143 
144  if (!err)
145  return false;
146 
147  // get map for current track
148  InfoMap metadataMap;
149  m_metadata->toMap(metadataMap);
150 
151  // add the map from the next track
152  MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
153  if (nextMetadata)
154  nextMetadata->toMap(metadataMap, "next");
155 
156  SetTextFromMap(metadataMap);
157 
158  MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
159  if (ratingState)
160  ratingState->DisplayState(QString("%1").arg(m_metadata->Rating()));
161 
162  MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
163  if (albumImage)
164  {
165  if (!m_metadata->getAlbumArtFile().isEmpty())
166  {
167  albumImage->SetFilename(m_metadata->getAlbumArtFile());
168  albumImage->Load();
169  }
170  }
171 
172  m_displayTimer = new QTimer(this);
173  connect(m_displayTimer, SIGNAL(timeout()), this, SLOT(Close()));
174  m_displayTimer->setSingleShot(true);
176 
177  return true;
178 }
179 
180 bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
181 {
182  QStringList actions;
183  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
184 
185  for (int i = 0; i < actions.size() && !handled; i++)
186  {
187  QString action = actions[i];
188  handled = true;
189 
190  if (action == "INFO")
191  Close();
192  else
193  handled = false;
194  }
195 
196  if (!handled && MythScreenType::keyPressEvent(event))
197  handled = true;
198 
199  return handled;
200 }
This widget is used for grouping other widgets for display when a particular named state is called.
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
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 customEvent(QEvent *event) override
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MusicView m_currentView
Definition: musiccommon.h:139
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
Basic menu dialog, message and a list of options.
static void showTrackInfoPopup(void)
void customEvent(QEvent *event) override
MythScreenStack * GetStack(const QString &stackname)
void ShowMenu(void) override
static MythThemedMenu * menu
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
MythMenu * createVisualizerMenu(void)
void BuildFocusList(void)
QTimer * m_displayTimer
int Rating() const
bool Create(void) override
bool keyPressEvent(QKeyEvent *) override
Key event handler.
static Type TrackChangeEvent
Definition: musicplayer.h:40
virtual void Close()
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
#define MUSICINFOPOPUPTIME
MythMenu * createMainMenu(void)
QString getAlbumArtFile(void)
virtual void SetTextFromMap(const InfoMap &infoMap)
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
MythUIType * GetFocusWidget(void) const
MythMainWindow * GetMythMainWindow(void)
MusicMetadata * m_metadata
bool keyPressEvent(QKeyEvent *) override
Key event handler.
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
bool DisplayState(const QString &name)
static Type PlayedTracksChangedEvent
Definition: musicplayer.h:51
VisualizerView(MythScreenStack *parent, MythScreenType *parentScreen)
bool Create(void) override
Screen in which all other widgets are contained and rendered.
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:132
void toMap(InfoMap &metadataMap, const QString &prefix="")
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
bool CreateCommon(void)
Definition: musiccommon.cpp:81