Skip to content

Commit f43a134

Browse files
committed
src/qml/main: use a single subtitle list and manual search instance
Use a single instance of SubtitleListPage and ManualSearchPage in Main.qml. The previous implementation used multiple instances depending on whether they were in a separate window or internal. This fixes that overhead by just using one and reparenting it based on the configuration. This commit was written by Codex.
1 parent e57457b commit f43a134

1 file changed

Lines changed: 33 additions & 32 deletions

File tree

src/qml/Main.qml

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -180,18 +180,7 @@ ApplicationWindow {
180180
}
181181
onAuxiliarySearchRequested: function(text) {
182182
MementoSettings.windowSearch = true;
183-
if (MementoSettings.interfaceSearchWindow)
184-
{
185-
searchWindowLoader.pendingQuery = text;
186-
if (searchWindowLoader.item?.searchPage)
187-
{
188-
searchWindowLoader.item.searchPage.setQuery(text);
189-
}
190-
}
191-
else
192-
{
193-
inlineSearchPage.setQuery(text);
194-
}
183+
searchPage.setQuery(text);
195184
}
196185

197186
DropArea {
@@ -222,51 +211,44 @@ ApplicationWindow {
222211

223212
SplitView.preferredWidth: toolSplitView.hasVisibleChildren ? toolSplitView.savedWidth : 0
224213
SplitView.minimumWidth: toolSplitView.hasVisibleChildren ? 300 : 0
214+
parent: toolSplitView.hasVisibleChildren ? mainSplitView : null
225215
visible: toolSplitView.hasVisibleChildren
226216
orientation: Qt.Vertical
227217

228-
ManualSearchPage {
229-
id: inlineSearchPage
218+
Item {
219+
id: inlineSearchHost
230220
SplitView.minimumHeight: 200
231221
SplitView.preferredHeight: 400
232222
visible: MementoSettings.windowSearch && !MementoSettings.interfaceSearchWindow
233223
}
234224

235-
SubtitleListPage {
236-
id: inlineSubtitleLists
225+
Item {
226+
id: inlineSubtitleListHost
237227
SplitView.minimumHeight: 200
238228
visible: MementoSettings.windowSubtitleList && !MementoSettings.interfaceSubtitleListWindow
239-
player: player
240229
}
241230
}
242231
}
243232

244233
Loader {
245234
id: searchWindowLoader
246-
property string pendingQuery: ""
247235

248236
active: MementoSettings.interfaceSearchWindow
249237
sourceComponent: Component {
250238
Window {
251239
id: searchPageWindow
252240

253-
property alias searchPage: windowSearchPage
241+
property alias searchHost: searchWindowHost
254242

255243
width: 500
256244
height: 500
257245
visible: MementoSettings.interfaceSearchWindow && MementoSettings.windowSearch
258246
title: qsTr("Search")
259247
onClosing: if (visible) MementoSettings.windowSearch = false
260248

261-
ManualSearchPage {
262-
id: windowSearchPage
249+
Item {
250+
id: searchWindowHost
263251
anchors.fill: parent
264-
Component.onCompleted: {
265-
if (searchWindowLoader.pendingQuery.length > 0)
266-
{
267-
setQuery(searchWindowLoader.pendingQuery);
268-
}
269-
}
270252
}
271253
}
272254
}
@@ -275,27 +257,46 @@ ApplicationWindow {
275257
Loader {
276258
id: subtitleListWindowLoader
277259

278-
/* Need to load the player into the SubtitleList */
279-
readonly property MpvPlayer mainPlayer: player
280-
281260
active: MementoSettings.interfaceSubtitleListWindow
282261
sourceComponent: Component {
283262
Window {
284263
id: subtitleListWindow
264+
265+
property alias subtitleListHost: subtitleListWindowHost
266+
285267
width: 500
286268
height: 720
287269
visible: MementoSettings.interfaceSubtitleListWindow && MementoSettings.windowSubtitleList
288270
title: qsTr("Subtitle List")
289271
onClosing: if (visible) MementoSettings.windowSubtitleList = false
290272

291-
SubtitleListPage {
273+
Item {
274+
id: subtitleListWindowHost
292275
anchors.fill: parent
293-
player: subtitleListWindowLoader.mainPlayer
294276
}
295277
}
296278
}
297279
}
298280

281+
ManualSearchPage {
282+
id: searchPage
283+
parent: MementoSettings.interfaceSearchWindow ?
284+
searchWindowLoader.item?.searchHost ?? null :
285+
inlineSearchHost
286+
anchors.fill: parent
287+
visible: MementoSettings.windowSearch
288+
}
289+
290+
SubtitleListPage {
291+
id: subtitleListPage
292+
parent: MementoSettings.interfaceSubtitleListWindow ?
293+
subtitleListWindowLoader.item?.subtitleListHost ?? null :
294+
inlineSubtitleListHost
295+
anchors.fill: parent
296+
visible: MementoSettings.windowSubtitleList
297+
player: player
298+
}
299+
299300
Loader {
300301
id: dictionaryInstallLoader
301302
active: false

0 commit comments

Comments
 (0)