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")
106 else if (
107 action == "NEXTTRACK" ||
108 action == "PREVTRACK" ||
109 action == "FFWD" ||
110 action == "RWND" ||
111 action == "THMBUP" ||
112 action == "THMBDOWN" ||
113 action == "SPEEDUP" ||
114 action == "SPEEDDOWN")
115 {
116 handled = MusicCommon::keyPressEvent(event);
118 }
119 else
120 {
121 handled = false;
122 }
123 }
124
125 if (!handled && MusicCommon::keyPressEvent(event))
126 handled = true;
127
128 return handled;
129}
130
132{
133 QString label = tr("Actions");
134
135 auto *menu = new MythMenu(label, this, "menu");
136
137 menu->AddItem(tr("Change Visualizer"), nullptr, createVisualizerMenu());
138 menu->AddItem(tr("Show Track Info"), &VisualizerView::showTrackInfoPopup);
139 menu->AddItem(tr("Other Options"), nullptr, createMainMenu());
140
141 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
142
143 auto *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
144
145 if (menuPopup->Create())
146 popupStack->AddScreen(menuPopup);
147 else
148 delete menuPopup;
149}
150
152{
154 return;
155 MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
156
157 auto *popup = new TrackInfoPopup(popupStack);
158
159 if (popup->Create())
160 popupStack->AddScreen(popup);
161 else
162 delete popup;
163}
164
165//---------------------------------------------------------
166// TrackInfoPopup
167//---------------------------------------------------------
168static constexpr std::chrono::seconds MUSICINFOPOPUPTIME { 8s };
169
171{
172 if (m_displayTimer)
173 {
174 m_displayTimer->stop();
175 delete m_displayTimer;
176 m_displayTimer = nullptr;
177 }
178}
179
181{
182 bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
183
184 if (!err)
185 return false;
186
187 // find common widgets available on any view
188 err = CreateCommon();
189
190 if (err)
191 {
192 LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'trackinfo_popup'");
193 return false;
194 }
196
197 // get map for current track
199 InfoMap metadataMap;
200 metadata->toMap(metadataMap);
201
202 // add the map from the next track
203 MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
204 if (nextMetadata)
205 nextMetadata->toMap(metadataMap, "next");
206
207 SetTextFromMap(metadataMap);
208
209 MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
210 if (ratingState)
211 ratingState->DisplayState(QString("%1").arg(metadata->Rating()));
212
213 MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
214 if (albumImage)
215 {
216 if (!metadata->getAlbumArtFile().isEmpty())
217 {
218 albumImage->SetFilename(metadata->getAlbumArtFile());
219 albumImage->Load();
220 }
221 }
222
223 m_displayTimer = new QTimer(this);
225 m_displayTimer->setSingleShot(true);
227
228 return true;
229}
230
231bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
232{
234 return true;
235
237 QStringList actions;
238 bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
239
240 for (int i = 0; i < actions.size() && !handled; i++)
241 {
242 const QString& action = actions[i];
243 handled = true;
244
245 if (action == "SELECT")
246 {
247 if (m_displayTimer)
248 m_displayTimer->stop();
249 return true;
250 }
251 if (action == "ESCAPE")
252 Close();
253 else if (action == "INFO")
255 else if (action == "MENU")
256 {
257 // menu over info misbehaves: if we close after 8 seconds,
258 // then menu seg faults! We could workaround that by
259 // canceling our timer as shown here, but menu fails to
260 // get the visualizer list (how does m_visualModes.count()
261 // == 0?) So just doing nothing forces user to ESCAPE out
262 // of info to get to the working menu. -twitham
263
264 // if (m_displayTimer)
265 // {
266 // m_displayTimer->stop();
267 // delete m_displayTimer;
268 // m_displayTimer = nullptr;
269 // }
270 // handled = false;
271 }
272 else
273 {
274 handled = false;
275 }
276 }
277 // keep info up while seeking, theme should show progressbar/time
278 if (m_displayTimer)
280
281 if (!handled && VisualizerView::keyPressEvent(event))
282 handled = true;
283
284 return handled;
285}
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:141
bool CreateCommon(void)
Definition: musiccommon.cpp:78
void previous(void)
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
MainVisual * m_mainvisual
Definition: musiccommon.h:144
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:138
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:79
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