InnerActiveAdInterstitial.qml 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import QtQuick 1.0
  2. //full screen interstitial ad
  3. //(well should be used fullscreen but you need to specify width and height still
  4. //options:
  5. // message text: something like "A quick word from our sponsors
  6. // color: background color for panel
  7. // skip in: number of seconds before ad can be skipped
  8. Rectangle {
  9. id: adWrapper
  10. //specific to interstitials
  11. //default to a boring gray
  12. color: "#c0c0c0"
  13. property alias messageText: sponsorText.text
  14. property int skipIn: 0
  15. //screen width is important for getting the right ads showing
  16. property alias screenWidth: ad.screenWidth
  17. property alias screenHeight: ad.screenHeight
  18. //private
  19. property int __skippingIn: -1
  20. //aliased to the ad properties so they can be set here but reflected in the child
  21. property alias appid: ad.appid
  22. //these probably don't need to be specified
  23. property alias channelid: ad.channelid
  24. function loadAd() {
  25. ad.loadAd();
  26. //disable skip button and restart timer
  27. if(skipIn > 0) {
  28. __skippingIn = skipIn
  29. skipButton.disabled = true;
  30. skipTimer.start();
  31. }
  32. }
  33. function hide() {
  34. visible = false;
  35. }
  36. function show() {
  37. visible = true;
  38. }
  39. Text {
  40. id: sponsorText
  41. text: "A quick word from our sponsors..."
  42. anchors.horizontalCenter: parent.horizontalCenter
  43. anchors.top: parent.top
  44. anchors.topMargin: 25
  45. font.pointSize: 14
  46. wrapMode: Text.Wrap
  47. color: "black"
  48. }
  49. Column {
  50. id: buttons
  51. spacing: 6
  52. anchors.horizontalCenter: parent.horizontalCenter
  53. anchors.bottom: parent.bottom
  54. anchors.bottomMargin: 25
  55. //width: parent.width
  56. //height: 200
  57. //skip button
  58. Rectangle {
  59. id: skipButton
  60. property bool disabled: false
  61. border.width: 1
  62. radius: 2
  63. border.color: "#060606"
  64. color: "#cfcfcf"
  65. //color: "green"
  66. width: adWrapper.width * .70
  67. //width: 200
  68. height: 40
  69. Text {
  70. color: skipButton.disabled ? "#e0e0e0" : "black"
  71. font.pointSize: 14
  72. anchors.centerIn: parent
  73. text: __skippingIn > 0 ? "Skip in " + __skippingIn + " sec(s)" : "Skip"
  74. }
  75. MouseArea {
  76. anchors.fill: parent
  77. onClicked: {
  78. console.log("skip pressed");
  79. if(parent.disabled == false)
  80. adWrapper.hide();
  81. }
  82. onPressed: { if(!parent.disabled) parent.color = Qt.lighter(parent.color,1.1); }
  83. onReleased: { if(!parent.disabled) parent.color = Qt.darker(parent.color, 1.1); }
  84. }
  85. }
  86. //visit link button
  87. Rectangle {
  88. border.width: 1
  89. radius: 2
  90. border.color: "#060606"
  91. color: "#cfcfcf"
  92. //color: "green"
  93. width: adWrapper.width * .70
  94. //width: 200
  95. height: 40
  96. Text {
  97. color: "black"
  98. font.pointSize: 14
  99. anchors.centerIn: parent
  100. text: "Open Link"
  101. }
  102. MouseArea {
  103. anchors.fill: parent
  104. onClicked: {
  105. console.log("visit ad button pressed");
  106. ad.adClicked();
  107. }
  108. onPressed: { parent.color = Qt.lighter(parent.color,1.2); }
  109. onReleased: { parent.color = Qt.darker(parent.color, 1.2); }
  110. }
  111. }
  112. }
  113. InnerActiveAd {
  114. id: ad
  115. width: parent.width
  116. anchors.bottom: buttons.top
  117. anchors.bottomMargin: 10
  118. anchors.top: sponsorText.bottom
  119. anchors.topMargin: 10
  120. }
  121. Timer {
  122. id: skipTimer
  123. interval: 1000 //countdown timer
  124. repeat: true
  125. onTriggered: {
  126. if(__skippingIn == 0) {
  127. skipTimer.stop();
  128. console.log("Ad finished");
  129. skipButton.disabled = false;
  130. } else
  131. __skippingIn = __skippingIn - 1;
  132. }
  133. }
  134. }