StatusBar.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/EAction.js");
  20. /**
  21. * The status bar is created and initialized here.
  22. */
  23. function StatusBar(guiAction) {
  24. EAction.call(this, guiAction);
  25. }
  26. StatusBar.prototype = new EAction();
  27. StatusBar.getPreferencesCategory = function() {
  28. return [qsTr("Widgets"), qsTr("Status Bar")];
  29. };
  30. StatusBar.init = function(basePath) {
  31. var appWin = EAction.getMainWindow();
  32. var action = new RGuiAction(qsTr("&Status Bar"), appWin);
  33. action.setRequiresDocument(false);
  34. action.setScriptFile(basePath + "/StatusBar.js");
  35. //action.setIcon(basePath + "/StatusBar.svg");
  36. action.setDefaultShortcut(new QKeySequence("g,s"));
  37. action.setDefaultCommands(["gs"]);
  38. action.setGroupSortOrder(3800);
  39. action.setSortOrder(200);
  40. action.setWidgetNames(["ViewMenu", "!WidgetsToolBar", "!ViewToolsPanel"]);
  41. var statusBar = appWin.statusBar();
  42. var splitter = new QSplitter(statusBar);
  43. splitter.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.Fixed);
  44. splitter.setFixedHeight(40);
  45. splitter.childrenCollapsible = false;
  46. splitter.objectName = "StatusBar";
  47. statusBar.addWidget(splitter, 1000);
  48. };
  49. StatusBar.postInit = function() {
  50. var statusBarSplitter = StatusBar.getStatusBarSplitter();
  51. if (isNull(statusBarSplitter)) {
  52. return;
  53. }
  54. var sl = RSettings.getStringListValue("StatusBar/Sizes", []);
  55. var l = [];
  56. for (var i=0; i<sl.length; i++) {
  57. l.push(parseInt(sl[i]));
  58. }
  59. statusBarSplitter.setSizes(l);
  60. };
  61. StatusBar.uninit = function(basePath) {
  62. var statusBarSplitter = StatusBar.getStatusBarSplitter();
  63. if (isNull(statusBarSplitter)) {
  64. return;
  65. }
  66. var sizes = statusBarSplitter.sizes();
  67. var sl = [];
  68. for (var i=0; i<sizes.length; i++) {
  69. sl.push("%1".arg(sizes[i]));
  70. }
  71. RSettings.setValue("StatusBar/Sizes", sl);
  72. };
  73. StatusBar.clearMessage = function() {
  74. var appWin = EAction.getMainWindow();
  75. var statusBar = appWin.statusBar();
  76. statusBar.clearMessage();
  77. };
  78. StatusBar.getStatusBarSplitter = function() {
  79. var appWin = EAction.getMainWindow();
  80. return appWin.findChild("StatusBar");
  81. };
  82. StatusBar.addWidget = function(widget, sortOrder, visible) {
  83. widget.setProperty("SortOrder", sortOrder);
  84. var i;
  85. var appWin = EAction.getMainWindow();
  86. var statusBarSplitter = appWin.findChild("StatusBar");
  87. var list = [];
  88. for (i=0; i<statusBarSplitter.count(); i++) {
  89. list.push(statusBarSplitter.widget(i));
  90. }
  91. var maxSortOrder = 0;
  92. var index = 0;
  93. for (i = 0; i < list.length; ++i) {
  94. var w = list[i];
  95. var wSortOrder = w.property("SortOrder");
  96. if (wSortOrder > maxSortOrder && wSortOrder < widget.property("SortOrder")) {
  97. maxSortOrder = wSortOrder;
  98. index = i+1;
  99. }
  100. }
  101. widget.setParent(statusBarSplitter);
  102. if (index >= list.length) {
  103. statusBarSplitter.addWidget(widget);
  104. } else {
  105. statusBarSplitter.insertWidget(index, widget);
  106. }
  107. widget.visible = visible;
  108. };
  109. StatusBar.applyPreferences = function(doc, mdiChild) {
  110. var appWin = RMainWindowQt.getMainWindow();
  111. var statusBarSplitter = StatusBar.getStatusBarSplitter();
  112. StatusBar.applyFont(statusBarSplitter);
  113. var widgetNames = ["CoordinateDisplay", "MouseDisplay", "SelectionDisplay", "ProgressDisplay"];
  114. for (var i=0; i<widgetNames.length; i++) {
  115. var widgetName = widgetNames[i];
  116. var w = statusBarSplitter.findChild(widgetName);
  117. if (!isNull(w)) {
  118. w.visible = RSettings.getBoolValue("StatusBar/" + widgetName, true);
  119. }
  120. w = statusBarSplitter.findChild(widgetName + "Separator");
  121. if (!isNull(w)) {
  122. w.visible = RSettings.getBoolValue("StatusBar/" + widgetName, true);
  123. }
  124. }
  125. };
  126. StatusBar.applyFont = function(widget) {
  127. var children = widget.children();
  128. for (var i = 0; i < children.length; ++i) {
  129. var c = children[i];
  130. if (isOfType(c, QLabel) || isOfType(c, QComboBox)) {
  131. c.font = RSettings.getStatusBarFont();
  132. }
  133. else {
  134. StatusBar.applyFont(c);
  135. }
  136. }
  137. };
  138. StatusBar.prototype.beginEvent = function() {
  139. EAction.prototype.beginEvent.call(this);
  140. if (RSettings.getOriginalArguments().contains("-no-show")) {
  141. return;
  142. }
  143. var appWin = RMainWindowQt.getMainWindow();
  144. var widget = appWin.statusBar();
  145. widget.visible = !widget.visible;
  146. };