Advertisement
Guest User

Untitled

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