MythTV master
visualizerview.cpp
Go to the documentation of this file.
1// C++
2#include <cstdlib>
3#include <iostream>
4
5// qt
6#include <QKeyEvent>
7#include <QTimer>
8
9// myth
19
20// mythmusic
21#include "mainvisual.h"
22#include "musiccommon.h"
23#include "visualizerview.h"
24
26 :MusicCommon(parent, parentScreen, "visualizerview")
27{
29}
30
32{
33 // Load the theme for this screen
34 bool err = LoadWindowFromXML("music-ui.xml", "visualizerview", this);
35
36 if (!err)
37 return false;
38
39 // find common widgets available on any view
40 err = CreateCommon();
41
42 // find widgets specific to this view
43
44 if (err)
45 {
46 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'visualizerview'");
47 return false;
48 }
49
51
53
54 return true;
55}
56
57void VisualizerView::customEvent(QEvent *event)
58{
59 if (event->type() == MusicPlayerEvent::kTrackChangeEvent ||
62
64}
65
66bool VisualizerView::keyPressEvent(QKeyEvent *event)
67{
69 return true;
70
71 QStringList actions;
72 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
73
74 for (int i = 0; i < actions.size() && !handled; i++)
75 {
76 QString action = actions[i];
77 handled = true;
78
81
82 // unassgined arrow keys might as well be useful
83 if (action == "UP")
84 {
85 action = "PREVTRACK";
86 previous();
87 }
88 else if (action == "DOWN")
89 {
90 action = "NEXTTRACK";
91 next();
92 }
93 else if (action == "LEFT")
94 {
95 action = "RWND";
96 seekback();
97 }
98 else if (action == "RIGHT")
99 {
100 action = "FFWD";
101 seekforward();
102 }
103
104 if (action == "INFO")
105 {
107 }
108 else if (
109 action == "NEXTTRACK" ||
110 action == "PREVTRACK" ||
111 action == "FFWD" ||
112 action == "RWND" ||
113 action == "THMBUP" ||
114 action == "THMBDOWN" ||
115 action == "SPEEDUP" ||
116 action == "SPEEDDOWN")
117 {
118 handled = MusicCommon::keyPressEvent(event);
120 }
121 else
122 {
123 handled = false;
124 }
125 }
126
127 if (!handled && MusicCommon::keyPressEvent(event))
128 handled = true;
129
130 return handled;
131}
132
134{
135 QString label = tr("Actions");
136
137 auto *menu = new MythMenu(label, this, "menu");
138
139 menu->AddItem(tr("Change Visualizer"), nullptr, createVisualizerMenu());
140 menu->AddItem(tr("Show Track Info"), &VisualizerView::showTrackInfoPopup);
141 menu->AddItem(tr("Other Options"), nullptr, createMainMenu());
142
143 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
144
145 auto *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
146
147 if (menuPopup->Create())
148 popupStack->AddScreen(menuPopup);
149 else
150 delete menuPopup;
151}
152
154{
156 return;
157 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
158
159 auto *popup = new TrackInfoPopup(popupStack);
160
161 if (popup->Create())
162 popupStack->AddScreen(popup);
163 else
164 delete popup;
165}
166
167//---------------------------------------------------------
168// TrackInfoPopup
169//---------------------------------------------------------
170static constexpr std::chrono::seconds MUSICINFOPOPUPTIME { 8s };
171
173{
174 if (m_displayTimer)
175 {
176 m_displayTimer->stop();
177 delete m_displayTimer;
178 m_displayTimer = nullptr;
179 }
180}
181
183{
184 bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
185
186 if (!err)
187 return false;
188
189 // find common widgets available on any view
190 err = CreateCommon();
191
192 if (err)
193 {
194 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'trackinfo_popup'");
195 return false;
196 }
198
199 // get map for current track
201 InfoMap metadataMap;
202 metadata->toMap(metadataMap);
203
204 // add the map from the next track
205 MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
206 if (nextMetadata)
207 nextMetadata->toMap(metadataMap, "next");
208
209 SetTextFromMap(metadataMap);
210
211 MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
212 if (ratingState)
213 ratingState->DisplayState(QString("%1").arg(metadata->Rating()));
214
215 MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
216 if (albumImage)
217 {
218 if (!metadata->getAlbumArtFile().isEmpty())
219 {
220 albumImage->SetFilename(metadata->getAlbumArtFile());
221 albumImage->Load();
222 }
223 }
224
225 m_displayTimer = new QTimer(this);
227 m_displayTimer->setSingleShot(true);
229
230 return true;
231}
232
233bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
234{
236 return true;
237
239 QStringList actions;
240 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
241
242 for (int i = 0; i < actions.size() && !handled; i++)
243 {
244 const QString& action = actions[i];
245 handled = true;
246
247 if (action == "SELECT")
248 {
249 if (m_displayTimer)
250 m_displayTimer->stop();
251 return true;
252 }
253 if (action == "ESCAPE")
254 {
255 Close();
256 }
257 else if (action == "INFO")
258 {
260 }
261 else if (action == "MENU")
262 {
263 // menu over info misbehaves: if we close after 8 seconds,
264 // then menu seg faults! We could workaround that by
265 // canceling our timer as shown here, but menu fails to
266 // get the visualizer list (how does m_visualModes.count()
267 // == 0?) So just doing nothing forces user to ESCAPE out
268 // of info to get to the working menu. -twitham
269
270 // if (m_displayTimer)
271 // {
272 // m_displayTimer->stop();
273 // delete m_displayTimer;
274 // m_displayTimer = nullptr;
275 // }
276 // handled = false;
277 }
278 else
279 {
280 handled = false;
281 }
282 }
283 // keep info up while seeking, theme should show progressbar/time
284 if (m_displayTimer)
286
287 if (!handled && VisualizerView::keyPressEvent(event))
288 handled = true;
289
290 return handled;
291}
VisualBase * visual(void) const
Definition: mainvisual.h:42
void seekforward(void)
void next(void)
MythMenu * createMainMenu(void)
MythMenu * createVisualizerMenu(void)
void seekback(void)
static void showTrackInfo(MusicMetadata *mdata)
MusicView m_currentView
Definition: musiccommon.h:143
bool CreateCommon(void)
Definition: musiccommon.cpp:78
void previous(void)
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
MainVisual * m_mainvisual
Definition: musiccommon.h:146
void customEvent(QEvent *event) override
void toMap(InfoMap &metadataMap, const QString &prefix="")
QString getAlbumArtFile(void)
int Rating() const
static const Type kPlayedTracksChangedEvent
Definition: musicplayer.h:50
static const Type kTrackChangeEvent
Definition: musicplayer.h:39
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
Basic menu dialog, message and a list of options.
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
MythScreenStack * GetStack(const QString &Stackname)
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Screen in which all other widgets are contained and rendered.
void BuildFocusList(void)
MythUIType * GetFocusWidget(void) const
virtual void Close()
virtual void SetTextFromMap(const InfoMap &infoMap)
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:98
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
This widget is used for grouping other widgets for display when a particular named state is called.
bool DisplayState(const QString &name)
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
QTimer * m_displayTimer
~TrackInfoPopup(void) override
bool Create(void) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
virtual void handleKeyPress(const QString &action)
Definition: visualize.h:83
VisualizerView(MythScreenStack *parent, MythScreenType *parentScreen)
void customEvent(QEvent *event) override
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
bool Create(void) override
void ShowMenu(void) override
void showTrackInfoPopup(void)
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
@ MV_VISUALIZERINFO
Definition: musiccommon.h:44
@ MV_VISUALIZER
Definition: musiccommon.h:37
MusicPlayer * gPlayer
Definition: musicplayer.cpp:38
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythMainWindow * GetMythMainWindow(void)
static MythThemedMenu * menu
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
static constexpr std::chrono::seconds MUSICINFOPOPUPTIME