examples/QtQuick/bluetoothex/qml/bluetoothex/OptionsMenu.qml

00001 import QtQuick 1.0
00002 
00003 import "bluetoothoptions.js" as BluetoothOptions
00004 
00005 // List of menu items.
00006 ListView{
00007     id:listView
00008     model: listModel
00009     ListModel{
00010         id:listModel
00011         ListElement{
00012             option:"Discover devices"
00013         }
00014         ListElement{
00015             option:"Start slave"
00016         }
00017         ListElement{
00018             option:"Clear text"
00019         }
00020     }
00021     // Menu item is a simple rectangle with text in it.
00022     delegate:
00023         Rectangle{
00024         width: parent.width
00025         height: 50
00026         color: "steelblue"
00027         border.color: "black"
00028 
00029         Text{
00030         text: option
00031         anchors.centerIn: parent
00032         color: "white"
00033         }
00034         MouseArea{
00035             id:listItemMouseArea
00036             anchors.fill: parent
00037             onClicked:{
00038                 BluetoothOptions.buttonPressed(listModel.get(index).option);
00039                 parent.parent.parent.visible = false;
00040             }
00041         }
00042     }
00043 
00044 function initializeMenu(){
00045 listModel.clear();
00046 listModel.append({'option': "Discover devices"});
00047 listModel.append({'option': "Start slave"});
00048 listModel.append({'option': "Clear text"});
00049 }
00050 // Hear to connections, to change menu list.
00051 /*
00052 enum TBluetoothDiscoveryMode{
00053 EStopDeviceDiscovery = 0,
00054 EStartSlave,
00055 EHasDevices,
00056 EHasServices,
00057 EHasConnections,
00058 EStopSlave,
00059 ESendMessage
00060 };
00061 */
00062 Connections {
00063     target: bluetoothex
00064 
00065     onChangeMenu: {
00066 
00067         switch(menuOptions)
00068               {
00069               case 0:
00070                   initializeMenu();
00071                   listModel.remove(0);
00072                   listModel.insert(0,{'option': "Stop discovery"})
00073                   break;
00074               case 1:
00075                   listView.height = 150;
00076                   initializeMenu();
00077                   break;
00078               case 2:
00079                   listView.height = 200;
00080                   initializeMenu();
00081                   listModel.append({'option': "Discover services"});
00082                   break;
00083               case 3:
00084                   listView.height = 250;
00085                   initializeMenu();
00086                   listModel.append({'option': "Discover services"});
00087                   listModel.append({'option': "Connect devices"});
00088                   break;
00089               case 4:
00090                   initializeMenu();
00091                   listView.height = 300;
00092                   listModel.append({'option': "Disconnect devices"});
00093                   listModel.append({'option': "Send message"});
00094                   listModel.append({'option': "Show connected devices"});
00095                   break;
00096               case 5:
00097                   listView.height = 150;
00098                   initializeMenu();
00099                   listModel.remove(1);
00100                   listModel.insert(1,{'option': "Stop slave"});
00101                   break;
00102               case 6:
00103                   listView.height = 200;
00104                   initializeMenu();
00105                   listModel.remove(1);
00106                   listModel.insert(1,{'option': "Stop slave"});
00107                   listModel.append({'option': "Send message"});
00108                   break;
00109               }
00110         visible = false;
00111     }
00112 }
00113 }
00114 
00115 

Generated by  doxygen 1.6.2