Advertisement
Guest User

Untitled

a guest
Jul 19th, 2018
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 7.76 KB | None | 0 0
  1. mport QtQuick 2.10
  2. import QtQuick.Window 2.10
  3. import QtQuick.Controls 2.3
  4. import QtQuick.Layouts 1.3
  5.  
  6.  
  7. Window {
  8.     visible: true
  9.     width: 340
  10.     height: 280
  11.     title: qsTr("")
  12.  
  13.     Connections {
  14.  
  15.         target: bdconnect // Указываем целевое соединение
  16.         /* Объявляем и реализуем функцию, как параметр
  17.          * объекта и с имененем похожим на название сигнала
  18.          * Разница в том, что добавляем в начале on и далее пишем
  19.          * с заглавной буквы
  20.          * */
  21.         onSendToQml: {
  22.             //console.debug("txtNote")
  23.             textArea.text = txtNote
  24.             myModel.updateModel() // И обновляем модель данных с новой записью
  25.         }
  26.     }
  27.  
  28.  
  29.     GridLayout {
  30.         id: gridLayout
  31.         anchors.fill: parent
  32.         anchors.margins: 20
  33.         rowSpacing: 20
  34.         columnSpacing: 20
  35.  
  36.         Row {
  37.             spacing: 2
  38.  
  39.             Layout.fillWidth: true
  40.             Layout.fillHeight: true
  41.  
  42.             Rectangle {
  43.                 id:textzone
  44.                 color: "white"
  45.                 anchors.left: parent.left
  46.                 width: parent.width/2
  47.                 height: parent.height
  48.                 border.width: 1
  49.                 border.color: "black"
  50.                 radius: 3
  51.                
  52.                 ScrollView {
  53.                     id: view
  54.                     anchors.fill: parent
  55.                 TextArea {
  56.                     id: textArea
  57.                     text: qsTr("")
  58.                     property var checktxt:textArea.text
  59.                     anchors.fill: textzone
  60.                     wrapMode: TextEdit.WordWrap
  61.                     onTextChanged:{
  62.                         if (textArea.text !== checktxt && checktxt !== "" && textArea.text !== ""){
  63.                             console.debug("new = |"+textArea.text+ "| " + "old= |" + checktxt +"|")
  64.                             bdconnect.updateBD(textArea.text,list_view1.currentItem.idNote)
  65.                             }
  66.                         }
  67.                 }
  68.                 }
  69.             }
  70.                  Rectangle {
  71.                         id:listzone
  72.                         color: "white";
  73.                         anchors.left: textzone.right
  74.                         anchors.leftMargin: 5
  75.                         width: (parent.width - textzone.width)/2
  76.                         height: parent.height
  77.                         border.width: 1
  78.                         border.color: "black"
  79.                         radius: 3
  80.  
  81.  
  82.                 ListView {
  83.                         id: list_view1
  84.                         anchors.fill: parent
  85.                         clip: true //при соварчивании области списка. текст в списке уходит за границу
  86.  
  87.                         highlight: Rectangle {
  88.                             anchors.margins: 1
  89.                             color: "skyblue"
  90.                             focus: true
  91.                             radius: 3
  92.                         }
  93.                         highlightFollowsCurrentItem: true
  94.                         model:myModel
  95.  
  96.                         delegate: Item {
  97.                             id:deleg
  98.                             //anchors.left: parent.left
  99.  
  100.                             width: list_view1.width
  101.                             height: 12
  102.                             property var idNote: id
  103.                             property var strNote: fNote
  104.                             Item {
  105.                                 id: row1
  106.                                 anchors.fill: parent
  107.                                 anchors.margins: 1
  108.                                 Text {
  109.                                     text: " "+ strNote
  110.                                     //anchors.verticalCenter: parent.verticalCenter
  111.                                     font.bold: true
  112.  
  113.                                 }
  114.                             }
  115.                             MouseArea   {
  116.                                 id: mousearea2
  117.                                 anchors.fill: deleg //растяжениево всю площадь родителя
  118.                                 onClicked: {
  119.                                     list_view1.currentIndex = index //получение индекса элемента под курсором
  120.  
  121.                                 }
  122.                                 onDoubleClicked:{
  123.                                     list_view1.currentIndex = index
  124.                                     console.debug(list_view1.currentIndex)
  125.                                     textArea.clear()
  126.                                     bdconnect.selectBD(list_view1.currentItem.idNote)
  127.  
  128.                                 }
  129.  
  130.                             }
  131.                         }
  132.                     }
  133.                   }
  134.  
  135.  
  136.  
  137.             Rectangle {
  138.                 id:buttonzone
  139.                 color: "white";
  140.                 anchors.right: parent.right
  141.                 anchors.leftMargin: 5
  142.                 width: ((parent.width - textzone.width)/2)-10
  143.                 height: parent.height/3
  144.  
  145.                 Button {
  146.                     id: btnnew
  147.                     text: qsTr("New")
  148.                     anchors.right: buttonzone.top
  149.                     width: buttonzone.width
  150.                     height: buttonzone.height/3
  151.                     background: Rectangle {
  152.                         border.color: "black"
  153.                         color: btnnew.down ? "#DCDCDC":"#FFFFFF"
  154.                         border.width: 1
  155.                         radius: 5
  156.                     }
  157.                     onClicked: {
  158.                               textArea.clear()
  159.                               console.debug(list_view1.currentIndex)
  160.                                }
  161.                 }
  162.  
  163.                 Button {
  164.                     id: btnsave
  165.                     x: 0
  166.                     text: qsTr("Save")
  167.                     anchors.topMargin: 0
  168.                     anchors.top: btnnew.bottom
  169.                     width: buttonzone.width
  170.                     height: buttonzone.height/3
  171.                     background: Rectangle {
  172.                         border.color: "black"
  173.                         color: btnsave.down ? "#DCDCDC":"#FFFFFF"
  174.                         border.width: 1
  175.                         radius: 5
  176.                     }
  177.                     onClicked: {
  178.                           //отправим данные в слот ядра приложения
  179.                           bdconnect.insertBD(textArea.text)
  180.                           myModel.updateModel() // И обновляем модель данных с новой записью
  181.                           console.debug("save= "+list_view1.currentItem.idNote)
  182.                                 }
  183.                 }
  184.                 Button {
  185.                     id: btndel
  186.                     text: qsTr("Del")
  187.                     anchors.top: btnsave.bottom
  188.                     width: buttonzone.width
  189.                     height: buttonzone.height/3
  190.  
  191.                     background: Rectangle {
  192.                         border.color: "black"
  193.                         color: btndel.down ? "#DCDCDC":"#FFFFFF"
  194.                         border.width: 1
  195.                         radius: 5
  196.                     }
  197.                     onClicked: {
  198.                         console.debug(list_view1.currentItem.idNote)
  199.                         bdconnect.deleteNote(list_view1.currentItem.idNote)
  200.                         myModel.updateModel()
  201.  
  202.                     }
  203.  
  204.                 }
  205.  
  206.  
  207.             }
  208.         }
  209.     }
  210.  
  211.  
  212. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement