KeyIcon.qml 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright (C) 2016 The Qt Company Ltd.
  2. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
  3. import QtQuick
  4. /*!
  5. \qmltype KeyIcon
  6. \inqmlmodule QtQuick.VirtualKeyboard.Styles
  7. \brief Key icon with adjustable color.
  8. \ingroup qmlclass
  9. \ingroup qtvirtualkeyboard-styles-qml
  10. The KeyIcon item displays an icon with adjustable color.
  11. */
  12. Item {
  13. /*! The icon color. */
  14. property alias color: overlay.color
  15. /*! The source image. */
  16. property alias source: icon.source
  17. Image {
  18. id: icon
  19. sourceSize.height: parent.height
  20. sourceSize.width: parent.width
  21. anchors.horizontalCenter: parent.horizontalCenter
  22. anchors.verticalCenter: parent.verticalCenter
  23. visible: false
  24. }
  25. ShaderEffect {
  26. id: overlay
  27. property color color
  28. property variant texture: icon
  29. anchors.fill: icon
  30. fragmentShader: "
  31. uniform lowp vec4 color;
  32. uniform lowp float qt_Opacity;
  33. uniform lowp sampler2D texture;
  34. varying highp vec2 qt_TexCoord0;
  35. void main() {
  36. highp vec4 sample = texture2D(texture, qt_TexCoord0) * qt_Opacity;
  37. gl_FragColor = vec4(color.rgb, 1.0) * sample.a;
  38. }
  39. "
  40. }
  41. }