main.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. var buffInfoPanels = new Array();
  2. function infoMessage( infoPanelComponent, icon, textMessages, time_ms, color )
  3. {
  4. var sprite = infoPanelComponent.createObject( main.mainViewItem, {
  5. "text": textMessages,
  6. "__numScreen": buffInfoPanels.length,
  7. "icon": icon,
  8. "colorBorder": color
  9. } );
  10. buffInfoPanels.push( sprite );
  11. time_ms = time_ms || 3000
  12. sprite.showPanelTime( time_ms );
  13. if ( sprite == null ) {
  14. console.log("infoMessage(): error creating object");
  15. }
  16. }
  17. function removeInfoPanel( objPanel )
  18. {
  19. var remN = objPanel.__numScreen;
  20. for( var j = 0; j < buffInfoPanels.length; j++ )
  21. {
  22. var sprite = buffInfoPanels[ j ];
  23. var n = sprite.__numScreen;
  24. if( n > remN )
  25. {
  26. sprite.__numScreen = sprite.__numScreen - 1
  27. }
  28. }
  29. objPanel.destroy()
  30. buffInfoPanels.splice( remN, 1 );
  31. }
  32. function clearInfoStack()
  33. {
  34. buffInfoPanels.length = 0
  35. }
  36. function infoMessageN( icon, textMessages, time_ms, color )
  37. {
  38. var component = Qt.createComponent("TopInfoPanel.qml");
  39. var sprite = component.createObject( main.mainViewItem, {
  40. "text": textMessages,
  41. "__numScreen": buffInfoPanels.length,
  42. "icon": icon,
  43. "colorBorder": color
  44. } );
  45. buffInfoPanels.push( sprite );
  46. time_ms = time_ms || 3000
  47. sprite.showPanelTime( time_ms );
  48. if ( sprite == null ) {
  49. console.log("infoMessage(): error creating object");
  50. }
  51. }
  52. /****************************************************************/
  53. function baseName(path) {
  54. var filePath = path.toString();
  55. var pos1 = 0;
  56. var pos2 = 0;
  57. while( path != "" )
  58. {
  59. pos1 = filePath.indexOf("/", pos2);
  60. if( pos1 < 0 )
  61. {
  62. return filePath.substring( pos2 );
  63. }
  64. pos2 = pos1+1
  65. }
  66. return "";
  67. }
  68. function basePath(path) {
  69. var filePath = path.toString();
  70. var pos = 0;
  71. pos = filePath.lastIndexOf("/");
  72. //console.log( "pos1="+pos1 )
  73. //console.log( "filePath="+filePath )
  74. if( pos >= 0 )
  75. {
  76. //console.log( "filePath.length=" + filePath.length )
  77. return filePath.substring( 0, pos );
  78. }
  79. return "";
  80. }
  81. /****************************************************************/
  82. var bufColorName = new Array();
  83. var indexColorName = 0;
  84. function getColorByIndex( index )
  85. {
  86. var ret = "#000000"
  87. switch( index )
  88. {
  89. case 0: ret = "#020066"; break;
  90. case 1: ret = "#96003c"; break;
  91. case 2: ret = "#006a96"; break;
  92. case 3: ret = "#009691"; break;
  93. case 4: ret = "#00963c"; break;
  94. case 5: ret = "#57b100"; break;
  95. case 6: ret = "#b1a700"; break;
  96. case 7: ret = "#9b5168"; break;
  97. case 8: ret = "#ed8f88"; break;
  98. case 9: ret = "#875450"; break;
  99. case 10: ret = "#3e4a96"; break;
  100. }
  101. //console.log( "getColorByIndex("+index+") = " + ret )
  102. return ret;
  103. }
  104. function getNameColor( name )
  105. {
  106. var colorName = bufColorName[ name ];
  107. //console.log( "colorName="+colorName + " name="+name )
  108. if( colorName == undefined ) {
  109. colorName = getColorByIndex(indexColorName);
  110. bufColorName[ name ] = colorName;
  111. indexColorName = indexColorName + 1;
  112. }
  113. return colorName;
  114. }
  115. /****************************************************************/
  116. var componentFC;
  117. var spriteFC;
  118. function dlgFilesChoose( appWindow, presetDir, callbackFunc )
  119. {
  120. componentFC = Qt.createComponent("DialogFiles.qml");
  121. if (componentFC.status == Component.Ready)
  122. finishCreationFC( appWindow, presetDir, callbackFunc );
  123. else
  124. componentFC.statusChanged.connect( finishCreationFC(appWindow, presetDir, callbackFunc) );
  125. }
  126. function finishCreationFC( appWindow, presetDir, callbackFunc )
  127. {
  128. if (componentFC.status == Component.Ready)
  129. {
  130. spriteFC = componentFC.createObject(appWindow, {"presetPath": presetDir} );
  131. if (spriteFC == null) {
  132. console.log("Error creating DialogFiles.qml");
  133. }
  134. }
  135. else if (componentFC.status == Component.Error)
  136. {
  137. console.log( "Error loading component:", componentFC.errorString() );
  138. }
  139. spriteFC.fileSelected.connect( callbackFunc );
  140. spriteFC.dlgShowHide();
  141. }
  142. /****************************************************************/