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 "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 'visualizerview'");
46  return false;
47  }
48 
50 
52 
53  return true;
54 }
55 
56 void VisualizerView::customEvent(QEvent *event)
57 {
58  if (event->type() == MusicPlayerEvent::kTrackChangeEvent ||
61 
63 }
64 
65 bool VisualizerView::keyPressEvent(QKeyEvent *event)
66 {
67  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
68  return true;
69 
70  QStringList actions;
71  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
72 
73  for (int i = 0; i < actions.size() && !handled; i++)
74  {
75  QString action = actions[i];
76  handled = true;
77 
78  if (action == "INFO")
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"), &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);
115 
116  if (popup->Create())
117  popupStack->AddScreen(popup);
118  else
119  delete popup;
120 }
121 
122 //---------------------------------------------------------
123 // TrackInfoPopup
124 //---------------------------------------------------------
125 static constexpr std::chrono::seconds MUSICINFOPOPUPTIME { 8s };
126 
128 {
129  if (m_displayTimer)
130  {
131  m_displayTimer->stop();
132  delete m_displayTimer;
133  m_displayTimer = nullptr;
134  }
135 }
136 
138 {
139  bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
140 
141  if (!err)
142  return false;
143 
144  // find common widgets available on any view
145  m_currentView = MV_VISUALIZER; // reverted to zero ?!
146  err = CreateCommon();
147 
148  if (err)
149  {
150  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'trackinfo_popup'");
151  return false;
152  }
153 
154  // get map for current track
156  InfoMap metadataMap;
157  metadata->toMap(metadataMap);
158 
159  // add the map from the next track
160  MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
161  if (nextMetadata)
162  nextMetadata->toMap(metadataMap, "next");
163 
164  SetTextFromMap(metadataMap);
165 
166  MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
167  if (ratingState)
168  ratingState->DisplayState(QString("%1").arg(metadata->Rating()));
169 
170  MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
171  if (albumImage)
172  {
173  if (!metadata->getAlbumArtFile().isEmpty())
174  {
175  albumImage->SetFilename(metadata->getAlbumArtFile());
176  albumImage->Load();
177  }
178  }
179 
180  m_displayTimer = new QTimer(this);
182  m_displayTimer->setSingleShot(true);
184 
185  return true;
186 }
187 
188 bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
189 {
190  QStringList actions;
191  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
192 
193  for (int i = 0; i < actions.size() && !handled; i++)
194  {
195  QString action = actions[i];
196  handled = true;
197 
198  if (action == "ESCAPE")
199  Close();
200  else if (action == "INFO")
202  else if (action == "MENU")
203  {
204  // menu over info misbehaves: if we close after 8 seconds,
205  // then menu seg faults! We could workaround that by
206  // canceling our timer as shown here, but menu fails to
207  // get the visualizer list (how does m_visualModes.count()
208  // == 0?) So just doing nothing forces user to ESCAPE out
209  // of info to get to the working menu. -twitham
210 
211  // if (m_displayTimer)
212  // {
213  // m_displayTimer->stop();
214  // delete m_displayTimer;
215  // m_displayTimer = nullptr;
216  // }
217  // handled = false;
218  }
219  else
220  handled = false;
221  }
222  // keep info up while seeking, theme should show progressbar/time
223  if (m_displayTimer)
225 
226  if (!handled && VisualizerView::keyPressEvent(event))
227  handled = true;
228 
229  return handled;
230 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:140
TrackInfoPopup::Create
bool Create(void) override
Definition: visualizerview.cpp:137
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:37
hardwareprofile.smolt.timeout
float timeout
Definition: smolt.py:103
mythuitext.h
MythUIImage
Image widget, displays a single image or multiple images in sequence.
Definition: mythuiimage.h:97
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:576
TrackInfoPopup
Definition: visualizerview.h:36
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:133
MusicCommon::createVisualizerMenu
MythMenu * createVisualizerMenu(void)
Definition: musiccommon.cpp:2376
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:966
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
MusicCommon::showTrackInfo
static void showTrackInfo(MusicMetadata *mdata)
Definition: musiccommon.cpp:1946
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:127
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:1160
mythuiutils.h
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:1111
MusicMetadata::toMap
void toMap(InfoMap &metadataMap, const QString &prefix="")
Definition: musicmetadata.cpp:1085
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:1255
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
VisualizerView::showTrackInfoPopup
static void showTrackInfoPopup(void)
Definition: visualizerview.cpp:110
VisualizerView::VisualizerView
VisualizerView(MythScreenStack *parent, MythScreenType *parentScreen)
Definition: visualizerview.cpp:24
VisualizerView::Create
bool Create(void) override
Definition: visualizerview.cpp:30
VisualizerView::customEvent
void customEvent(QEvent *event) override
Definition: visualizerview.cpp:56
musiccommon.h
MusicPlayer::getNextMetadata
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
Definition: musicplayer.cpp:1172
MusicCommon::createMainMenu
MythMenu * createMainMenu(void)
Definition: musiccommon.cpp:2180
MythMenu
Definition: mythdialogbox.h:99
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:695
TrackInfoPopup::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:188
mythcontext.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
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:1184
MUSICINFOPOPUPTIME
static constexpr std::chrono::seconds MUSICINFOPOPUPTIME
Definition: visualizerview.cpp:125
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:48
VisualizerView::ShowMenu
void ShowMenu(void) override
Definition: visualizerview.cpp:90
VisualizerView::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:65