/client/zones/developing/src/controls/TabBar.qml

http://optra.codeplex.com · QML · 111 lines · 100 code · 9 blank · 2 comment · 12 complexity · 322c044406517e73d641feb06452dfea MD5 · raw file

  1. import QtQuick 1.0
  2. import "custom" as Components
  3. import "plugin"
  4. Item {
  5. id: tabbar
  6. property int tabHeight: tabrow.height
  7. property int tabWidth: tabrow.width
  8. Keys.onRightPressed: {
  9. if (tabFrame && tabFrame.current < tabFrame.count - 1)
  10. tabFrame.current = tabFrame.current + 1
  11. }
  12. Keys.onLeftPressed: {
  13. if (tabFrame && tabFrame.current > 0)
  14. tabFrame.current = tabFrame.current - 1
  15. }
  16. height: tabHeight
  17. property Item tabFrame
  18. onTabFrameChanged:parent = tabFrame
  19. visible: tabFrame ? tabFrame.tabsVisible : true
  20. property int __overlap : styleitem.pixelMetric("tabvshift");
  21. property string position: tabFrame ? tabFrame.position : "North"
  22. property string tabBarAlignment: styleitem.styleHint("tabbaralignment");
  23. property int tabOverlap: styleitem.pixelMetric("taboverlap");
  24. property int tabBaseOverlap: styleitem.pixelMetric("tabbaseoverlap");
  25. property int tabHSpace: styleitem.pixelMetric("tabhspace");
  26. property int tabVSpace: styleitem.pixelMetric("tabvspace");
  27. function tab(index) {
  28. for (var i = 0; i < tabrow.children.length; ++i) {
  29. if (tabrow.children[i].tabindex == index) {
  30. return tabrow.children[i]
  31. }
  32. }
  33. return null;
  34. }
  35. QStyleItem {
  36. visible:false
  37. id:styleitem
  38. elementType: "tab"
  39. text: "generic"
  40. }
  41. Row {
  42. id: tabrow
  43. focus: true
  44. property int paintMargins: 1
  45. states:
  46. State {
  47. when: tabBarAlignment == "center"
  48. name: "centered"
  49. AnchorChanges {
  50. target:tabrow
  51. anchors.horizontalCenter: tabbar.horizontalCenter
  52. }
  53. }
  54. Repeater {
  55. id:repeater
  56. focus:true
  57. model: tabFrame ? tabFrame.tabs.length : null
  58. delegate: Item {
  59. id:tab
  60. focus:true
  61. property int tabindex: index
  62. property bool selected : tabFrame.current == index
  63. z: selected ? 1 : -1
  64. function updateRect() {
  65. var rect = style.sizeFromContents(textitem.width + tabHSpace + 2, Math.max(style.fontHeight + tabVSpace + 6, 0))
  66. width = rect.width
  67. height = rect.height
  68. }
  69. // Component.onCompleted: print("taboverlap" + tabOverlap + " tabbaseoverlap " + tabBaseOverlap + " overlap " +__overlap + " hspace " + tabHSpace)
  70. QStyleItem {
  71. id: style
  72. elementType: "tab"
  73. selected: tab.selected
  74. info: tabbar.position
  75. text: tabFrame.tabs[index].title
  76. hover: mousearea.containsMouse
  77. focus: tabbar.focus && selected
  78. property bool first: index === 0
  79. paintMargins: tabrow.paintMargins
  80. activeControl: tabFrame.count == 1 ? "only" : index === 0 ? "beginning" :
  81. index == tabFrame.count-1 ? "end" : "middle"
  82. anchors.fill: parent
  83. anchors.margins: -paintMargins
  84. Text {
  85. id: textitem
  86. // Used for size hint
  87. visible: false
  88. onWidthChanged: updateRect()
  89. onHeightChanged: updateRect()
  90. text: tabFrame.tabs[index].title
  91. }
  92. }
  93. MouseArea {
  94. id: mousearea
  95. anchors.fill: parent
  96. hoverEnabled: true
  97. onPressed: tabFrame.current = index
  98. }
  99. }
  100. }
  101. }
  102. }