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 <mythuitext.h>
14 #include <mythuiimage.h>
15 #include <mythuistatetype.h>
16 #include <mythuiutils.h>
17 #include <mythdialogbox.h>
18 
19 // mythmusic
20 #include "musiccommon.h"
21 #include "visualizerview.h"
22 
24  :MusicCommon(parent, parentScreen, "visualizerview")
25 {
27 }
28 
30 {
31  // Load the theme for this screen
32  bool err = LoadWindowFromXML("music-ui.xml", "visualizerview", this);
33 
34  if (!err)
35  return false;
36 
37  // find common widgets available on any view
38  err = CreateCommon();
39 
40  // find widgets specific to this view
41 
42  if (err)
43  {
44  LOG(VB_GENERAL, LOG_ERR, "Cannot load screen 'lyricsview'");
45  return false;
46  }
47 
49 
50  return true;
51 }
52 
53 void VisualizerView::customEvent(QEvent *event)
54 {
55  if (event->type() == MusicPlayerEvent::TrackChangeEvent ||
58 
60 }
61 
62 bool VisualizerView::keyPressEvent(QKeyEvent *event)
63 {
64  if (GetFocusWidget() && GetFocusWidget()->keyPressEvent(event))
65  return true;
66 
67  QStringList actions;
68  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions);
69 
70  for (int i = 0; i < actions.size() && !handled; i++)
71  {
72  QString action = actions[i];
73  handled = true;
74 
75  if (action == "INFO")
76  {
78  }
79  else
80  handled = false;
81  }
82 
83  if (!handled && MusicCommon::keyPressEvent(event))
84  handled = true;
85 
86  return handled;
87 }
88 
90 {
91  QString label = tr("Actions");
92 
93  auto *menu = new MythMenu(label, this, "menu");
94 
95  menu->AddItem(tr("Change Visualizer"), nullptr, createVisualizerMenu());
96  menu->AddItem(tr("Show Track Info"), &VisualizerView::showTrackInfoPopup);
97  menu->AddItem(tr("Other Options"), nullptr, createMainMenu());
98 
99  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
100 
101  auto *menuPopup = new MythDialogBox(menu, popupStack, "actionmenu");
102 
103  if (menuPopup->Create())
104  popupStack->AddScreen(menuPopup);
105  else
106  delete menuPopup;
107 }
108 
110 {
111  MythScreenStack *popupStack = GetMythMainWindow()->GetStack("popup stack");
112 
113  auto *popup = new TrackInfoPopup(popupStack, gPlayer->getCurrentMetadata());
114 
115  if (!popup->Create())
116  {
117  delete popup;
118  return;
119  }
120 
121  popupStack->AddScreen(popup);
122 }
123 
124 //---------------------------------------------------------
125 // TrackInfoPopup
126 //---------------------------------------------------------
127 static constexpr std::chrono::seconds MUSICINFOPOPUPTIME { 8s };
128 
130 {
131  if (m_displayTimer)
132  {
133  m_displayTimer->stop();
134  delete m_displayTimer;
135  m_displayTimer = nullptr;
136  }
137 }
138 
140 {
141  bool err = LoadWindowFromXML("music-ui.xml", "trackinfo_popup", this);
142 
143  if (!err)
144  return false;
145 
146  // get map for current track
147  InfoMap metadataMap;
148  m_metadata->toMap(metadataMap);
149 
150  // add the map from the next track
151  MusicMetadata *nextMetadata = gPlayer->getNextMetadata();
152  if (nextMetadata)
153  nextMetadata->toMap(metadataMap, "next");
154 
155  SetTextFromMap(metadataMap);
156 
157  MythUIStateType *ratingState = dynamic_cast<MythUIStateType *>(GetChild("ratingstate"));
158  if (ratingState)
159  ratingState->DisplayState(QString("%1").arg(m_metadata->Rating()));
160 
161  MythUIImage *albumImage = dynamic_cast<MythUIImage *>(GetChild("coverart"));
162  if (albumImage)
163  {
164  if (!m_metadata->getAlbumArtFile().isEmpty())
165  {
166  albumImage->SetFilename(m_metadata->getAlbumArtFile());
167  albumImage->Load();
168  }
169  }
170 
171  m_displayTimer = new QTimer(this);
173  m_displayTimer->setSingleShot(true);
175 
176  return true;
177 }
178 
179 bool TrackInfoPopup::keyPressEvent(QKeyEvent *event)
180 {
181  QStringList actions;
182  bool handled = GetMythMainWindow()->TranslateKeyPress("Music", event, actions, false);
183 
184  for (int i = 0; i < actions.size() && !handled; i++)
185  {
186  QString action = actions[i];
187  handled = true;
188 
189  if (action == "INFO")
190  Close();
191  else
192  handled = false;
193  }
194 
195  if (!handled && MythScreenType::keyPressEvent(event))
196  handled = true;
197 
198  return handled;
199 }
MusicCommon::m_currentView
MusicView m_currentView
Definition: musiccommon.h:139
TrackInfoPopup::Create
bool Create(void) override
Definition: visualizerview.cpp:139
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:97
MusicCommon::CreateCommon
bool CreateCommon(void)
Definition: musiccommon.cpp:80
MythScreenType::Close
virtual void Close()
Definition: mythscreentype.cpp:385
MusicCommon::keyPressEvent
bool keyPressEvent(QKeyEvent *e) override
Key event handler.
Definition: musiccommon.cpp:580
TrackInfoPopup
Definition: visualizerview.h:35
MythUIType::GetChild
MythUIType * GetChild(const QString &name) const
Get a named child of this UIType.
Definition: mythuitype.cpp:131
MusicCommon::createVisualizerMenu
MythMenu * createVisualizerMenu(void)
Definition: musiccommon.cpp:2371
MythUIImage::Load
bool Load(bool allowLoadInBackground=true, bool forceStat=false)
Load the image(s), wraps ImageLoader::LoadImage()
Definition: mythuiimage.cpp:968
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:44
mythuistatetype.h
MusicMetadata
Definition: musicmetadata.h:80
menu
static MythThemedMenu * menu
Definition: mythtv/programs/mythtv-setup/main.cpp:53
mythuibuttonlist.h
mythuiimage.h
TrackInfoPopup::~TrackInfoPopup
~TrackInfoPopup(void) override
Definition: visualizerview.cpp:129
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:1158
mythuiutils.h
MusicPlayerEvent::TrackChangeEvent
static Type TrackChangeEvent
Definition: musicplayer.h:40
MusicPlayerEvent::PlayedTracksChangedEvent
static Type PlayedTracksChangedEvent
Definition: musicplayer.h:51
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:1113
MusicMetadata::toMap
void toMap(InfoMap &metadataMap, const QString &prefix="")
Definition: musicmetadata.cpp:1091
MV_VISUALIZER
@ MV_VISUALIZER
Definition: musiccommon.h:36
MythDialogBox
Basic menu dialog, message and a list of options.
Definition: mythdialogbox.h:166
MusicMetadata::getAlbumArtFile
QString getAlbumArtFile(void)
Definition: musicmetadata.cpp:1261
TrackInfoPopup::m_metadata
MusicMetadata * m_metadata
Definition: visualizerview.h:48
MythScreenType::BuildFocusList
void BuildFocusList(void)
Definition: mythscreentype.cpp:205
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:109
VisualizerView::VisualizerView
VisualizerView(MythScreenStack *parent, MythScreenType *parentScreen)
Definition: visualizerview.cpp:23
VisualizerView::Create
bool Create(void) override
Definition: visualizerview.cpp:29
VisualizerView::customEvent
void customEvent(QEvent *event) override
Definition: visualizerview.cpp:53
musiccommon.h
MusicPlayer::getNextMetadata
MusicMetadata * getNextMetadata(void)
get the metadata for the next track in the playlist
Definition: musicplayer.cpp:1170
MusicCommon::createMainMenu
MythMenu * createMainMenu(void)
Definition: musiccommon.cpp:2175
MythMenu
Definition: mythdialogbox.h:99
MythScreenType::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: mythscreentype.cpp:397
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:179
mythcontext.h
GetMythMainWindow
MythMainWindow * GetMythMainWindow(void)
Definition: mythmainwindow.cpp:101
visualizerview.h
build_compdb.action
action
Definition: build_compdb.py:9
MythMainWindow::GetStack
MythScreenStack * GetStack(const QString &Stackname)
Definition: mythmainwindow.cpp:319
MusicMetadata::Rating
int Rating() const
Definition: musicmetadata.h:240
MythUIImage::SetFilename
void SetFilename(const QString &filename)
Must be followed by a call to Load() to load the image.
Definition: mythuiimage.cpp:676
mythmainwindow.h
MythScreenStack::AddScreen
virtual void AddScreen(MythScreenType *screen, bool allowFade=true)
Definition: mythscreenstack.cpp:50
MusicCommon::customEvent
void customEvent(QEvent *event) override
Definition: musiccommon.cpp:1184
MUSICINFOPOPUPTIME
static constexpr std::chrono::seconds MUSICINFOPOPUPTIME
Definition: visualizerview.cpp:127
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:47
VisualizerView::ShowMenu
void ShowMenu(void) override
Definition: visualizerview.cpp:89
VisualizerView::keyPressEvent
bool keyPressEvent(QKeyEvent *event) override
Key event handler.
Definition: visualizerview.cpp:62