Advertisement
Guest User

Untitled

a guest
Mar 15th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
QML 6.18 KB | None | 0 0
  1. import QtQuick 2.11
  2. import QtQuick.Controls 2.4
  3. import QtQml.Models 2.11
  4.  
  5. Item {
  6.     id: element
  7.     clip: true
  8.  
  9.     property Component columnHeader: Item {}
  10.     property Component rowHeader: Item {}
  11.     property Component cell: Item {}
  12.  
  13.     property int rowsCount: 0
  14.     property int columnsCount: 0
  15.  
  16.     property alias columnHeaderHeight: luRectangle.height
  17.     property alias rowHeaderWidth: luRectangle.width
  18.  
  19.     QtObject {
  20.         id: __private
  21.         property var columnWidths: ({})
  22.         property var rowHeights: ({})
  23.  
  24.         function changeWidth(index, width) {
  25.             columnWidths[index] = width
  26.             widthChanged(index, width)
  27.         }
  28.         function changeHeight(index, height) {
  29.             rowHeights[index] = height
  30.             heightChanged(index, height)
  31.         }
  32.  
  33.         signal widthChanged(int columnIndex, real newWidth)
  34.         signal heightChanged(int rowIndex, real newHeight)
  35.     }
  36.  
  37.  
  38.     ResizableItem {
  39.         id: luRectangle
  40.         width: 20
  41.         height: 20
  42.         anchors.top: parent.top
  43.         anchors.left: parent.left
  44.     }
  45.  
  46.     Flickable {
  47.         id: columnsFlickable
  48.         clip: true
  49.         anchors.left: luRectangle.right
  50.         anchors.top: parent.top
  51.         height: luRectangle.height
  52.         anchors.right: verticalRightScrollBar.left
  53.         contentWidth: contentRow.width
  54.         ScrollBar.horizontal: horizontalBottomScrollBar
  55.         boundsMovement:   Flickable.StopAtBounds
  56.         Row {
  57.             id: contentRow
  58.             height: parent.height
  59.             Repeater {
  60.                 height: parent.height
  61.                 ResizableItem {
  62.  
  63.                     height: parent.height
  64.                     onHeightChanged: luRectangle.height = height
  65.                     property int __index: index
  66.                     Loader {
  67.                         id: columnHeaderLoader
  68.                         property int index: parent.__index
  69.                         sourceComponent: columnHeader
  70.                         height: parent.height
  71.                     }
  72.                     width: columnHeaderLoader.width
  73.                     onWidthChanged: {
  74.                         columnHeaderLoader.width = width
  75.                         __private.changeWidth(index, width)
  76.                     }
  77.                 }
  78.                 model: columnsCount
  79.             }
  80.         }
  81.     }
  82.  
  83.     Flickable {
  84.         id: rowsFlickable
  85.         width: luRectangle.width
  86.         clip: true
  87.         anchors.left: parent.left
  88.         anchors.top: luRectangle.bottom
  89.         anchors.bottom: horizontalBottomScrollBar.top
  90.         ScrollBar.vertical: verticalRightScrollBar
  91.         contentHeight: contentColumn.height
  92.         boundsMovement:   Flickable.StopAtBounds
  93.         Column {
  94.             id: contentColumn
  95.             width: parent.width
  96.             Repeater {
  97.                 anchors.left: parent.left
  98.                 ResizableItem {
  99.                     id: rowHeaderItem
  100.                     width: parent.width
  101.                     onWidthChanged: luRectangle.width = width
  102.                     property int __index: index
  103.                     Loader {
  104.                         id: rowHeaderLoader
  105.                         property int index: rowHeaderItem.__index
  106.                         sourceComponent: rowHeader
  107.                         width: parent.width
  108.                     }
  109.                     height: rowHeaderLoader.height
  110.  
  111.                     onHeightChanged: {
  112.                         rowHeaderLoader.height = height
  113.                         __private.changeHeight(index, height)
  114.                     }
  115.  
  116.                 }
  117.                 model: rowsCount
  118.             }
  119.         }
  120.     }
  121.  
  122.  
  123.     Flickable {
  124.         clip: true
  125.         //interactive: false
  126.         anchors.bottom: horizontalBottomScrollBar.top
  127.         anchors.right: verticalRightScrollBar.left
  128.         anchors.left: luRectangle.right
  129.         anchors.top: luRectangle.bottom
  130.         ScrollBar.horizontal: horizontalBottomScrollBar
  131.         ScrollBar.vertical: verticalRightScrollBar
  132.         contentHeight: gridContent.height
  133.         contentWidth: gridContent.width
  134.         boundsMovement:   Flickable.StopAtBounds
  135.         Grid {
  136.             id: gridContent
  137.             columns: columnsCount
  138.             Repeater {
  139.                 model: columnsCount * rowsCount
  140.                 Item {
  141.                     id: cellContent
  142.  
  143.                     Loader {
  144.                         id: cellLoader
  145.                         property int column: index % columnsCount
  146.                         property int row: index / columnsCount
  147.                         sourceComponent: cell
  148.                         width: parent.width
  149.                         height: parent.height
  150.                     }
  151.  
  152.                     width: __private.columnWidths[cellLoader.column] || 0
  153.                     height: __private.rowHeights[cellLoader.row] || 0
  154.                     Connections {
  155.                         target: __private
  156.                         onWidthChanged: {
  157.                             if (columnIndex==cellLoader.column) {
  158.                                 cellContent.width = newWidth
  159.                             }
  160.                         }
  161.                         onHeightChanged: {
  162.                             if (rowIndex==cellLoader.row) {
  163.                                 cellContent.height = newHeight
  164.                             }
  165.                         }
  166.                     }
  167.                 }
  168.             }
  169.         }
  170.     }
  171.  
  172.     ScrollBar {
  173.         id: verticalRightScrollBar
  174.         orientation: Qt.Vertical
  175.         anchors.bottom: drRectangle.top
  176.         anchors.top: parent.top
  177.         anchors.right: parent.right
  178.         size: columnsFlickable.contentWidth
  179.     }
  180.     ScrollBar {
  181.         id: horizontalBottomScrollBar
  182.         anchors.right: drRectangle.left
  183.         anchors.left: parent.left
  184.         anchors.bottom: parent.bottom
  185.         size: rowsFlickable.contentHeight
  186.     }
  187.  
  188.     Rectangle {
  189.         id: drRectangle
  190.         width: verticalRightScrollBar.width
  191.         height: horizontalBottomScrollBar.height
  192.         anchors.bottom: parent.bottom
  193.         anchors.right: parent.right
  194.         color: "lightgray"
  195.     }
  196.  
  197. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement