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 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:139
TrackInfoPopup::Create
bool Create(void) override
Definition: visualizerview.cpp:140
gPlayer
MusicPlayer * gPlayer
Definition: musicplayer.cpp:35
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:98
MusicCommon::CreateCommon
bool CreateCommon(void)
Definition: musiccommon.cpp:81
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:402
MusicCommon::keyPressEvent
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
Definition: musiccommon.cpp:581
TrackInfoPopup
Definition: visualizerview.h:36
MythMainWindow::TranslateKeyPress
bool TranslateKeyPress(const QString &context, QKeyEvent *e, QStringList &actions, bool allowJumps=true)
Get a list of actions for a keypress in the given context.
Definition: mythmainwindow.cpp:1106
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:130
MusicCommon::createVisualizerMenu
MythMenu * createVisualizerMenu(void)
Definition: musiccommon.cpp:2374
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:967
mythdialogbox.h
MythScreenStack
Definition: mythscreenstack.h:16
mythdbcon.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
MythScreenType
Screen in which all other widgets are contained and rendered.
Definition: mythscreentype.h:45
mythuistatetype.h
MusicMetadata
Definition: musicmetadata.h:81
menu
static MythThemedMenu * menu
Definition: mythtv/programs/mythtv-setup/main.cpp:55
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &stackname)
Definition: mythmainwindow.cpp:309
mythuibuttonlist.h
mythuiimage.h
TrackInfoPopup::~TrackInfoPopup
~TrackInfoPopup(void) override
Definition: visualizerview.cpp:130
MythScreenType::GetFocusWidget
MythUIType * GetFocusWidget(void) const
Definition: mythscreentype.cpp:112
InfoMap
QHash< QString, QString > InfoMap
Definition: mythtypes.h:15
MusicPlayer::getCurrentMetadata
MusicMetadata * getCurrentMetadata(void)
get the metadata for the current track in the playlist
Definition: musicplayer.cpp:1155
mythuiutils.h
MusicPlayerEvent::TrackChangeEvent
static Type TrackChangeEvent
Definition: musicplayer.h:40
MusicPlayerEvent::PlayedTracksChangedEvent
static Type PlayedTracksChangedEvent
Definition: musicplayer.h:51
MUSICINFOPOPUPTIME
#define MUSICINFOPOPUPTIME
Definition: visualizerview.cpp:128
MusicMetadata::toMap
void toMap(InfoMap &metadataMap, const QString &prefix="")
Definition: musicmetadata.cpp:1099
MV_VISUALIZER
@ MV_VISUALIZER
Definition: musiccommon.h:36
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:138
MusicMetadata::getAlbumArtFile
QString getAlbumArtFile(void)
Definition: musicmetadata.cpp:1269
TrackInfoPopup::m_metadata
MusicMetadata * m_metadata
Definition: visualizerview.h:48
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:222
TrackInfoPopup::m_displayTimer
QTimer * m_displayTimer
Definition: visualizerview.h:49
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:54
musiccommon.h
MusicPlayer::getNextMetadata
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
Definition: musicplayer.cpp:1167
MusicCommon::createMainMenu
MythMenu * createMainMenu(void)
Definition: musiccommon.cpp:2178
MythMenu
Definition: mythdialogbox.h:93
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:414
XMLParseBase::LoadWindowFromXML
static bool LoadWindowFromXML(const QString &xmlfile, const QString &windowname, MythUIType *parent)
Definition: xmlparsebase.cpp:692
TrackInfoPopup::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:180
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:107
visualizerview.h
build_compdb.action
action
Definition: build_compdb.py:9
MusicMetadata::Rating
int Rating() const
Definition: musicmetadata.h:238
MythUIImage::SetFilename
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
Definition: mythuiimage.cpp:675
mythuiwebbrowser.h
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:49
MusicCommon::customEvent
void customEvent(QEvent *event) override
Definition: musiccommon.cpp:1186
MythUIStateType
This widget is used for grouping other widgets for display when a particular named state is called....
Definition: mythuistatetype.h:23
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:63