CommonCountBubble.qml 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
  4. ** All rights reserved.
  5. ** Contact: Nokia Corporation (qt-info@nokia.com)
  6. **
  7. ** This file is part of the Qt Components project.
  8. **
  9. ** $QT_BEGIN_LICENSE:BSD$
  10. ** You may use this file under the terms of the BSD license as follows:
  11. **
  12. ** "Redistribution and use in source and binary forms, with or without
  13. ** modification, are permitted provided that the following conditions are
  14. ** met:
  15. ** * Redistributions of source code must retain the above copyright
  16. ** notice, this list of conditions and the following disclaimer.
  17. ** * Redistributions in binary form must reproduce the above copyright
  18. ** notice, this list of conditions and the following disclaimer in
  19. ** the documentation and/or other materials provided with the
  20. ** distribution.
  21. ** * Neither the name of Nokia Corporation and its Subsidiary(-ies) nor
  22. ** the names of its contributors may be used to endorse or promote
  23. ** products derived from this software without specific prior written
  24. ** permission.
  25. **
  26. ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  27. ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  28. ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  29. ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  30. ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  31. ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  32. ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  33. ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  34. ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  36. ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
  37. ** $QT_END_LICENSE$
  38. **
  39. ****************************************************************************/
  40. import QtQuick 1.1
  41. import com.nokia.meego 1.0
  42. import "UIConstants.js" as C
  43. /*
  44. Class: CountBubble
  45. CountBubble component is a flexible shape that holds a number and can be added in lists or
  46. notification banners for example.
  47. */
  48. ImplicitSizeItem {
  49. id: root
  50. /*
  51. * Property: largeSized
  52. * [bool=false] Use small or large count bubble.
  53. */
  54. property bool largeSized: false
  55. /*
  56. * Property: value
  57. * [int=0] Reflects the current value.
  58. */
  59. property int value: 0
  60. property string __textValue: root.value
  61. implicitWidth: internal.getBubbleWidth()
  62. implicitHeight: largeSized ? 32:24
  63. BorderImage {
  64. source: "image://theme/" + (largeSized ? C.COLOR_NAME:"") + "meegotouch-countbubble-background"+(largeSized ? "-large":"")
  65. anchors.fill: parent
  66. border { left: 10; top: 10; right: 10; bottom: 10 }
  67. }
  68. Text {
  69. id: text
  70. height: parent.height
  71. y:1
  72. color: largeSized ? "#FFFFFF" : "black"
  73. font.family: largeSized ? C.FONT_FAMILY : C.FONT_FAMILY_BOLD
  74. font.weight: largeSized ? Font.Normal : Font.Bold
  75. anchors.horizontalCenter: parent.horizontalCenter
  76. verticalAlignment: Text.AlignVCenter
  77. font.pixelSize: largeSized ? 22:18
  78. text: root.__textValue
  79. }
  80. QtObject {
  81. id: internal
  82. function getBubbleWidth() {
  83. if (largeSized) {
  84. if (root.__textValue.length < 2)
  85. return 32;
  86. else if (root.__textValue.length < 3)
  87. return 40;
  88. else if (root.__textValue.length < 4)
  89. return 52;
  90. else
  91. return text.paintedWidth+19
  92. } else {
  93. if (root.__textValue.length < 2)
  94. return 24;
  95. else if (root.__textValue.length < 3)
  96. return 30;
  97. else if (root.__textValue.length < 4)
  98. return 40;
  99. else
  100. return text.paintedWidth+13
  101. }
  102. }
  103. }
  104. }