CommonPageHeader.qml 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2012 Róbert Márki
  4. **
  5. ** This file is part of Web Feeds.
  6. **
  7. ** Web Feeds is free software: you can redistribute it and/or modify
  8. ** it under the terms of the GNU General Public License as published by
  9. ** the Free Software Foundation, either version 3 of the License, or
  10. ** (at your option) any later version.
  11. **
  12. ** Web Feeds is distributed in the hope that it will be useful,
  13. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ** GNU General Public License for more details.
  16. **
  17. ** You should have received a copy of the GNU General Public License
  18. ** along with Web Feeds. If not, see <http://www.gnu.org/licenses/>.
  19. ****************************************************************************/
  20. import QtQuick 1.1
  21. import com.nokia.meego 1.0
  22. import com.nokia.extras 1.1
  23. import "UIConstants.js" as UIConstants
  24. Item {
  25. id: root
  26. signal clicked;
  27. property bool filterEnabled: false
  28. property string titleText: qsTr("Title")
  29. property string subTitleText: qsTr("Subtitle")
  30. property alias titleFont: headerTitle.font.family
  31. property alias subTitleFont: subTitle.font.family
  32. property bool multiline: false
  33. property color titleColor: "black"
  34. property color subTitleColor: "dimgray"
  35. property color backgrounColor: "transparent"
  36. property alias leftHelperItem: leftHelperItemLoader.sourceComponent
  37. property alias rightHelperItem: rightHelperItemLoader.sourceComponent
  38. property int leftHelperSpacing: UIConstants.DEFAULT_MARGIN
  39. property int rightHelperSpacing: UIConstants.DEFAULT_MARGIN
  40. height: root.multiline ? Math.max((UIConstants.HEADER_DEFAULT_TOP_SPACING_PORTRAIT + headerTitle.paintedHeight +
  41. (subTitle.visible ? (subTitle.paintedHeight + UIConstants.DEFAULT_MARGIN) : 0) +
  42. UIConstants.HEADER_DEFAULT_BOTTOM_SPACING_PORTRAIT), UIConstants.HEADER_DEFAULT_HEIGHT_PORTRAIT)
  43. : UIConstants.HEADER_DEFAULT_HEIGHT_PORTRAIT;
  44. Rectangle {
  45. id: background
  46. anchors.fill: parent
  47. color: (root.filterEnabled && mouseArea.pressed) ? "gray" : root.backgrounColor
  48. }
  49. Loader {
  50. id: leftHelperItemLoader
  51. visible: (leftHelperItemLoader.status == Loader.Ready)
  52. anchors.left: parent.left
  53. anchors.leftMargin: leftHelperItemLoader.sourceComponent ? UIConstants.DEFAULT_MARGIN : 0
  54. anchors.verticalCenter: parent.verticalCenter
  55. width: leftHelperItemLoader.sourceComponent ? leftHelperItemLoader.item.width : 0
  56. height: leftHelperItemLoader.sourceComponent ? leftHelperItemLoader.item.height : 0
  57. }
  58. Column {
  59. id: column
  60. anchors.left: leftHelperItemLoader.right
  61. anchors.leftMargin: leftHelperItemLoader.visible ? root.leftHelperSpacing : UIConstants.DEFAULT_MARGIN
  62. anchors.right: rightHelperItemLoader.left
  63. anchors.rightMargin: rightHelperItemLoader.visible ? root.rightHelperSpacing : UIConstants.DEFAULT_MARGIN
  64. anchors.verticalCenter: parent.verticalCenter
  65. spacing: UIConstants.DEFAULT_MARGIN
  66. Label {
  67. id: headerTitle
  68. text: root.titleText
  69. color: root.titleColor
  70. font.pixelSize: UIConstants.FONT_XLARGE
  71. font.weight: Font.Normal
  72. width: parent.width
  73. elide: root.multiline ? Text.ElideNone : Text.ElideRight
  74. wrapMode: root.multiline ? Text.Wrap : Text.NoWrap
  75. }
  76. Label {
  77. id: subTitle
  78. font.weight: Font.Normal
  79. font.pixelSize: UIConstants.FONT_LSMALL
  80. color: root.subTitleColor
  81. visible: subTitle.text.length && root.multiline
  82. text: root.subTitleText
  83. width: parent.width
  84. elide: Text.ElideNone
  85. wrapMode: Text.Wrap
  86. maximumLineCount: 2
  87. }
  88. }
  89. Loader {
  90. id: rightHelperItemLoader
  91. visible: (rightHelperItemLoader.status == Loader.Ready)
  92. anchors.right: filterIndicator.left
  93. anchors.rightMargin: rightHelperItemLoader.sourceComponent ? UIConstants.DEFAULT_MARGIN : 0
  94. anchors.verticalCenter: parent.verticalCenter
  95. width: rightHelperItemLoader.sourceComponent ? rightHelperItemLoader.item.width : 0
  96. height: rightHelperItemLoader.sourceComponent ? rightHelperItemLoader.item.height : 0
  97. }
  98. FilterIndicator {
  99. id: filterIndicator
  100. anchors.verticalCenter: parent.verticalCenter
  101. anchors.right: parent.right
  102. anchors.rightMargin: root.filterEnabled ? UIConstants.DEFAULT_MARGIN : 0
  103. width: root.filterEnabled ? 32 : 0
  104. visible: root.filterEnabled
  105. }
  106. MouseArea {
  107. id: mouseArea
  108. anchors.fill: parent
  109. onClicked: {
  110. if(root.filterEnabled)
  111. root.clicked();
  112. }
  113. }
  114. }