InputPreferences.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  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. include("scripts/WidgetFactory.js");
  21. // TODO: use QLocale::decimalPoint
  22. function InputPreferences(guiAction) {
  23. EAction.call(this, guiAction);
  24. }
  25. InputPreferences.prototype = new EAction();
  26. InputPreferences.getPreferencesCategory = function() {
  27. if (!hasPlugin("PROTOOLS")) {
  28. return [qsTr("General"), qsTr("Coordinate Format")];
  29. }
  30. };
  31. InputPreferences.initPreferences = function(pageWidget, calledByPrefDialog, document) {
  32. var combo;
  33. InputPreferences.pageWidget = pageWidget;
  34. combo = pageWidget.findChild("DecimalPoint");
  35. var decimalPointCombo = combo;
  36. InputPreferences.updateDecimalPointCombo(combo);
  37. combo['currentIndexChanged(int)'].connect(InputPreferences.correctBasedOnDecimalPoint);
  38. combo['currentIndexChanged(int)'].connect(InputPreferences.updatePreview);
  39. combo = pageWidget.findChild("CartesianCoordinateSeparator");
  40. combo.addItem(qsTr("Comma") + " ',' " + qsTr("(Default)"), ",");
  41. combo.addItem(qsTr("Semicolon") + " ';'", ";");
  42. combo['currentIndexChanged(int)'].connect(InputPreferences.correctBasedOnSeparator);
  43. combo['currentIndexChanged(int)'].connect(InputPreferences.updatePreview);
  44. combo = pageWidget.findChild("PolarCoordinateSeparator");
  45. combo.addItem(qsTr("Less Than") + " '<' " + qsTr("(Default)"), "<");
  46. combo['currentIndexChanged(int)'].connect(InputPreferences.updatePreview);
  47. combo = pageWidget.findChild("RelativeCoordinatePrefix");
  48. var at = String.fromCharCode(64); // @ (doxygen can't cope with an @ here)
  49. combo.addItem(qsTr("At") + " '" + at + "' " + qsTr("(Default)"), at);
  50. combo.addItem(qsTr("Percentage") + " '%'", "%");
  51. combo.addItem(qsTr("Dollar") + " '$'", "$");
  52. combo.addItem(qsTr("Hash") + " '#'", "#");
  53. combo['currentIndexChanged(int)'].connect(InputPreferences.updatePreview);
  54. var locale = QLocale.system();
  55. var dot;
  56. if (RSettings.getQtVersion() >= 0x060000) {
  57. dot = locale.decimalPoint();
  58. }
  59. else {
  60. dot = String.fromCharCode(locale.decimalPoint());
  61. }
  62. decimalPointCombo.currentIndex = decimalPointCombo.findData(dot);
  63. InputPreferences.updatePreview();
  64. };
  65. InputPreferences.updateDecimalPointCombo = function(combo) {
  66. combo.clear();
  67. combo.addItem(qsTr("Dot") + " '.' " + qsTr("(Default)"), ".");
  68. combo.addItem(qsTr("Comma") + " ','", ",");
  69. };
  70. InputPreferences.correctBasedOnDecimalPoint = function() {
  71. var combo;
  72. combo = InputPreferences.pageWidget.findChild("DecimalPoint");
  73. var dot = combo.itemData(combo.currentIndex);
  74. combo = InputPreferences.pageWidget.findChild("CartesianCoordinateSeparator");
  75. var cartSep = combo.itemData(combo.currentIndex);
  76. if (cartSep==dot) {
  77. for (var i=0; i<combo.count; ++i) {
  78. if (i!=combo.currentIndex) {
  79. combo.currentIndex = i;
  80. break;
  81. }
  82. }
  83. }
  84. };
  85. InputPreferences.correctBasedOnSeparator = function() {
  86. var combo;
  87. combo = InputPreferences.pageWidget.findChild("CartesianCoordinateSeparator");
  88. var cartSep = combo.itemData(combo.currentIndex);
  89. combo = InputPreferences.pageWidget.findChild("DecimalPoint");
  90. var dot = combo.itemData(combo.currentIndex);
  91. if (cartSep==dot) {
  92. for (var i=0; i<combo.count; ++i) {
  93. if (i!=combo.currentIndex) {
  94. combo.currentIndex = i;
  95. break;
  96. }
  97. }
  98. }
  99. };
  100. InputPreferences.updatePreview = function() {
  101. var combo, label;
  102. combo = InputPreferences.pageWidget.findChild("DecimalPoint");
  103. var dot = combo.itemData(combo.currentIndex);
  104. combo = InputPreferences.pageWidget.findChild("CartesianCoordinateSeparator");
  105. var cartSep = combo.itemData(combo.currentIndex);
  106. combo = InputPreferences.pageWidget.findChild("PolarCoordinateSeparator");
  107. var polarSep = combo.itemData(combo.currentIndex);
  108. combo = InputPreferences.pageWidget.findChild("RelativeCoordinatePrefix");
  109. var relPre = combo.itemData(combo.currentIndex);
  110. label = InputPreferences.pageWidget.findChild("AbsCart");
  111. label.text = "10" + dot + "5" + cartSep + "7" + dot + "25";
  112. label = InputPreferences.pageWidget.findChild("AbsPolar");
  113. label.text = "12" + dot + "125" + polarSep + "30" + dot + "0";
  114. label = InputPreferences.pageWidget.findChild("RelCart");
  115. label.text = relPre + "10" + dot + "5" + cartSep + "7" + dot + "25";
  116. label = InputPreferences.pageWidget.findChild("RelPolar");
  117. label.text = relPre + "12" + dot + "125" + polarSep + "30" + dot + "0";
  118. };
  119. InputPreferences.applyPreferences = function(doc) {
  120. };