FluInfoBar.qml 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. import QtQuick
  2. import QtQuick.Controls
  3. import FluentUI
  4. FluObject {
  5. id:infoBar
  6. property var root;
  7. property int layoutY: 75;
  8. FluObject{
  9. id:mcontrol
  10. property string const_success: "success";
  11. property string const_info: "info";
  12. property string const_warning: "warning";
  13. property string const_error: "error";
  14. property int maxWidth: 300;
  15. property var screenLayout: null;
  16. function create(type,text,duration,moremsg){
  17. if(screenLayout){
  18. var last = screenLayout.getLastloader();
  19. if(last.type === type && last.text === text && moremsg === last.moremsg){
  20. last.restart();
  21. return;
  22. }
  23. }
  24. initScreenLayout();
  25. contentComponent.createObject(screenLayout,{
  26. type:type,
  27. text:text,
  28. duration:duration,
  29. moremsg:moremsg,
  30. });
  31. }
  32. function createCustom(itemcomponent,duration){
  33. initScreenLayout();
  34. if(itemcomponent){
  35. contentComponent.createObject(screenLayout,{itemcomponent:itemcomponent,duration:duration});
  36. }
  37. }
  38. function initScreenLayout(){
  39. if(screenLayout == null){
  40. screenLayout = screenlayoutComponent.createObject(root);
  41. screenLayout.y = infoBar.layoutY;
  42. screenLayout.z = 100000;
  43. }
  44. }
  45. Component{
  46. id:screenlayoutComponent
  47. Column{
  48. spacing: 20
  49. width: parent.width
  50. move: Transition {
  51. NumberAnimation { properties: "y"; easing.type: Easing.OutBack; duration: 300 }
  52. }
  53. onChildrenChanged: if(children.length === 0) destroy();
  54. function getLastloader(){
  55. if(children.length > 0){
  56. return children[children.length - 1];
  57. }
  58. return null;
  59. }
  60. }
  61. }
  62. Component{
  63. id:contentComponent
  64. Item{
  65. id:content;
  66. property int duration: 1500
  67. property var itemcomponent
  68. property string type
  69. property string text
  70. property string moremsg
  71. width: parent.width;
  72. height: loader.height;
  73. function close(){
  74. content.destroy();
  75. }
  76. function restart(){
  77. delayTimer.restart();
  78. }
  79. Timer {
  80. id:delayTimer
  81. interval: duration; running: true; repeat: true
  82. onTriggered: content.close();
  83. }
  84. Loader{
  85. id:loader;
  86. x:(parent.width - width) / 2;
  87. property var _super: content;
  88. scale: item ? 1 : 0;
  89. asynchronous: true
  90. Behavior on scale {
  91. NumberAnimation {
  92. easing.type: Easing.OutBack;
  93. duration: 100
  94. }
  95. }
  96. sourceComponent:itemcomponent ? itemcomponent : mcontrol.fluent_sytle;
  97. }
  98. }
  99. }
  100. property Component fluent_sytle: Rectangle{
  101. width: rowlayout.width + (_super.moremsg ? 25 : 80);
  102. height: rowlayout.height + 20;
  103. color: {
  104. if(FluTheme.dark){
  105. switch(_super.type){
  106. case mcontrol.const_success: return Qt.rgba(57/255,61/255,27/255,1);
  107. case mcontrol.const_warning: return Qt.rgba(67/255,53/255,25/255,1);
  108. case mcontrol.const_info: return Qt.rgba(39/255,39/255,39/255,1);
  109. case mcontrol.const_error: return Qt.rgba(68/255,39/255,38/255,1);
  110. }
  111. return Qt.rgba(255,255,255,1)
  112. }else{
  113. switch(_super.type){
  114. case mcontrol.const_success: return "#dff6dd";
  115. case mcontrol.const_warning: return "#fff4ce";
  116. case mcontrol.const_info: return "#f4f4f4";
  117. case mcontrol.const_error: return "#fde7e9";
  118. }
  119. return "#FFFFFF"
  120. }
  121. }
  122. radius: 4
  123. border.width: 1
  124. border.color: {
  125. if(FluTheme.dark){
  126. switch(_super.type){
  127. case mcontrol.const_success: return Qt.rgba(56/255,61/255,27/255,1);
  128. case mcontrol.const_warning: return Qt.rgba(66/255,53/255,25/255,1);
  129. case mcontrol.const_info: return Qt.rgba(38/255,39/255,39/255,1);
  130. case mcontrol.const_error: return Qt.rgba(67/255,39/255,38/255,1);
  131. }
  132. return "#FFFFFF"
  133. }else{
  134. switch(_super.type){
  135. case mcontrol.const_success: return "#d2e8d0";
  136. case mcontrol.const_warning: return "#f0e6c2";
  137. case mcontrol.const_info: return "#e6e6e6";
  138. case mcontrol.const_error: return "#eed9db";
  139. }
  140. return "#FFFFFF"
  141. }
  142. }
  143. Row{
  144. id:rowlayout
  145. x:20;
  146. y:(parent.height - height) / 2;
  147. spacing: 10
  148. FluIcon{
  149. iconSource:{
  150. switch(_super.type){
  151. case mcontrol.const_success: return FluentIcons.CompletedSolid;
  152. case mcontrol.const_warning: return FluentIcons.InfoSolid;
  153. case mcontrol.const_info: return FluentIcons.InfoSolid;
  154. case mcontrol.const_error: return FluentIcons.StatusErrorFull;
  155. }FluentIcons.StatusErrorFull
  156. return FluentIcons.FA_info_circle
  157. }
  158. iconSize:20
  159. iconColor: {
  160. if(FluTheme.dark){
  161. switch(_super.type){
  162. case mcontrol.const_success: return Qt.rgba(108/255,203/255,95/255,1);
  163. case mcontrol.const_warning: return Qt.rgba(252/255,225/255,0/255,1);
  164. case mcontrol.const_info: return FluTheme.primaryColor.lighter;
  165. case mcontrol.const_error: return Qt.rgba(255/255,153/255,164/255,1);
  166. }
  167. return "#FFFFFF"
  168. }else{
  169. switch(_super.type){
  170. case mcontrol.const_success: return "#0f7b0f";
  171. case mcontrol.const_warning: return "#9d5d00";
  172. case mcontrol.const_info: return "#0066b4";
  173. case mcontrol.const_error: return "#c42b1c";
  174. }
  175. return "#FFFFFF"
  176. }
  177. }
  178. }
  179. FluText{
  180. text:_super.text
  181. wrapMode: Text.WrapAnywhere
  182. width: Math.min(implicitWidth,mcontrol.maxWidth)
  183. }
  184. }
  185. }
  186. }
  187. function showSuccess(text,duration=1000,moremsg){
  188. mcontrol.create(mcontrol.const_success,text,duration,moremsg ? moremsg : "");
  189. }
  190. function showInfo(text,duration=1000,moremsg){
  191. mcontrol.create(mcontrol.const_info,text,duration,moremsg ? moremsg : "");
  192. }
  193. function showWarning(text,duration=1000,moremsg){
  194. mcontrol.create(mcontrol.const_warning,text,duration,moremsg ? moremsg : "");
  195. }
  196. function showError(text,duration=1000,moremsg){
  197. mcontrol.create(mcontrol.const_error,text,duration,moremsg ? moremsg : "");
  198. }
  199. function showCustom(itemcomponent,duration=1000){
  200. mcontrol.createCustom(itemcomponent,duration);
  201. }
  202. }