PenToolBar.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. function PenToolBar() {
  21. }
  22. PenToolBar.init = function(basePath) {
  23. var penToolBar = EAction.getToolBar(qsTr("Pen"), "Pen");
  24. var w = WidgetFactory.createWidget(includeBasePath, "PenToolBar.ui", RMainWindowQt.getMainWindow());
  25. WidgetFactory.moveChildren(w, penToolBar, w.objectName);
  26. destr(w);
  27. //penToolBar.addWidget(w);
  28. penToolBar.visible = false;
  29. var appWin = EAction.getMainWindow();
  30. var adapter = new RPenListenerAdapter();
  31. appWin.addPenListener(adapter);
  32. adapter.penUpdated.connect(
  33. function(di) {
  34. if (isNull(di)) {
  35. return;
  36. }
  37. var colorCombo = penToolBar.findChild("Color");
  38. colorCombo.blockSignals(true);
  39. colorCombo.setColor(di.getCurrentColor());
  40. colorCombo.blockSignals(false);
  41. var linetypeCombo = penToolBar.findChild("Linetype");
  42. linetypeCombo.blockSignals(true);
  43. linetypeCombo.init(di.getDocument());
  44. linetypeCombo.setLinetypePattern(di.getCurrentLinetypePattern());
  45. linetypeCombo.blockSignals(false);
  46. var lineweightCombo = penToolBar.findChild("Lineweight");
  47. lineweightCombo.blockSignals(true);
  48. lineweightCombo.setLineweight(di.getCurrentLineweight());
  49. lineweightCombo.blockSignals(false);
  50. }
  51. );
  52. adapter.penCleared.connect(
  53. function(documentInterface) {
  54. // TODO
  55. qDebug("clearPen");
  56. }
  57. );
  58. var colorCombo = penToolBar.findChild("Color");
  59. colorCombo.valueChanged.connect(
  60. function(color) {
  61. var di = EAction.getDocumentInterface();
  62. if (!isNull(di)) {
  63. di.setCurrentColor(color);
  64. }
  65. }
  66. );
  67. var linetypeCombo = penToolBar.findChild("Linetype");
  68. linetypeCombo.minimumWidth = 250;
  69. linetypeCombo.valueChanged.connect(
  70. function(p) {
  71. var di = EAction.getDocumentInterface();
  72. if (!isNull(di)) {
  73. di.setCurrentLinetypePattern(p);
  74. }
  75. }
  76. );
  77. var lineweightCombo = penToolBar.findChild("Lineweight");
  78. lineweightCombo.valueChanged.connect(
  79. function(lw) {
  80. var di = EAction.getDocumentInterface();
  81. if (!isNull(di)) {
  82. di.setCurrentLineweight(lw);
  83. }
  84. }
  85. );
  86. var resetButton = penToolBar.findChild("Reset");
  87. if (!isNull(resetButton)) {
  88. resetButton.toolTip = qsTr("Reset to Defaults");
  89. resetButton.clicked.connect(
  90. function() {
  91. colorCombo.setColor(new RColor(RColor.ByLayer));
  92. linetypeCombo.setLinetypePattern("BYLAYER");
  93. lineweightCombo.setLineweight(RLineweight.WeightByLayer);
  94. }
  95. );
  96. }
  97. };