SelectionDisplay.js 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 SelectionDisplay() {
  22. }
  23. SelectionDisplay.postInit = function(basePath) {
  24. var widget = WidgetFactory.createWidget(basePath, "SelectionDisplay.ui");
  25. StatusBar.addWidget(widget, 300, RSettings.getBoolValue("StatusBar/SelectionDisplay", true));
  26. var selectionText = widget.findChild("SelectionText");
  27. selectionText.font = RSettings.getStatusBarFont();
  28. var appWin = EAction.getMainWindow();
  29. var adapter = new RSelectionListenerAdapter();
  30. appWin.addSelectionListener(adapter);
  31. adapter.selectionChanged.connect(SelectionDisplay.selectionChanged);
  32. };
  33. SelectionDisplay.selectionChanged = function(documentInterface) {
  34. var appWin = EAction.getMainWindow();
  35. var widget = appWin.findChild("SelectionDisplay");
  36. var selectionText = widget.findChild("SelectionText");
  37. if (isNull(documentInterface)) {
  38. selectionText.text = "";
  39. return;
  40. }
  41. // create one of the following text strings:
  42. // 1/n line(s) on layer "X"
  43. // n lines on m layers
  44. // n entities on layer "X"
  45. // n entities on m layers
  46. var doc = documentInterface.getDocument();
  47. var entities = doc.querySelectedEntities();
  48. var count = entities.length;
  49. if (count === 0) {
  50. selectionText.text = qsTr("No entities selected.");
  51. return;
  52. }
  53. var typesSingular = [];
  54. var layers = [];
  55. var pt = new RPropertyTypeId(0);
  56. for (var i = 0; i < count; ++i) {
  57. var entityId = entities[i];
  58. if (entityId == undefined || entityId == "") {
  59. continue;
  60. }
  61. var entity = doc.queryEntityDirect(entityId);
  62. typesSingular.push(entity.getType());
  63. layers.push(entity.getLayerName());
  64. }
  65. typesSingular = typesSingular.unique();
  66. layers = layers.unique();
  67. var str;
  68. if (typesSingular.length == 1) {
  69. var typeStr = entityTypeToString(typesSingular[0], count>1);
  70. if (layers.length == 1 ) {
  71. str = qsTr("%1 %2 on Layer \"%3\"").arg(entities.length).arg(typeStr).arg(layers[0]);
  72. }
  73. else {
  74. str = qsTr("%1 %2 on %3 Layers").arg(entities.length).arg(typeStr).arg(layers.length);
  75. }
  76. } else {
  77. if (layers.length == 1 ) {
  78. str = qsTr("%n Entities on Layer \"%1\"", "", entities.length).arg(layers[0]);
  79. }
  80. else {
  81. str = qsTr("%n Entities", "", entities.length) + " " + qsTr("on") + " " + qsTr("%n Layers", "", layers.length);
  82. }
  83. }
  84. selectionText.text = qsTr("Selected entities:\n%1.").arg(str);
  85. };