Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 6.09 KB | None | 0 0
  1. import QtQuick 2.6
  2.  
  3. import wesual.Stage   1.0
  4. import wesual.Touch 1.0
  5.  
  6. Item {
  7.     id : virtualKeyboardOverlay
  8.  
  9.     property int translateToY : 52
  10.     property int keyBoardBottomMargin : 600
  11.     property var keyboard
  12.  
  13.     property var filteredDocs : []
  14.     property var autocompleteDocs : []
  15.  
  16.     property string searchString : searchInput.text
  17.  
  18.     implicitWidth  : parent.width
  19.     implicitHeight : parent.height
  20.  
  21.     states : [
  22.         State {
  23.             name : "translate"
  24.             when : virtualKeyboardOverlay.visible
  25.  
  26.             PropertyChanges {
  27.                 target : logo
  28.                 y : translateToY
  29.             }
  30.         }
  31.     ]
  32.  
  33.     transitions : Transition {
  34.         NumberAnimation {
  35.             property : "y"
  36.             duration : 300
  37.         }
  38.     }
  39.  
  40.     onVisibleChanged : {
  41.         if (visible) {
  42.             searchInput.forceActiveFocus();
  43.             filteredDocs = template_.doctors;
  44.             keyboard.botMargin = 700
  45.         }
  46.     }
  47.  
  48.     onFilteredDocsChanged : {
  49.         autocompleteDocs = [];
  50.         var docs = [];
  51.         if (filteredDocs.length > 0) {
  52.             for (var i = 0; i <= 4; i++) {
  53.                 if (filteredDocs.length >= i) {
  54.                     if (filteredDocs[i]) {
  55.                         docs.push(filteredDocs[i]);
  56.                     }
  57.                 }
  58.             }
  59.             autocompleteDocs = docs;
  60.         }
  61.     }
  62.  
  63.     function filterName(doc) {
  64.         var fullName = doc.nachname + " " + doc.vorname
  65.         var passed = true;
  66.         var searchParams = searchString.split(" ");
  67.  
  68.         for (var i = 0; i < searchParams.length; i++) {
  69.             if(!fullName.toLowerCase().includes(searchParams[i].toLowerCase())) {
  70.                 passed = false;
  71.                 break;
  72.             }
  73.         }
  74.  
  75.         return passed;
  76.     }
  77.  
  78.     Component.onCompleted : {
  79.         var component = Qt.createComponent("Keyboard.qml");
  80.         keyboard = component.createObject(keyboardOverlay);
  81.     }
  82.  
  83.     Rectangle {
  84.         id : background
  85.  
  86.         anchors.fill : parent
  87.         opacity : 0.95
  88.     }
  89.  
  90.     TapArea {
  91.         anchors.fill : parent
  92.  
  93.         mouseEnabled : true
  94.  
  95.         onTap : {
  96.             parent.visible = false;
  97.             parent.enabled = false;
  98.             searchInput.text = ""
  99.         }
  100.     }
  101.  
  102.     Image {
  103.         id : logo
  104.  
  105.         anchors {
  106.             horizontalCenter : parent.horizontalCenter
  107.         }
  108.  
  109.         y : 52
  110.  
  111.         source : "ambuLogoSmall.png"
  112.     }
  113.  
  114.     Rectangle {
  115.         id : searchBar
  116.  
  117.         anchors {
  118.             horizontalCenter : parent.horizontalCenter
  119.             top : logo.bottom
  120.             topMargin : 35
  121.         }
  122.  
  123.         width  : 758
  124.         height : 72
  125.         radius : 10
  126.  
  127.         border.width : 2
  128.         border.color : "#afca0b"
  129.  
  130.         Text {
  131.             id : placeHolderText
  132.  
  133.             anchors {
  134.                 left   : parent.left
  135.                 verticalCenter : parent.verticalCenter
  136.                 leftMargin : 25
  137.             }
  138.  
  139.             states : [
  140.                 State {
  141.                     name : "empty"
  142.                     when : searchInput.text.length === 0
  143.  
  144.                     PropertyChanges {
  145.                         target : placeHolderText
  146.                         text   : "Nach Namen suchen ..."
  147.                     }
  148.                 }
  149.             ]
  150.  
  151.             color  : "#706f6f"
  152.             width  : 640
  153.  
  154.             text : ""
  155.  
  156.             font.pixelSize : 32
  157.             font.family : "Lucida Sans Unicode"
  158.         }
  159.  
  160.         TextInput {
  161.             id : searchInput
  162.  
  163.             anchors {
  164.                 left   : parent.left
  165.                 verticalCenter : parent.verticalCenter
  166.                 leftMargin : 25
  167.             }
  168.  
  169.             color  : "#706f6f"
  170.             width  : 640
  171.  
  172.             font.pixelSize : 32
  173.             font.family : "Lucida Sans Unicode"
  174.  
  175.             onTextChanged : {
  176.                 searchString = text;
  177.                 filteredDocs = template_.doctors.filter(filterName);
  178.             }
  179.         }
  180.  
  181.         Item {
  182.             id : searchBarButton
  183.  
  184.             anchors {
  185.                 left : searchInput.right
  186.                 right : parent.right
  187.                 top   : parent.top
  188.                 bottom : parent.bottom
  189.             }
  190.  
  191.             Image {
  192.                 id : searchBarIcon
  193.  
  194.                 anchors.centerIn : parent
  195.  
  196.                 source : "SearchThin.png"
  197.             }
  198.         }
  199.     }
  200.     Column {
  201.         id : searchResultColumn
  202.  
  203.         visible : searchInput.text.length >= 2
  204.         enabled : searchInput.text.length >= 2
  205.  
  206.         anchors {
  207.             top : searchBar.bottom
  208.             horizontalCenter : searchBar.horizontalCenter
  209.         }
  210.  
  211.         width : searchBar.width - 20
  212.         spacing : 1.5
  213.  
  214.         Repeater {
  215.             model : autocompleteDocs
  216.             delegate : Rectangle {
  217.                 id : searchResultDelegate
  218.  
  219.                 width  : 740
  220.                 height : 55
  221.  
  222.                 antialiasing : true
  223.  
  224.                 color : "#afca0b"
  225.  
  226.                 Text {
  227.                     anchors.verticalCenter : parent.verticalCenter
  228.                     color : "white"
  229.  
  230.                     leftPadding : 18
  231.  
  232.                     text : modelData.nachname + " " + modelData.vorname
  233.  
  234.                     font.pixelSize : 38
  235.                     font.family : "Stratum2"
  236.                 }
  237.  
  238.                 TapArea {
  239.                     anchors.fill : parent
  240.  
  241.                     mouseEnabled : true
  242.  
  243.                     onTap : {
  244.                         portrait_.selectedDocs =
  245.                             template_.doctors
  246.                         portrait_.selectedDocsIndex =
  247.                             portrait_.getDocIndex(modelData)
  248.                         virtualKeyboardOverlay.visible = false;
  249.                         virtualKeyboardOverlay.enabled = false;
  250.                         // todo : open doc detail view
  251.                         portrait_.detailedView = true;
  252.                     }
  253.                 }
  254.             }
  255.         }
  256.     }
  257. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement