ProgressBar.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Copyright (c) 2011-2018 by Andrew Mustun. All rights reserved.
  3. *
  4. * This file is part of the QCAD project.
  5. *
  6. * QCAD is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * QCAD is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with QCAD.
  18. */
  19. include("scripts/WidgetFactory.js");
  20. include("scripts/Widgets/StatusBar/StatusBar.js");
  21. function ProgressBar() {
  22. ProgressBar.progressBar = undefined;
  23. ProgressBar.text = "";
  24. }
  25. /**
  26. * Progress bar widget in status bar.
  27. */
  28. ProgressBar.postInit = function(basePath) {
  29. var widget = WidgetFactory.createWidget(basePath, "ProgressBar.ui");
  30. StatusBar.addWidget(widget, 1000, RSettings.getBoolValue("StatusBar/ProgressDisplay", true));
  31. ProgressBar.prepare();
  32. if (!isNull(ProgressBar.progressBar)) {
  33. ProgressBar.progressBar.visible = false;
  34. }
  35. var appWin = EAction.getMainWindow();
  36. appWin.progressText.connect(this, this.setProgressText);
  37. appWin.progress.connect(this, this.progress);
  38. appWin.progressEnd.connect(this, this.progressEnd);
  39. };
  40. ProgressBar.prepare = function() {
  41. var appWin = EAction.getMainWindow();
  42. var statusBar = appWin.findChild("StatusBar");
  43. ProgressBar.progressLabel = statusBar.findChild("ProgressText");
  44. ProgressBar.progressBar = statusBar.findChild("ProgressBar");
  45. ProgressBar.progressDialog = appWin.findChild("ProgressDialog");
  46. ProgressBar.dialogMode = RSettings.getBoolValue("Appearance/ShowProgressDialog", false);
  47. };
  48. ProgressBar.setProgressText = function(text) {
  49. ProgressBar.prepare();
  50. if (ProgressBar.dialogMode===true) {
  51. if (!isNull(ProgressBar.progressDialog)) {
  52. ProgressBar.progressDialog.labelText = text;
  53. }
  54. else {
  55. ProgressBar.text = text;
  56. }
  57. }
  58. else {
  59. if (!isNull(ProgressBar.progressLabel)) {
  60. ProgressBar.progressLabel.text = text;
  61. }
  62. }
  63. };
  64. ProgressBar.progress = function(value) {
  65. ProgressBar.prepare();
  66. if (ProgressBar.dialogMode===true) {
  67. if (isNull(ProgressBar.progressDialog)) {
  68. ProgressBar.progressDialog = new QProgressDialog(ProgressBar.text, "", 0, 100, EAction.getMainWindow());
  69. ProgressBar.progressDialog.objectName = "ProgressDialog";
  70. ProgressBar.progressDialog.windowModality = Qt.ApplicationModal;
  71. ProgressBar.progressDialog.minimumDuration = 500;
  72. ProgressBar.progressDialog.setCancelButton(0);
  73. }
  74. ProgressBar.progressDialog.value = value;
  75. // don't process events if modal dialog does not block user from doing something:
  76. if (ProgressBar.progressDialog.visible) {
  77. QCoreApplication.processEvents();
  78. }
  79. }
  80. else {
  81. if (!isNull(ProgressBar.progressBar)) {
  82. if (!RSettings.getOriginalArguments().contains("-no-show")) {
  83. ProgressBar.progressBar.visible = true;
  84. }
  85. ProgressBar.progressBar.value = value;
  86. }
  87. }
  88. var appWin = EAction.getMainWindow();
  89. if (appWin.enabled) {
  90. appWin.disable();
  91. }
  92. };
  93. ProgressBar.progressEnd = function() {
  94. ProgressBar.prepare();
  95. if (ProgressBar.dialogMode===true) {
  96. if (!isNull(ProgressBar.progressDialog)) {
  97. ProgressBar.progressDialog.setValue(100);
  98. }
  99. }
  100. else {
  101. if (!isNull(ProgressBar.progressBar)) {
  102. ProgressBar.progressBar.reset();
  103. ProgressBar.setProgressText("");
  104. ProgressBar.progressBar.visible = false;
  105. }
  106. }
  107. var appWin = EAction.getMainWindow();
  108. if (!appWin.enabled) {
  109. appWin.enable();
  110. }
  111. };