設置

2013-07-18 39 views
-1

UPDATE設置

我想通過滑動頂部邊框執行設置,這裏是我的代碼,我在做這個吧?目前這不起作用。我想知道如何實現它。我應該在哪裏放置代碼,以及我缺少什麼,以便它能夠工作?

import bb.cascades 1.0 

NavigationPane { 
    //property variant menu; 

    Menu.definition: MenuDefinition { 
     settingsAction: SettingsActionItem { 
      imageSource: "asset:///images/navbar_icon_settings.png" 

      onTriggered: { 
       cppObj.onSettingsClicked(); 
      } 
     } 
     actions: [ 
      ActionItem { 
       title: "Action 1" 
       imageSource: "asset:///images/navbar_icon_settings.png" 
       onTriggered: { 
        cppObj.onSettingsClicked(); 
       } 
      } 
     ] 
    } 

    firstPage: Page { 

     Container { 
      background: Color.create("#f9f7f2"); 
      layout: StackLayout {} 

      // Container for holding the title 
      Container { 
       horizontalAlignment: HorizontalAlignment.Center 
       layout: DockLayout {} 

       ImageView { 
        horizontalAlignment: HorizontalAlignment.Fill 
        verticalAlignment: VerticalAlignment.Fill 
        imageSource: "asset:///images/navigation_bar.png" 
       } 

       /*Container { 
        horizontalAlignment: HorizontalAlignment.Right 
        rightPadding: 30 
        topPadding: 40 
        layout: DockLayout {} 

        ImageButton { 
         id: btnsettings 
         verticalAlignment: VerticalAlignment.Center 
         defaultImageSource: "asset:///images/navbar_icon_settings.png" 

         onClicked: { 
          // show settings page when the button is clicked 
          cppObj.onSettingsClicked(); 
         } 
        } 
       }*/ 
      } 
      Container { 
       topPadding: 20 
       leftPadding: 20 
       rightPadding: 20 
       bottomPadding: 20 
       background: Color.create("#F4E9E1"); 
       horizontalAlignment: HorizontalAlignment.Fill 
       layout: StackLayout {} 

       Label { 
        verticalAlignment: VerticalAlignment.Center 
        horizontalAlignment: HorizontalAlignment.Left 
        text: cppObj.name 

        textStyle { 
         // fontFamily: FontStyle.Default.Myriad 
         // fontSize: 36 
         color: Color.create("#60323C") 
        } 
       } 
      } 

      Container { 
       verticalAlignment: VerticalAlignment.Center 
       horizontalAlignment: HorizontalAlignment.Center 
       layout: DockLayout {} 
       Divider {} 
       ScrollView { 
        scrollViewProperties { 
         scrollMode: ScrollMode.Vertical 
        } 
       /* ImageView { 
       id: listviewbackground 
       verticalAlignment: VerticalAlignment.Center 
       horizontalAlignment: HorizontalAlignment.Center 
       scalingMethod: ScalingMethod.Fill 
       imageSource: "asset:///images/list_view_cell.png" 
       }*/ 

        ListView { 
         id: lvprojects 
         dataModel: cppObj.model() 

         listItemComponents: [ 
          ListItemComponent { 
           type: "item" 

           Container { 
            horizontalAlignment: HorizontalAlignment.Center 
            layout: DockLayout {} 
            touchPropagationMode: TouchPropagationMode.Full; 

            StandardListItem { 
             title:ListItemData.desc 
            } 
           } 
          } 
         ] 

         onTriggered: { 
          var selectedItem = dataModel.data(indexPath); 

          onClicked: { 
           // show issue's comment page when the button is clicked 
           cppObj.onIssueClicked(selectedItem.name); 
          } 
         } 
        } 
       } 
      } 
     } 
     actions: [ 
      ActionItem { 
       title: qsTr ("Add Issue") 
       imageSource: "asset:///images/actionbar_icon_add.png" 
       ActionBar.placement: ActionBarPlacement.OnBar 

       onTriggered: { 
        cppObj.onAddIssuesClicked(); 
       } 
      }, 

      ActionItem { 
       title: qsTr ("Issues") 
       imageSource: "asset:///images/actionbar_icon_issues.png" 
       ActionBar.placement: ActionBarPlacement.OnBar 

       onTriggered: { 
        cppObj.onIssuesClicked(); 
       } 
      }, 

      ActionItem { 
       title: qsTr ("Members") 
       imageSource: "asset:///images/actionbar_icon_members.png" 
       ActionBar.placement: ActionBarPlacement.OnBar 

       onTriggered: { 
        cppObj.onMembersClicked(); 
       } 
      } 
     ] 
    } 
    /*attachedObjects: [ 
     ComponentDefinition { 
      id: settingsPage 
      source: "topsettings.qml" 
     } 
    ] 
    onCreationCompleted: { 
     // Create the app menu for the cookbook. 
     menu = settingsPage.createObject(); 
    } 
    onPopTransitionEnded: { 
     // Transition is done destroy the Page to free up memory. 
     page.destroy(); 
    }*/ 
} 

而這裏的設置不顯示topsettings.qml

MenuDefinition { 
    settingsAction: SettingsActionItem { 
     imageSource: "asset:///images/navbar_icon_settings.png" 

     onTriggered: { 
      cppObj.onSettingsClicked(); 
     } 
    } 

enter image description here

+0

爲什麼你在附件中包含了'MenuDefinition'?附加對象與您可能嘗試構建的應用程序菜單無關。 – Sunseeker

回答

1

您的代碼看起來不錯:唯一的問題是,你嘗試定義您的Menu.definitionPage中,但您應該將其定義在Pane中。請參閱此處例如:https://github.com/Kernald/tt-rss-bb10/blob/master/assets/main.qml#L9

順便提一下,請注意,您有幫助和設置的預定義操作。看到之前的鏈接,我也使用了它們。

+0

我更新了我的代碼,並且設置仍然不顯示:( – kev

1

比方說,你有NavigationPane作爲QML文件第一次加載在應用程序啓動,所以這應該放在MenuDefinition這樣的:

NavigationPane { 

    Menu.definition: MenuDefinition { 
     helpAction: HelpActionItem { 
      onTriggered: {    
      } 
     } 
     actions: [ 
      ActionItem { 
       title: "Action 1" 
       imageSource: "asset:///images/ic_action1.png" 
       onTriggered: { 
       } 
      }, 
      ActionItem { 
       title: "Action 2" 
       imageSource: "asset:///images/ic_action2.png" 
       onTriggered: { 
       } 
      } 
     ] 
    } 

    firstPage: Page { 
    } 
} 

注意,可能有多達4種元素和HelpActionItem爲如果你想實現類似的菜單條目,那麼已經定義好了SettingsActionItem

+0

我已更新我的代碼,並且設置仍然不顯示:( – kev

+0

將這段代碼放在「Page」,「NavigationPane」等內這是在應用程序啓動時首先加載。看看我的更新答案 – Sunseeker

+0

編輯我的代碼就像你說的,但沒有任何反應 – kev