FluNavigationView.qml 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  1. import QtQuick
  2. import QtQuick.Window
  3. import QtQuick.Controls
  4. import QtQuick.Controls.Basic
  5. import QtQuick.Layouts
  6. import FluentUI
  7. Item {
  8. enum DisplayMode {
  9. Open,
  10. Compact,
  11. Minimal,
  12. Auto
  13. }
  14. property url logo
  15. property string title: ""
  16. property FluObject items
  17. property FluObject footerItems
  18. property int displayMode: FluNavigationView.Auto
  19. property Component autoSuggestBox
  20. property var window : {
  21. if(Window.window == null)
  22. return null
  23. return Window.window
  24. }
  25. id:control
  26. QtObject{
  27. id:d
  28. property bool enableStack: true
  29. property int displayMode: {
  30. if(control.displayMode !==FluNavigationView.Auto){
  31. return control.displayMode
  32. }
  33. if(control.width<=700){
  34. return FluNavigationView.Minimal
  35. }else if(control.width<=900){
  36. return FluNavigationView.Compact
  37. }else{
  38. return FluNavigationView.Open
  39. }
  40. }
  41. property var stackItems: []
  42. property bool enableNavigationPanel: false
  43. property bool isCompact: d.displayMode === FluNavigationView.Compact
  44. property bool isMinimal: d.displayMode === FluNavigationView.Minimal
  45. property bool isCompactAndPanel: d.displayMode === FluNavigationView.Compact && d.enableNavigationPanel
  46. property bool isCompactAndNotPanel:d.displayMode === FluNavigationView.Compact && !d.enableNavigationPanel
  47. property bool isMinimalAndPanel: d.displayMode === FluNavigationView.Minimal && d.enableNavigationPanel
  48. onIsCompactAndNotPanelChanged: {
  49. collapseAll()
  50. }
  51. onDisplayModeChanged: {
  52. if(d.displayMode === FluNavigationView.Compact){
  53. collapseAll()
  54. }
  55. if(d.displayMode === FluNavigationView.Minimal){
  56. anim_layout_list_x.enabled = false
  57. d.enableNavigationPanel = false
  58. timer_anim_x_enable.restart()
  59. }
  60. }
  61. function handleItems(){
  62. var idx = 0
  63. var data = []
  64. if(items){
  65. for(var i=0;i<items.children.length;i++){
  66. var item = items.children[i]
  67. item.idx = idx
  68. data.push(item)
  69. idx++
  70. if(item instanceof FluPaneItemExpander){
  71. for(var j=0;j<item.children.length;j++){
  72. var itemChild = item.children[j]
  73. itemChild.parent = item
  74. itemChild.idx = idx
  75. data.push(itemChild)
  76. idx++
  77. }
  78. }
  79. }
  80. if(footerItems){
  81. var comEmpty = Qt.createComponent("FluPaneItemEmpty.qml");
  82. for(var k=0;k<footerItems.children.length;k++){
  83. var itemFooter = footerItems.children[k]
  84. if (comEmpty.status === Component.Ready) {
  85. var objEmpty = comEmpty.createObject(items,{idx:idx});
  86. itemFooter.idx = idx;
  87. data.push(objEmpty)
  88. idx++
  89. }
  90. }
  91. }
  92. }
  93. return data
  94. }
  95. }
  96. Component{
  97. id:com_panel_item_empty
  98. Item{
  99. visible: false
  100. }
  101. }
  102. Component{
  103. id:com_panel_item_separatorr
  104. FluDivider{
  105. width: layout_list.width
  106. height: {
  107. if(model.parent){
  108. return model.parent.isExpand ? 1 : 0
  109. }
  110. return 1
  111. }
  112. Behavior on height {
  113. NumberAnimation{
  114. duration: 167
  115. easing.type: Easing.BezierSpline
  116. easing.bezierCurve: [ 0, 0, 0, 1 ]
  117. }
  118. }
  119. }
  120. }
  121. Component{
  122. id:com_panel_item_header
  123. Item{
  124. height: {
  125. if(model.parent){
  126. return model.parent.isExpand ? 30 : 0
  127. }
  128. return 30
  129. }
  130. Behavior on height {
  131. NumberAnimation{
  132. duration: 167
  133. easing.type: Easing.BezierSpline
  134. easing.bezierCurve: [ 0, 0, 0, 1 ]
  135. }
  136. }
  137. width: layout_list.width
  138. FluText{
  139. text:model.title
  140. fontStyle: FluText.BodyStrong
  141. anchors{
  142. bottom: parent.bottom
  143. left:parent.left
  144. leftMargin: 10
  145. }
  146. }
  147. }
  148. }
  149. Component{
  150. id:com_panel_item_expander
  151. Item{
  152. height: 38
  153. width: layout_list.width
  154. Rectangle{
  155. radius: 4
  156. anchors{
  157. top: parent.top
  158. bottom: parent.bottom
  159. left: parent.left
  160. right: parent.right
  161. topMargin: 2
  162. bottomMargin: 2
  163. leftMargin: 6
  164. rightMargin: 6
  165. }
  166. Rectangle{
  167. width: 3
  168. height: 18
  169. radius: 1.5
  170. color: FluTheme.primaryColor.dark
  171. visible: {
  172. for(var i=0;i<model.children.length;i++){
  173. var item = model.children[i]
  174. if(item.idx === nav_list.currentIndex && !model.isExpand){
  175. return true
  176. }
  177. }
  178. return false
  179. }
  180. anchors{
  181. verticalCenter: parent.verticalCenter
  182. }
  183. }
  184. FluIcon{
  185. rotation: model.isExpand?0:180
  186. iconSource:FluentIcons.ChevronUp
  187. iconSize: 15
  188. anchors{
  189. verticalCenter: parent.verticalCenter
  190. right: parent.right
  191. rightMargin: 12
  192. }
  193. opacity: {
  194. if(d.isCompactAndNotPanel){
  195. return false
  196. }
  197. return true
  198. }
  199. visible:opacity
  200. Behavior on opacity {
  201. NumberAnimation{
  202. duration: 83
  203. }
  204. }
  205. Behavior on rotation {
  206. NumberAnimation{
  207. duration: 83
  208. }
  209. }
  210. }
  211. MouseArea{
  212. id:item_mouse
  213. hoverEnabled: true
  214. anchors.fill: parent
  215. onClicked: {
  216. if(d.isCompactAndNotPanel){
  217. control_popup.showPopup(Qt.point(50,mapToItem(control,0,0).y),model.children)
  218. return
  219. }
  220. model.isExpand = !model.isExpand
  221. }
  222. }
  223. color: {
  224. if(FluTheme.dark){
  225. if((nav_list.currentIndex === idx)&&type===0){
  226. return Qt.rgba(1,1,1,0.06)
  227. }
  228. if(item_mouse.containsMouse){
  229. return Qt.rgba(1,1,1,0.03)
  230. }
  231. return Qt.rgba(0,0,0,0)
  232. }else{
  233. if(nav_list.currentIndex === idx&&type===0){
  234. return Qt.rgba(0,0,0,0.06)
  235. }
  236. if(item_mouse.containsMouse){
  237. return Qt.rgba(0,0,0,0.03)
  238. }
  239. return Qt.rgba(0,0,0,0)
  240. }
  241. }
  242. Component{
  243. id:com_icon
  244. FluIcon{
  245. iconSource: {
  246. if(model.icon){
  247. return model.icon
  248. }
  249. return 0
  250. }
  251. iconSize: 15
  252. }
  253. }
  254. Item{
  255. id:item_icon
  256. width: 30
  257. height: 30
  258. anchors{
  259. verticalCenter: parent.verticalCenter
  260. left:parent.left
  261. leftMargin: 3
  262. }
  263. Loader{
  264. anchors.centerIn: parent
  265. sourceComponent: {
  266. if(model.cusIcon){
  267. return model.cusIcon
  268. }
  269. return com_icon
  270. }
  271. }
  272. }
  273. FluText{
  274. id:item_title
  275. text:model.title
  276. opacity: {
  277. if(d.isCompactAndNotPanel){
  278. return false
  279. }
  280. return true
  281. }
  282. visible:opacity
  283. Behavior on opacity {
  284. NumberAnimation{
  285. duration: 83
  286. }
  287. }
  288. anchors{
  289. verticalCenter: parent.verticalCenter
  290. left:item_icon.right
  291. }
  292. color:{
  293. if(item_mouse.pressed){
  294. return FluTheme.dark ? FluColors.Grey80 : FluColors.Grey120
  295. }
  296. return FluTheme.dark ? FluColors.White : FluColors.Grey220
  297. }
  298. }
  299. }
  300. }
  301. }
  302. Component{
  303. id:com_panel_item
  304. Item{
  305. Behavior on height {
  306. NumberAnimation{
  307. duration: 167
  308. easing.type: Easing.BezierSpline
  309. easing.bezierCurve: [ 0, 0, 0, 1 ]
  310. }
  311. }
  312. clip: true
  313. height: {
  314. if(model.parent){
  315. return model.parent.isExpand ? 38 : 0
  316. }
  317. return 38
  318. }
  319. width: layout_list.width
  320. Rectangle{
  321. radius: 4
  322. anchors{
  323. top: parent.top
  324. bottom: parent.bottom
  325. left: parent.left
  326. right: parent.right
  327. topMargin: 2
  328. bottomMargin: 2
  329. leftMargin: 6
  330. rightMargin: 6
  331. }
  332. MouseArea{
  333. id:item_mouse
  334. hoverEnabled: true
  335. anchors.fill: parent
  336. onClicked: {
  337. if(type === 0){
  338. if(model.tapFunc){
  339. model.tapFunc()
  340. }else{
  341. nav_list.currentIndex = idx
  342. layout_footer.currentIndex = -1
  343. if(d.isMinimal || d.isCompact){
  344. d.enableNavigationPanel = false
  345. }
  346. }
  347. }else{
  348. if(model.tapFunc){
  349. model.tapFunc()
  350. }else{
  351. model.tap()
  352. d.stackItems.push(model)
  353. nav_list.currentIndex = nav_list.count-layout_footer.count+idx
  354. layout_footer.currentIndex = idx
  355. if(d.isMinimal || d.isCompact){
  356. d.enableNavigationPanel = false
  357. }
  358. }
  359. }
  360. }
  361. }
  362. color: {
  363. if(FluTheme.dark){
  364. if(type===0){
  365. if(nav_list.currentIndex === idx){
  366. return Qt.rgba(1,1,1,0.06)
  367. }
  368. }else{
  369. if(nav_list.currentIndex === (nav_list.count-layout_footer.count+idx)){
  370. return Qt.rgba(1,1,1,0.06)
  371. }
  372. }
  373. if(item_mouse.containsMouse){
  374. return Qt.rgba(1,1,1,0.03)
  375. }
  376. return Qt.rgba(0,0,0,0)
  377. }else{
  378. if(type===0){
  379. if(nav_list.currentIndex === idx){
  380. return Qt.rgba(0,0,0,0.06)
  381. }
  382. }else{
  383. if(nav_list.currentIndex === (nav_list.count-layout_footer.count+idx)){
  384. return Qt.rgba(0,0,0,0.06)
  385. }
  386. }
  387. if(item_mouse.containsMouse){
  388. return Qt.rgba(0,0,0,0.03)
  389. }
  390. return Qt.rgba(0,0,0,0)
  391. }
  392. }
  393. Component{
  394. id:com_icon
  395. FluIcon{
  396. iconSource: {
  397. if(model.icon){
  398. return model.icon
  399. }
  400. return 0
  401. }
  402. iconSize: 15
  403. }
  404. }
  405. Item{
  406. id:item_icon
  407. width: 30
  408. height: 30
  409. anchors{
  410. verticalCenter: parent.verticalCenter
  411. left:parent.left
  412. leftMargin: 3
  413. }
  414. Loader{
  415. anchors.centerIn: parent
  416. sourceComponent: {
  417. if(model.cusIcon){
  418. return model.cusIcon
  419. }
  420. return com_icon
  421. }
  422. }
  423. }
  424. FluText{
  425. id:item_title
  426. text:model.title
  427. opacity: {
  428. if(d.isCompactAndNotPanel){
  429. return false
  430. }
  431. return true
  432. }
  433. visible:opacity
  434. Behavior on opacity {
  435. NumberAnimation{
  436. duration: 83
  437. }
  438. }
  439. color:{
  440. if(item_mouse.pressed){
  441. return FluTheme.dark ? FluColors.Grey80 : FluColors.Grey120
  442. }
  443. return FluTheme.dark ? FluColors.White : FluColors.Grey220
  444. }
  445. anchors{
  446. verticalCenter: parent.verticalCenter
  447. left:item_icon.right
  448. }
  449. }
  450. }
  451. }
  452. }
  453. Item {
  454. id:nav_app_bar
  455. width: parent.width
  456. height: 50
  457. z:999
  458. RowLayout{
  459. height:parent.height
  460. spacing: 0
  461. FluIconButton{
  462. iconSource: FluentIcons.ChromeBack
  463. Layout.leftMargin: 5
  464. Layout.preferredWidth: 40
  465. Layout.preferredHeight: 40
  466. Layout.alignment: Qt.AlignVCenter
  467. disabled: nav_swipe.depth === 1
  468. iconSize: 13
  469. onClicked: {
  470. nav_swipe.pop()
  471. d.stackItems.pop()
  472. var item = d.stackItems[d.stackItems.length-1]
  473. d.enableStack = false
  474. if(item.idx<(nav_list.count - layout_footer.count)){
  475. layout_footer.currentIndex = -1
  476. }else{
  477. console.debug(item.idx-(nav_list.count-layout_footer.count))
  478. layout_footer.currentIndex = item.idx-(nav_list.count-layout_footer.count)
  479. }
  480. nav_list.currentIndex = item.idx
  481. d.enableStack = true
  482. }
  483. }
  484. FluIconButton{
  485. id:btn_nav
  486. iconSource: FluentIcons.GlobalNavButton
  487. iconSize: 15
  488. Layout.preferredWidth: d.isMinimal ? 40 : 0
  489. Layout.preferredHeight: 40
  490. Layout.alignment: Qt.AlignVCenter
  491. onClicked: {
  492. d.enableNavigationPanel = !d.enableNavigationPanel
  493. }
  494. visible: Layout.preferredWidth !== 0
  495. Behavior on Layout.preferredWidth{
  496. NumberAnimation{
  497. duration: 167
  498. easing.type: Easing.BezierSpline
  499. easing.bezierCurve: [ 0, 0, 0, 1 ]
  500. }
  501. }
  502. }
  503. Image{
  504. id:image_logo
  505. Layout.preferredHeight: 20
  506. Layout.preferredWidth: 20
  507. source: control.logo
  508. Layout.leftMargin: {
  509. if(btn_nav.visible){
  510. return 12
  511. }
  512. return 5
  513. }
  514. Layout.alignment: Qt.AlignVCenter
  515. }
  516. FluText{
  517. Layout.alignment: Qt.AlignVCenter
  518. text:control.title
  519. Layout.leftMargin: 12
  520. fontStyle: FluText.Body
  521. }
  522. }
  523. }
  524. Item{
  525. anchors{
  526. left: d.isMinimal || d.isCompactAndPanel ? parent.left : layout_list.right
  527. top: nav_app_bar.bottom
  528. right: parent.right
  529. bottom: parent.bottom
  530. leftMargin: d.isCompactAndPanel ? 50 : 0
  531. }
  532. StackView{
  533. id:nav_swipe
  534. anchors.fill: parent
  535. clip: true
  536. popEnter : Transition{}
  537. popExit : Transition {
  538. NumberAnimation {
  539. properties: "y"
  540. from: 0
  541. to: nav_swipe.height
  542. duration: 167
  543. easing.type: Easing.BezierSpline
  544. easing.bezierCurve: [ 1, 0, 0, 0 ]
  545. }
  546. }
  547. pushEnter: Transition {
  548. NumberAnimation {
  549. properties: "y";
  550. from: nav_swipe.height;
  551. to: 0
  552. duration: 167
  553. easing.type: Easing.BezierSpline
  554. easing.bezierCurve: [ 0, 0, 0, 1 ]
  555. }
  556. }
  557. pushExit : Transition{}
  558. replaceEnter : Transition{}
  559. replaceExit : Transition{}
  560. }
  561. }
  562. MouseArea{
  563. anchors.fill: parent
  564. visible: d.isMinimalAndPanel||d.isCompactAndPanel
  565. onClicked: {
  566. d.enableNavigationPanel = false
  567. }
  568. }
  569. Rectangle{
  570. id:layout_list
  571. width: {
  572. if(d.isCompactAndNotPanel){
  573. return 50
  574. }
  575. return 300
  576. }
  577. Behavior on width{
  578. NumberAnimation{
  579. duration: 167
  580. easing.type: Easing.BezierSpline
  581. easing.bezierCurve: [ 0, 0, 0, 1 ]
  582. }
  583. }
  584. Behavior on x{
  585. id:anim_layout_list_x
  586. NumberAnimation{
  587. duration: 167
  588. easing.type: Easing.BezierSpline
  589. easing.bezierCurve: [ 0, 0, 0, 1 ]
  590. }
  591. }
  592. anchors{
  593. top: parent.top
  594. bottom: parent.bottom
  595. }
  596. border.color: FluTheme.dark ? Qt.rgba(45/255,45/255,45/255,1) : Qt.rgba(226/255,230/255,234/255,1)
  597. border.width: d.isMinimal || d.isCompactAndPanel ? 1 : 0
  598. color: {
  599. if(d.isMinimal || d.isCompactAndPanel){
  600. return FluTheme.dark ? Qt.rgba(61/255,61/255,61/255,1) : Qt.rgba(243/255,243/255,243/255,1)
  601. }
  602. if(window && window.active){
  603. return FluTheme.dark ? Qt.rgba(26/255,34/255,41/255,1) : Qt.rgba(238/255,244/255,249/255,1)
  604. }
  605. return FluTheme.dark ? Qt.rgba(32/255,32/255,32/255,1) : Qt.rgba(243/255,243/255,243/255,1)
  606. }
  607. Behavior on color{
  608. ColorAnimation {
  609. duration: 300
  610. }
  611. }
  612. x: {
  613. if(d.displayMode !== FluNavigationView.Minimal)
  614. return 0
  615. return d.isMinimalAndPanel ? 0 : -width
  616. }
  617. Item{
  618. id:layout_header
  619. width: layout_list.width
  620. clip: true
  621. y:nav_app_bar.height
  622. height: autoSuggestBox ? 38 : 0
  623. Loader{
  624. id:loader_auto_suggest_box
  625. anchors.centerIn: parent
  626. sourceComponent: autoSuggestBox
  627. opacity: {
  628. if(d.isCompactAndNotPanel){
  629. return false
  630. }
  631. return true
  632. }
  633. visible: opacity
  634. Behavior on opacity{
  635. NumberAnimation{
  636. duration: 83
  637. }
  638. }
  639. }
  640. FluIconButton{
  641. visible:opacity
  642. opacity:d.isCompactAndNotPanel
  643. Behavior on opacity{
  644. NumberAnimation{
  645. duration: 83
  646. }
  647. }
  648. hoverColor: FluTheme.dark ? Qt.rgba(1,1,1,0.03) : Qt.rgba(0,0,0,0.03)
  649. pressedColor: FluTheme.dark ? Qt.rgba(1,1,1,0.03) : Qt.rgba(0,0,0,0.03)
  650. normalColor: FluTheme.dark ? Qt.rgba(0,0,0,0) : Qt.rgba(0,0,0,0)
  651. width:38
  652. height:34
  653. x:6
  654. y:2
  655. iconSize: 15
  656. iconSource: {
  657. if(loader_auto_suggest_box.item){
  658. return loader_auto_suggest_box.item.autoSuggestBoxReplacement
  659. }
  660. return 0
  661. }
  662. onClicked: {
  663. d.enableNavigationPanel = !d.enableNavigationPanel
  664. }
  665. }
  666. }
  667. ListView{
  668. id:nav_list
  669. clip: true
  670. ScrollBar.vertical: FluScrollBar {}
  671. model:d.handleItems()
  672. highlightMoveDuration: 150
  673. highlight: Item{
  674. clip: true
  675. Rectangle{
  676. height: 18
  677. radius: 1.5
  678. color: FluTheme.primaryColor.dark
  679. width: 3
  680. anchors{
  681. verticalCenter: parent.verticalCenter
  682. left: parent.left
  683. leftMargin: 6
  684. }
  685. }
  686. }
  687. onCurrentIndexChanged: {
  688. if(d.enableStack){
  689. var item = model[currentIndex]
  690. if(item instanceof FluPaneItem){
  691. item.tap()
  692. d.stackItems.push(item)
  693. }
  694. }
  695. }
  696. currentIndex: -1
  697. anchors{
  698. top: layout_header.bottom
  699. topMargin: 6
  700. left: parent.left
  701. right: parent.right
  702. bottom: layout_footer.top
  703. }
  704. delegate: Loader{
  705. property var model: modelData
  706. property var idx: index
  707. property int type: 0
  708. sourceComponent: {
  709. if(modelData instanceof FluPaneItem){
  710. return com_panel_item
  711. }
  712. if(modelData instanceof FluPaneItemHeader){
  713. return com_panel_item_header
  714. }
  715. if(modelData instanceof FluPaneItemSeparator){
  716. return com_panel_item_separatorr
  717. }
  718. if(modelData instanceof FluPaneItemExpander){
  719. return com_panel_item_expander
  720. }
  721. if(modelData instanceof FluPaneItemEmpty){
  722. return com_panel_item_empty
  723. }
  724. }
  725. }
  726. }
  727. ListView{
  728. id:layout_footer
  729. clip: true
  730. width: layout_list.width
  731. height: childrenRect.height
  732. anchors.bottom: parent.bottom
  733. interactive: false
  734. currentIndex: -1
  735. model: {
  736. if(footerItems){
  737. return footerItems.children
  738. }
  739. }
  740. highlightMoveDuration: 150
  741. highlight: Item{
  742. clip: true
  743. Rectangle{
  744. height: 18
  745. radius: 1.5
  746. color: FluTheme.primaryColor.dark
  747. width: 3
  748. anchors{
  749. verticalCenter: parent.verticalCenter
  750. left: parent.left
  751. leftMargin: 6
  752. }
  753. }
  754. }
  755. delegate: Loader{
  756. property var model: modelData
  757. property var idx: index
  758. property int type: 1
  759. sourceComponent: {
  760. if(modelData instanceof FluPaneItem){
  761. return com_panel_item
  762. }
  763. if(modelData instanceof FluPaneItemHeader){
  764. return com_panel_item_header
  765. }
  766. if(modelData instanceof FluPaneItemSeparator){
  767. return com_panel_item_separatorr
  768. }
  769. }
  770. }
  771. }
  772. }
  773. Popup{
  774. property var childModel
  775. id:control_popup
  776. enter: Transition {
  777. NumberAnimation {
  778. property: "opacity"
  779. from:0
  780. to:1
  781. duration: 83
  782. }
  783. }
  784. background: Rectangle{
  785. width: 160
  786. radius: 4
  787. FluShadow{
  788. radius: 4
  789. }
  790. color: FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(248/255,250/255,253/255,1)
  791. height: 38*Math.min(Math.max(list_view.count,1),8)
  792. ListView{
  793. id:list_view
  794. anchors.fill: parent
  795. clip: true
  796. currentIndex: -1
  797. model: control_popup.childModel
  798. ScrollBar.vertical: FluScrollBar {}
  799. delegate:Button{
  800. width: 160
  801. padding:10
  802. background: Rectangle{
  803. color: {
  804. if(hovered){
  805. return FluTheme.dark ? Qt.rgba(63/255,60/255,61/255,1) : Qt.rgba(237/255,237/255,242/255,1)
  806. }
  807. return FluTheme.dark ? Qt.rgba(51/255,48/255,48/255,1) : Qt.rgba(0,0,0,0)
  808. }
  809. }
  810. contentItem: FluText{
  811. text:modelData.title
  812. anchors{
  813. verticalCenter: parent.verticalCenter
  814. }
  815. }
  816. onClicked: {
  817. if(modelData.tapFunc){
  818. modelData.tapFunc()
  819. }else{
  820. nav_list.currentIndex = idx
  821. layout_footer.currentIndex = -1
  822. if(d.isMinimal || d.isCompact){
  823. d.enableNavigationPanel = false
  824. }
  825. }
  826. control_popup.close()
  827. }
  828. }
  829. }
  830. }
  831. function showPopup(pos,model){
  832. control_popup.x = pos.x
  833. control_popup.y = pos.y
  834. control_popup.childModel = model
  835. control_popup.open()
  836. }
  837. }
  838. Timer{
  839. id:timer_anim_x_enable
  840. interval: 150
  841. onTriggered: {
  842. anim_layout_list_x.enabled = true
  843. }
  844. }
  845. function collapseAll(){
  846. for(var i=0;i<nav_list.model.length;i++){
  847. var item = nav_list.model[i]
  848. if(item instanceof FluPaneItemExpander){
  849. item.isExpand = false
  850. }
  851. }
  852. }
  853. function setCurrentIndex(index){
  854. nav_list.currentIndex = index
  855. }
  856. function getItems(){
  857. return nav_list.model
  858. }
  859. function push(url){
  860. nav_swipe.push(url)
  861. }
  862. function getCurrentIndex(){
  863. return nav_list.currentIndex
  864. }
  865. function startPageByItem(data){
  866. var items = getItems();
  867. for(var i=0;i<items.length;i++){
  868. var item = items[i]
  869. if(item.key === data.key){
  870. if(getCurrentIndex() === i){
  871. return
  872. }
  873. setCurrentIndex(i)
  874. if(item.parent && !d.isCompactAndNotPanel){
  875. item.parent.isExpand = true
  876. }
  877. return
  878. }
  879. }
  880. }
  881. }