BlockInsert.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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("Block.js");
  20. /**
  21. * \class Block
  22. * \ingroup ecma_block
  23. * \brief Base action for actions that insert blocks from the drawing or
  24. * other sources.
  25. */
  26. function BlockInsert(guiAction) {
  27. Block.call(this, guiAction);
  28. this.attributes = {};
  29. }
  30. BlockInsert.prototype = new Block();
  31. BlockInsert.includeBasePath = includeBasePath;
  32. BlockInsert.prototype.beginEvent = function() {
  33. Block.prototype.beginEvent.call(this);
  34. // hide attribute widgets by default:
  35. this.showAttributeControls(false);
  36. };
  37. BlockInsert.prototype.showAttributeControls = function(show) {
  38. var optionsToolBar = EAction.getOptionsToolBar();
  39. var widgetActionNames = [
  40. "AttributeLabelAction",
  41. "AttributeTagAction",
  42. "AttributeEqualLabelAction",
  43. "AttributeValueAction",
  44. "AttributeSeparatorAction"
  45. ];
  46. for (var i=0; i<widgetActionNames.length; i++) {
  47. var widgetActionName = widgetActionNames[i];
  48. var w = optionsToolBar.findChild(widgetActionName);
  49. if (!isNull(w)) {
  50. w.visible = show;
  51. }
  52. }
  53. };
  54. BlockInsert.prototype.slotReset = function() {
  55. Block.prototype.slotReset.call(this);
  56. this.attributes = [];
  57. this.slotAttributeTagChanged();
  58. };
  59. BlockInsert.prototype.slotAttributeTagChanged = function() {
  60. var optionsToolBar = EAction.getOptionsToolBar();
  61. var tagCombo = optionsToolBar.findChild("AttributeTag");
  62. var valueEdit = optionsToolBar.findChild("AttributeValue");
  63. var data = tagCombo.itemData(tagCombo.currentIndex);
  64. if (isNull(data)) {
  65. return;
  66. }
  67. var tag = data[0];
  68. var defaultValue = data[1];
  69. if (!isNull(this.attributes[tag])) {
  70. valueEdit.text = this.attributes[tag];
  71. }
  72. else {
  73. // init line edit with default value:
  74. valueEdit.text = data[1];
  75. }
  76. };
  77. BlockInsert.prototype.slotAttributeValueChanged = function(value) {
  78. var optionsToolBar = EAction.getOptionsToolBar();
  79. var tagCombo = optionsToolBar.findChild("AttributeTag");
  80. var valueEdit = optionsToolBar.findChild("AttributeValue");
  81. var data = tagCombo.itemData(tagCombo.currentIndex);
  82. if (isNull(data)) {
  83. return;
  84. }
  85. var tag = data[0];
  86. this.attributes[tag] = value;
  87. };