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
10 #include <libmyth/mythcontext.h>
11 #include <libmythbase/mythdbcon.h>
14 #include <libmythui/mythuiimage.h>
16 #include <libmythui/mythuitext.h>
17 #include <libmythui/mythuiutils.h>
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 
57 void VisualizerView::customEvent(QEvent *event)
58 {
59  if (event->type() == MusicPlayerEvent::kTrackChangeEvent ||
62 
64 }
65 
66 bool VisualizerView::keyPressEvent(QKeyEvent *event)
67 {
68  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
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  handled = false;
121  }
122 
123  if (!handled && MusicCommon::keyPressEvent(event))
124  handled = true;
125 
126  return handled;
127 }
128 
130 {
131  QString label = tr("Actions");
132 
133  auto *menu = new MythMenu(label, this, "menu");
134 
135  menu->AddItem(tr("Change Visualizer"), nullptr, createVisualizerMenu());
136  menu->AddItem(tr("Show Track Info"), &VisualizerView::showTrackInfoPopup);
137  menu->AddItem(tr("Other Options"), nullptr, createMainMenu());
138 
139  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
140 
141  auto *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
142 
143  if (menuPopup->Create())
144  popupStack->AddScreen(menuPopup);
145  else
146  delete menuPopup;
147 }
148 
150 {
152  return;
153  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
154 
155  auto *popup = new TrackInfoPopup(popupStack);
156 
157  if (popup->Create())
158  popupStack->AddScreen(popup);
159  else
160  delete popup;
161 }
162 
163 //---------------------------------------------------------
164 // TrackInfoPopup
165 //---------------------------------------------------------
166 static constexpr std::chrono::seconds MUSICINFOPOPUPTIME { 8s };
167 
169 {
170  if (m_displayTimer)
171  {
172  m_displayTimer->stop();
173  delete m_displayTimer;
174  m_displayTimer = nullptr;
175  }
176 }
177 
179 {
180  bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
181 
182  if (!err)
183  return false;
184 
185  // find common widgets available on any view
186  err = CreateCommon();
187 
188  if (err)
189  {
190  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'trackinfo_popup'");
191  return false;
192  }
194 
195  // get map for current track
197  InfoMap metadataMap;
198  metadata->toMap(metadataMap);
199 
200  // add the map from the next track
201  MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
202  if (nextMetadata)
203  nextMetadata->toMap(metadataMap, "next");
204 
205  SetTextFromMap(metadataMap);
206 
207  MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
208  if (ratingState)
209  ratingState->DisplayState(QString("%1").arg(metadata->Rating()));
210 
211  MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
212  if (albumImage)
213  {
214  if (!metadata->getAlbumArtFile().isEmpty())
215  {
216  albumImage->SetFilename(metadata->getAlbumArtFile());
217  albumImage->Load();
218  }
219  }
220 
221  m_displayTimer = new QTimer(this);
223  m_displayTimer->setSingleShot(true);
225 
226  return true;
227 }
228 
229 bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
230 {
231  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
232  return true;
233 
235  QStringList actions;
236  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
237 
238  for (int i = 0; i < actions.size() && !handled; i++)
239  {
240  QString action = actions[i];
241  handled = true;
242 
243  if (action == "SELECT")
244  {
245  if (m_displayTimer)
246  m_displayTimer->stop();
247  return true;
248  }
249  if (action == "ESCAPE")
250  Close();
251  else if (action == "INFO")
253  else if (action == "MENU")
254  {
255  // menu over info misbehaves: if we close after 8 seconds,
256  // then menu seg faults! We could workaround that by
257  // canceling our timer as shown here, but menu fails to
258  // get the visualizer list (how does m_visualModes.count()
259  // == 0?) So just doing nothing forces user to ESCAPE out
260  // of info to get to the working menu. -twitham
261 
262  // if (m_displayTimer)
263  // {
264  // m_displayTimer->stop();
265  // delete m_displayTimer;
266  // m_displayTimer = nullptr;
267  // }
268  // handled = false;
269  }
270  else
271  handled = false;
272  }
273  // keep info up while seeking, theme should show progressbar/time
274  if (m_displayTimer)
276 
277  if (!handled && VisualizerView::keyPressEvent(event))
278  handled = true;
279 
280  return handled;
281 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:141
TrackInfoPopup::Create
bool Create(void) override
Definition: visualizerview.cpp:178
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:37
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:102
mythuitext.h
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
MusicCommon::seekforward
void seekforward(void)
Definition: musiccommon.cpp:1090
MusicCommon::CreateCommon
bool CreateCommon(void)
Definition: musiccommon.cpp:76
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:386
MusicCommon::keyPressEvent
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
Definition: musiccommon.cpp:573
TrackInfoPopup
Definition: visualizerview.h:36
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:135
MusicCommon::createVisualizerMenu
MythMenu * createVisualizerMenu(void)
Definition: musiccommon.cpp:2409
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:966
MusicCommon::previous
void previous(void)
Definition: musiccommon.cpp:1082
MusicCommon::seekback
void seekback(void)
Definition: musiccommon.cpp:1097
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
MusicCommon::next
void next(void)
Definition: musiccommon.cpp:1073
MusicCommon::showTrackInfo
static void showTrackInfo(MusicMetadata *mdata)
Definition: musiccommon.cpp:1959
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
mythuistatetype.h
MusicMetadata
Definition: musicmetadata.h:80
mythuibuttonlist.h
mythuiimage.h
TrackInfoPopup::~TrackInfoPopup
~TrackInfoPopup(void) override
Definition: visualizerview.cpp:168
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:113
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MusicPlayerEvent::kPlayedTracksChangedEvent
static const Type kPlayedTracksChangedEvent
Definition: musicplayer.h:50
MusicPlayer::getCurrentMetadata
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
Definition: musicplayer.cpp:1170
mythuiutils.h
MV_VISUALIZERINFO
@ MV_VISUALIZERINFO
Definition: musiccommon.h:44
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &Context, QKeyEvent *Event, QStringList &Actions, bool AllowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1112
MusicMetadata::toMap
void toMap(InfoMap &metadataMap, const QString &prefix="")
Definition: musicmetadata.cpp:1088
MV_VISUALIZER
@ MV_VISUALIZER
Definition: musiccommon.h:37
MusicPlayerEvent::kTrackChangeEvent
static const Type kTrackChangeEvent
Definition: musicplayer.h:39
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
menu
static MythThemedMenu * menu
Definition: mythtv-setup.cpp:58
MusicMetadata::getAlbumArtFile
QString getAlbumArtFile(void)
Definition: musicmetadata.cpp:1258
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:206
TrackInfoPopup::m_displayTimer
QTimer * m_displayTimer
Definition: visualizerview.h:48
MythUIComposite::SetTextFromMap
virtual void SetTextFromMap(const InfoMap &infoMap)
Definition: mythuicomposite.cpp:9
MusicCommon::m_mainvisual
MainVisual * m_mainvisual
Definition: musiccommon.h:144
VisualizerView::showTrackInfoPopup
void showTrackInfoPopup(void)
Definition: visualizerview.cpp:149
VisualizerView::VisualizerView
VisualizerView(MythScreenStack *parent, MythScreenType *parentScreen)
Definition: visualizerview.cpp:25
VisualizerView::Create
bool Create(void) override
Definition: visualizerview.cpp:31
MainVisual::visual
VisualBase * visual(void) const
Definition: mainvisual.h:42
VisualizerView::customEvent
void customEvent(QEvent *event) override
Definition: visualizerview.cpp:57
musiccommon.h
MusicPlayer::getNextMetadata
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
Definition: musicplayer.cpp:1182
MusicCommon::createMainMenu
MythMenu * createMainMenu(void)
Definition: musiccommon.cpp:2205
MythMenu
Definition: mythdialogbox.h:99
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:687
TrackInfoPopup::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:229
mythcontext.h
mainvisual.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:104
visualizerview.h
build_compdb.action
action
Definition: build_compdb.py:9
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:323
MusicMetadata::Rating
int Rating() const
Definition: musicmetadata.h:239
MythUIImage::SetFilename
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
Definition: mythuiimage.cpp:674
VisualBase::handleKeyPress
virtual void handleKeyPress([[maybe_unused]] const QString &action)
Definition: visualize.h:81
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:52
MusicCommon::customEvent
void customEvent(QEvent *event) override
Definition: musiccommon.cpp:1180
MUSICINFOPOPUPTIME
static constexpr std::chrono::seconds MUSICINFOPOPUPTIME
Definition: visualizerview.cpp:166
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called....
Definition: mythuistatetype.h:22
MythUIStateType::DisplayState
bool DisplayState(const QString &name)
Definition: mythuistatetype.cpp:84
MusicCommon
Definition: musiccommon.h:49
VisualizerView::ShowMenu
void ShowMenu(void) override
Definition: visualizerview.cpp:129
VisualizerView::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:66