-
Notifications
You must be signed in to change notification settings - Fork 341
/
mythnavigationoverlay.cpp
210 lines (178 loc) · 5.84 KB
/
mythnavigationoverlay.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// MythTV
#include "mythmainwindow.h"
#include "mythdialogbox.h"
#include "mythuigroup.h"
#include "mythuibutton.h"
#include "mythplayerui.h"
#include "tv_play.h"
#include "overlays/mythnavigationoverlay.h"
MythNavigationOverlay::MythNavigationOverlay(MythMainWindow *MainWindow, TV* Tv,
MythPlayerUI *Player, const QString& Name, OSD* Osd)
: MythScreenType(static_cast<MythScreenType*>(nullptr), Name),
m_mainWindow(MainWindow),
m_tv(Tv),
m_player(Player),
m_parentOverlay(Osd)
{
}
bool MythNavigationOverlay::Create()
{
// Setup screen
if (!XMLParseBase::LoadWindowFromXML("osd.xml", "osd_navigation", this))
return false;
MythUIButton* more = nullptr;
UIUtilW::Assign(this, more, "more");
if (more)
connect(more, &MythUIButton::Clicked, this, &MythNavigationOverlay::More);
UIUtilW::Assign(this, m_pauseButton, "PAUSE");
UIUtilW::Assign(this, m_playButton, "PLAY");
UIUtilW::Assign(this, m_muteButton, "MUTE");
UIUtilW::Assign(this, m_unMuteButton, "unmute");
// Listen for player state changes
connect(m_player, &MythPlayerUI::PauseChanged, this, &MythNavigationOverlay::PauseChanged);
connect(m_player, &MythPlayerUI::AudioStateChanged, this, &MythNavigationOverlay::AudioStateChanged);
// Default constructor uses kMuteOff. Set initial mute button state accordingly
// and then request latest state.
if (m_muteButton)
m_muteButton->Show();
if (m_unMuteButton)
m_unMuteButton->Hide();
m_player->RefreshAudioState();
// TODO convert to video state when ready
bool paused = m_player->IsPaused();
m_paused = !paused;
PauseChanged(paused);
// Find number of groups and make sure only corrrect one is visible
MythUIGroup *group = nullptr;
for (int i = 0; i < 100 ; i++)
{
UIUtilW::Assign(this, group, QString("grp%1").arg(i));
if (!group)
break;
m_maxGroupNum = i;
if (i != m_visibleGroup)
group->SetVisible(false);
QList<MythUIType *> * children = group->GetAllChildren();
for (auto * child : qAsConst(*children))
{
if (child != more)
{
auto * button = dynamic_cast<MythUIButton*>(child);
if (button)
connect(button, &MythUIButton::Clicked, this, &MythNavigationOverlay::GeneralAction);
}
}
}
BuildFocusList();
return true;
}
bool MythNavigationOverlay::keyPressEvent(QKeyEvent* Event)
{
bool extendtimeout = true;
bool handled = false;
MythUIType* current = GetFocusWidget();
if (current && current->keyPressEvent(Event))
handled = true;
if (!handled)
{
QStringList actions;
handled = m_mainWindow->TranslateKeyPress("qt", Event, actions);
for (int i = 0; i < actions.size() && !handled; i++)
{
QString action = actions[i];
if (action == "ESCAPE" )
{
SendResult(-1, action);
handled = true;
extendtimeout = false;
}
}
}
if (!handled && MythScreenType::keyPressEvent(Event))
handled = true;
if (extendtimeout)
m_parentOverlay->SetExpiry(OSD_DLG_NAVIGATE, kOSDTimeout_Long);
return handled;
}
void MythNavigationOverlay::ShowMenu()
{
SendResult(100, "MENU");
}
void MythNavigationOverlay::SendResult(int Result, const QString& Action)
{
auto * dce = new DialogCompletionEvent("", Result, "", Action);
QCoreApplication::postEvent(m_tv, dce);
}
void MythNavigationOverlay::PauseChanged(bool Paused)
{
if (!(m_playButton && m_pauseButton))
return;
if (m_paused == Paused)
return;
m_paused = Paused;
MythUIType* current = GetFocusWidget();
m_playButton->SetVisible(m_paused);
m_pauseButton->SetVisible(!m_paused);
if (current && (current == m_playButton || current == m_pauseButton))
{
current->LoseFocus();
SetFocusWidget(m_paused ? m_playButton : m_pauseButton);
}
}
void MythNavigationOverlay::AudioStateChanged(MythAudioState AudioState)
{
if (!(m_muteButton && m_unMuteButton))
return;
if (!(AudioState.m_volumeControl && AudioState.m_hasAudioOut))
{
m_muteButton->Hide();
m_unMuteButton->Hide();
}
else if (m_audioState.m_muteState != AudioState.m_muteState)
{
bool muted = AudioState.m_muteState == kMuteAll;
MythUIType* current = GetFocusWidget();
m_muteButton->SetVisible(!muted);
m_unMuteButton->SetVisible(muted);
if (current && (current == m_muteButton || current == m_unMuteButton))
{
current->LoseFocus();
SetFocusWidget(muted ? m_unMuteButton : m_muteButton);
}
}
m_audioState = AudioState;
}
void MythNavigationOverlay::GeneralAction()
{
MythUIType* current = GetFocusWidget();
if (current)
{
QString name = current->objectName();
int result = 100;
int hashPos = name.indexOf('#');
if (hashPos > -1)
name.truncate(hashPos);
if (name == "INFO")
result = 0;
if (name == "unmute")
name = "MUTE";
SendResult(result, name);
}
}
// Switch to next group of icons. They have to be
// named grp0, grp1, etc with no gaps in numbers.
void MythNavigationOverlay::More()
{
if (m_maxGroupNum <= 0)
return;
MythUIGroup* group = nullptr;
UIUtilW::Assign(this, group, QString("grp%1").arg(m_visibleGroup));
if (group != nullptr)
group->SetVisible(false);
// wrap around after last group displayed
if (++m_visibleGroup > m_maxGroupNum)
m_visibleGroup = 0;
UIUtilW::Assign(this, group, QString("grp%1").arg(m_visibleGroup));
if (group != nullptr)
group->SetVisible(true);
}