Advertisement
Guest User

Untitled

a guest
Jul 24th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 9.27 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.  
  11.     property var filteredDocs : []
  12.     property var autocompleteDocs : []
  13.     property var keyboard
  14.  
  15.     Keys.onPressed  : portrait_.timerInactive.restart();
  16.     Keys.onReleased : portrait_.timerInactive.restart();
  17.  
  18.     property string searchString : searchInput.text
  19.     property TextInput inputString : searchInput
  20.  
  21.     implicitWidth  : parent.width
  22.     implicitHeight : parent.height
  23.  
  24.     states : [
  25.         State {
  26.             name : "translate"
  27.             when : virtualKeyboardOverlay.visible
  28.  
  29.             PropertyChanges {
  30.                 target : logo
  31.                 y : translateToY
  32.             }
  33.         }
  34.     ]
  35.  
  36.     transitions : Transition {
  37.         NumberAnimation {
  38.             property : "y"
  39.             duration : 300
  40.         }
  41.     }
  42.  
  43.     onVisibleChanged : {
  44.         if (visible) {
  45.             searchInput.forceActiveFocus();
  46.             filteredDocs = template_.doctors;
  47.         }
  48.     }
  49.  
  50.     onFilteredDocsChanged : {
  51.         autocompleteDocs = [];
  52.         var docs = [];
  53.         if (filteredDocs.length > 0) {
  54.             for (var i = 0; i <= 4; i++) {
  55.                 if (filteredDocs.length >= i) {
  56.                     if (filteredDocs[i]) {
  57.                         docs.push(filteredDocs[i]);
  58.                     }
  59.                 }
  60.             }
  61.             autocompleteDocs = docs;
  62.         }
  63.     }
  64.  
  65.     function filterName(doc) {
  66.         var fullName = doc.nachname + " " + doc.vorname
  67.         var passed = true;
  68.         var searchParams = searchString.split(" ");
  69.  
  70.         for (var i = 0; i < searchParams.length; i++) {
  71.             if(!fullName.toLowerCase().includes(searchParams[i].toLowerCase())) {
  72.                 passed = false;
  73.                 break;
  74.             }
  75.         }
  76.  
  77.         return passed;
  78.     }
  79.  
  80.     Component.onCompleted : {
  81.         var component = Qt.createComponent("Keyboard.qml");
  82.         keyboard = component.createObject(keyboardOverlay);
  83.     }
  84.  
  85.     Rectangle {
  86.         id : background
  87.  
  88.         anchors.fill : parent
  89.         opacity : 0.95
  90.     }
  91.  
  92.     TapArea {
  93.         anchors.fill : parent
  94.  
  95.         mouseEnabled : true
  96.  
  97.         onTap : {
  98.             parent.visible = false;
  99.             parent.enabled = false;
  100.             searchInput.text = ""
  101.         }
  102.     }
  103.  
  104.     Image {
  105.         id : logo
  106.  
  107.         anchors {
  108.             horizontalCenter : parent.horizontalCenter
  109.         }
  110.  
  111.         y : 52
  112.  
  113.         source : "ambuLogoSmall.png"
  114.     }
  115.  
  116.     Rectangle {
  117.         id : searchBar
  118.  
  119.         anchors {
  120.             horizontalCenter : parent.horizontalCenter
  121.             top : logo.bottom
  122.             topMargin : 35
  123.         }
  124.  
  125.         width  : 758
  126.         height : 72
  127.         radius : 10
  128.  
  129.         border.width : 2
  130.         border.color : "#afca0b"
  131.  
  132.         Text {
  133.             id : placeHolderText
  134.  
  135.             anchors {
  136.                 left   : parent.left
  137.                 verticalCenter : parent.verticalCenter
  138.                 leftMargin : 25
  139.             }
  140.  
  141.             states : [
  142.                 State {
  143.                     name : "empty"
  144.                     when : searchInput.text.length === 0
  145.  
  146.                     PropertyChanges {
  147.                         target : placeHolderText
  148.                         text   : {
  149.                             if (template_.activeLanguage === "de") {
  150.                                 return "Suchen ...";
  151.                             } else if (template_.activeLanguage === "en") {
  152.                                 return "Search ...";
  153.                             } else
  154.                                 return "Suchen ...";
  155.                         }
  156.                     }
  157.                 }
  158.             ]
  159.  
  160.             color  : "#706f6f"
  161.             width  : 640
  162.  
  163.             text : ""
  164.  
  165.             font.pixelSize : 32
  166.             font.family : "Lucida Sans Unicode"
  167.         }
  168.  
  169.         TextInput {
  170.             id : searchInput
  171.  
  172.             anchors {
  173.                 left   : parent.left
  174.                 verticalCenter : parent.verticalCenter
  175.                 leftMargin : 25
  176.             }
  177.  
  178.             color  : "#706f6f"
  179.             width  : 640
  180.  
  181.             font.pixelSize : 32
  182.             font.family : "Lucida Sans Unicode"
  183.  
  184.             onTextChanged : {
  185.                 searchString = text;
  186.                 filteredDocs = template_.doctors.filter(filterName);
  187.             }
  188.         }
  189.  
  190.         Item {
  191.             id : searchBarButton
  192.  
  193.             anchors {
  194.                 left : searchInput.right
  195.                 right : parent.right
  196.                 top   : parent.top
  197.                 bottom : parent.bottom
  198.             }
  199.  
  200.             Image {
  201.                 id : searchBarIcon
  202.  
  203.                 anchors.centerIn : parent
  204.  
  205.                 source : "SearchThin.png"
  206.             }
  207.         }
  208.     }
  209.  
  210.     Item {
  211.         id : noResultText
  212.  
  213.         width : parent.width
  214.         height : 100
  215.  
  216.         opacity : (autocompleteDocs.length === 0 && searchString.length > 2) ?
  217.                       1 : 0
  218.  
  219.         anchors.top : searchBar.bottom
  220.         anchors.topMargin : 20
  221.         anchors.horizontalCenter : parent.horizontalCenter
  222.  
  223.         Column {
  224.             anchors.horizontalCenter : parent.horizontalCenter
  225.  
  226.             Text {
  227.                 text : {
  228.                     if (template_.activeLanguage === "de") {
  229.                         return "Diese Suche ergab leider kein Ergebnis.";
  230.                     } else if (template_.activeLanguage === "en") {
  231.                         return "Sorry we could not find a match for your search.";
  232.                     } else {
  233.                         return "Diese Suche ergab leider kein Ergebnis.";
  234.                     }
  235.                 }
  236.  
  237.                 font.pixelSize : 26
  238.                 font.family : "Lucida Sans Unicode"
  239.  
  240.                 color  : "#706f6f"
  241.             }
  242.  
  243.             Row {
  244.  
  245.                 anchors.horizontalCenter : parent.horizontalCenter
  246.  
  247.                 Text {
  248.                     text : {
  249.                         if (template_.activeLanguage === "de") {
  250.                             return "In einem ";
  251.                         } else if (template_.activeLanguage === "en") {
  252.                             return "Browse through ";
  253.                         } else {
  254.                             return "In einem ";
  255.                         }
  256.                     }
  257.  
  258.                     font.pixelSize : 26
  259.                     font.family : "Lucida Sans Unicode"
  260.  
  261.                     color  : "#706f6f"
  262.                 }
  263.                 Text {
  264.                     text : {
  265.                         if (template_.activeLanguage === "de") {
  266.                             return "Fachgebiet ";
  267.                         } else if (template_.activeLanguage === "en") {
  268.                             return "medical fields?";
  269.                         } else {
  270.                             return "Fachgebiet ";
  271.                         }
  272.                     }
  273.  
  274.                     font.pixelSize : 26
  275.                     font.family : "Lucida Sans Unicode"
  276.  
  277.                     color  : "#afca0b"
  278.                 }
  279.                 Text {
  280.                     text : {
  281.                         if (template_.activeLanguage === "de") {
  282.                             return "suchen?";
  283.                         } else if (template_.activeLanguage === "en") {
  284.                             return " ";
  285.                         } else {
  286.                             return "suchen?";
  287.                         }
  288.                     }
  289.  
  290.                     font.pixelSize : 26
  291.                     font.family : "Lucida Sans Unicode"
  292.  
  293.                     color  : "#706f6f"
  294.                 }
  295.             }
  296.         }
  297.     }
  298.  
  299.  
  300.     Column {
  301.         id : searchResultColumn
  302.  
  303.         visible : searchInput.text.length >= 2
  304.         enabled : searchInput.text.length >= 2
  305.  
  306.         anchors {
  307.             top : searchBar.bottom
  308.             horizontalCenter : searchBar.horizontalCenter
  309.         }
  310.  
  311.         width : searchBar.width - 20
  312.         spacing : 1.5
  313.  
  314.         Repeater {
  315.             model : autocompleteDocs
  316.             delegate : Rectangle {
  317.                 id : searchResultDelegate
  318.  
  319.                 width  : 740
  320.                 height : 55
  321.  
  322.                 antialiasing : true
  323.  
  324.                 color : "#afca0b"
  325.  
  326.                 Text {
  327.                     anchors.verticalCenter : parent.verticalCenter
  328.                     color : "white"
  329.  
  330.                     leftPadding : 18
  331.  
  332.                     text : modelData.nachname + " " + modelData.vorname
  333.  
  334.                     font.pixelSize : 38
  335.                     font.family : "Stratum2"
  336.                 }
  337.  
  338.                 TapArea {
  339.                     anchors.fill : parent
  340.  
  341.                     mouseEnabled : true
  342.  
  343.                     onTap : {
  344.                         portrait_.selectedDocs =
  345.                             template_.doctors
  346.                         portrait_.selectedDocsIndex =
  347.                             portrait_.getDocIndex(modelData)
  348.                         portrait_.detailedView = true;
  349.                         virtualKeyboardOverlay.enabled = false;
  350.                     }
  351.                 }
  352.             }
  353.         }
  354.     }
  355. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement